Skip to content

Commit

Permalink
Fixing frontend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
villepynttari committed Jun 24, 2024
1 parent b3cab79 commit 094c1e6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "get-a-room-frontend",
"version": "0.1.0",
"private": true,
"type": "module",
"proxy": "http://localhost:8080",
"dependencies": {
"@emotion/babel-plugin": "^11.11.0",
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/offline.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Weather App</title>
<title>Get A Room!</title>
<style type="text/css">
html {
height: 100%;
Expand Down
19 changes: 13 additions & 6 deletions frontend/src/util/checkEnvVariables.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
const valueMock = jest.fn();

const envMock = jest.mock('util/getARoomEnv', () => () => {
valueMock.mockImplementationOnce(() => 'VITE_REACT_APP_SERVER_KEY');
return {
VITE_REACT_APP_SERVER_KEY: valueMock()
};
});

import { checkEnvVariables } from './checkEnvVariables';

describe('checkEnvVariables', () => {
beforeEach(() => {
process.env = {
...process.env,
REACT_APP_SERVER_KEY: 'Test server key'
};
jest.resetAllMocks();
});

test('Should fail without application server key', () => {
process.env.REACT_APP_SERVER_KEY = undefined;
valueMock.mockImplementationOnce(() => undefined);

expect(() => {
checkEnvVariables();
}).toThrow('Application server key not set');
});

test('Should fail with empty application server key', () => {
process.env.REACT_APP_SERVER_KEY = '';
valueMock.mockImplementationOnce(() => '');
expect(() => {
checkEnvVariables();
}).toThrow('Application server key not set');
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/util/checkEnvVariables.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import GETAROOM_ENV from './getARoomEnv';

export const checkEnvVariables = () => {
const { VITE_REACT_APP_SERVER_KEY } = import.meta.env;
const { VITE_REACT_APP_SERVER_KEY } = GETAROOM_ENV();

if (!VITE_REACT_APP_SERVER_KEY) {
throw new Error('Application server key not set');
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/util/getARoomEnv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const GETAROOM_ENV = () => {
return import.meta.env;
};
export default GETAROOM_ENV;

0 comments on commit 094c1e6

Please sign in to comment.