Skip to content

Commit 995ae2f

Browse files
opifexopifex
authored andcommitted
main page root test added
1 parent 16295be commit 995ae2f

File tree

2 files changed

+60
-5
lines changed

2 files changed

+60
-5
lines changed

__tests__/root.test.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import {
2+
buildServer,
3+
makeRequest,
4+
makeAuthRequest,
5+
clearUsers,
6+
insertUser,
7+
} from './helpers/utils.js';
8+
import testData from '../__fixtures__/users.json';
9+
10+
describe('Main Page Route', () => {
11+
let server;
12+
let request;
13+
let authRequest;
14+
15+
beforeAll(async () => {
16+
server = await buildServer();
17+
request = makeRequest(server);
18+
authRequest = makeAuthRequest(server);
19+
});
20+
21+
beforeEach(async () => {
22+
await clearUsers(server);
23+
await insertUser(server, testData.users.existing);
24+
});
25+
26+
afterAll(async () => {
27+
await server.close();
28+
});
29+
30+
describe('Main page', () => {
31+
it('GET / should show main page for unauthenticated user', async () => {
32+
const res = await request({ method: 'GET', url: '/' });
33+
expect(res.statusCode).toBe(200);
34+
expect(res.payload).toContain('FlowTrack');
35+
});
36+
37+
it('GET / should show main page for authenticated user', async () => {
38+
const res = await authRequest(
39+
{
40+
method: 'GET',
41+
url: '/',
42+
},
43+
testData.session.valid,
44+
);
45+
expect(res.statusCode).toBe(200);
46+
expect(res.payload).toContain('FlowTrack');
47+
});
48+
});
49+
});

__tests__/user.test.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
} from './helpers/utils.js';
88
import testData from '../__fixtures__/users.json';
99

10+
const validCredentials = testData.session.valid;
11+
1012
describe('User Management Routes', () => {
1113
let server;
1214
let request;
@@ -37,7 +39,9 @@ describe('User Management Routes', () => {
3739
const res = await request({
3840
method: 'POST',
3941
url: '/session',
40-
payload: { data: testData.session.valid },
42+
payload: {
43+
data: validCredentials,
44+
},
4145
});
4246
expect(res.statusCode).toBe(302);
4347
expect(res.headers['set-cookie']).toBeDefined();
@@ -48,7 +52,9 @@ describe('User Management Routes', () => {
4852
const res = await request({
4953
method: 'POST',
5054
url: '/session',
51-
payload: { data: testData.session.invalid },
55+
payload: {
56+
data: testData.session.invalid,
57+
},
5258
});
5359
expect(res.statusCode).toBe(302);
5460
expect(res.headers.location).toBe('/session/new');
@@ -61,7 +67,7 @@ describe('User Management Routes', () => {
6167
url: '/session',
6268
payload: { _method: 'delete' },
6369
},
64-
testData.session.valid,
70+
validCredentials,
6571
);
6672
expect(res.statusCode).toBe(302);
6773
expect(res.headers.location).toBe('/');
@@ -70,7 +76,7 @@ describe('User Management Routes', () => {
7076
it('DELETE /session should logout and redirect to root', async () => {
7177
const res = await authRequest(
7278
{ method: 'DELETE', url: '/session' },
73-
testData.session.valid,
79+
validCredentials,
7480
);
7581
expect(res.statusCode).toBe(302);
7682
expect(res.headers.location).toBe('/');
@@ -129,7 +135,7 @@ describe('User Management Routes', () => {
129135
it('GET /users/:id/edit should return 200 and show user data', async () => {
130136
const res = await authRequest(
131137
{ method: 'GET', url: `/users/${id}/edit` },
132-
testData.session.valid,
138+
validCredentials,
133139
);
134140
expect(res.statusCode).toBe(200);
135141
expect(res.payload).toContain(

0 commit comments

Comments
 (0)