Skip to content

Commit 740b9ea

Browse files
committed
fix tests
1 parent b9779c5 commit 740b9ea

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

tests/auth/apikey/unit.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ describe('apikey validation', () => {
1111
});
1212

1313
it('Should response with 400 if x-api-key header is not passed', async () => {
14-
const response = await request.get(endpoint);
14+
const response = await request.get(endpoint).timeout(2000);
1515
expect(response.status).toBe(400);
1616
expect(mockFindApiKey).not.toBeCalled();
1717
});
1818

1919
it('Should response with 403 if wrong x-api-key header is passed', async () => {
2020
const wrongApiKey = '123';
21-
const response = await request.get(endpoint).set('x-api-key', wrongApiKey);
21+
const response = await request.get(endpoint).set('x-api-key', wrongApiKey).timeout(2000);
2222
expect(response.status).toBe(403);
2323
expect(mockFindApiKey).toBeCalledTimes(1);
2424
expect(mockFindApiKey).toBeCalledWith(wrongApiKey);
2525
});
2626

2727
it('Should response with 404 if correct x-api-key header is passed and when route is not handelled', async () => {
28-
const response = await request.get(endpoint).set('x-api-key', API_KEY);
28+
const response = await request.get(endpoint).set('x-api-key', API_KEY).timeout(2000);
2929
expect(response.status).toBe(404);
3030
expect(mockFindApiKey).toBeCalledTimes(1);
3131
expect(mockFindApiKey).toBeCalledWith(API_KEY);

tests/auth/authentication/mock.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ jest.mock('../../../src/database/repository/KeystoreRepo', () => ({
5555
JWT.validate = mockJwtValidate;
5656

5757
export const addHeaders = (request: any) =>
58-
request.set('Content-Type', 'application/json').set('x-api-key', API_KEY);
58+
request.set('Content-Type', 'application/json').set('x-api-key', API_KEY).timeout(2000);
5959

6060
export const addAuthHeaders = (request: any, accessToken = ACCESS_TOKEN) =>
6161
request
6262
.set('Content-Type', 'application/json')
6363
.set('Authorization', `Bearer ${accessToken}`)
64-
.set('x-api-key', API_KEY);
64+
.set('x-api-key', API_KEY)
65+
.timeout(2000);

tests/routes/v1/login/mock.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import User from '../../../../src/database/model/User';
44
import { Types } from 'mongoose';
55
import bcrypt from 'bcrypt';
66
import * as authUtils from '../../../../src/auth/authUtils';
7+
import Role from '../../../../src/database/model/Role';
78

89
export const USER_EMAIL = '[email protected]';
910
export const USER_PASSWORD = 'abc123';
@@ -33,7 +34,7 @@ export const mockUserFindByEmail = jest.fn(
3334
password: USER_PASSWORD_HASH,
3435
name: 'abc',
3536
profilePicUrl: 'abc',
36-
roles: [],
37+
roles: [] as Role[],
3738
} as User;
3839
return null;
3940
},

tests/routes/v1/login/unit.test.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,10 @@ describe('Login basic route', () => {
112112

113113
it('Should send success response for correct credentials', async () => {
114114
const response = await addHeaders(
115-
request
116-
.post(endpoint)
117-
.send({
118-
email: USER_EMAIL,
119-
password: USER_PASSWORD,
120-
})
121-
.timeout(5000),
115+
request.post(endpoint).send({
116+
email: USER_EMAIL,
117+
password: USER_PASSWORD,
118+
}),
122119
);
123120
expect(response.status).toBe(200);
124121
expect(response.body.message).toMatch(/Success/i);

0 commit comments

Comments
 (0)