Skip to content

Commit db15c41

Browse files
committed
remove jest deprecated functions
1 parent 5f70eb2 commit db15c41

File tree

9 files changed

+203
-203
lines changed

9 files changed

+203
-203
lines changed

tests/auth/apikey/unit.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('apikey validation', () => {
1515
it('Should response with 400 if x-api-key header is not passed', async () => {
1616
const response = await request.get(endpoint).timeout(2000);
1717
expect(response.status).toBe(400);
18-
expect(mockFindApiKey).not.toBeCalled();
18+
expect(mockFindApiKey).not.toHaveBeenCalled();
1919
});
2020

2121
it('Should response with 403 if wrong x-api-key header is passed', async () => {
@@ -25,8 +25,8 @@ describe('apikey validation', () => {
2525
.set('x-api-key', wrongApiKey)
2626
.timeout(2000);
2727
expect(response.status).toBe(403);
28-
expect(mockFindApiKey).toBeCalledTimes(1);
29-
expect(mockFindApiKey).toBeCalledWith(wrongApiKey);
28+
expect(mockFindApiKey).toHaveBeenCalledTimes(1);
29+
expect(mockFindApiKey).toHaveBeenCalledWith(wrongApiKey);
3030
});
3131

3232
it('Should response with 404 if correct x-api-key header is passed and when route is not handelled', async () => {
@@ -35,7 +35,7 @@ describe('apikey validation', () => {
3535
.set('x-api-key', API_KEY)
3636
.timeout(2000);
3737
expect(response.status).toBe(404);
38-
expect(mockFindApiKey).toBeCalledTimes(1);
39-
expect(mockFindApiKey).toBeCalledWith(API_KEY);
38+
expect(mockFindApiKey).toHaveBeenCalledTimes(1);
39+
expect(mockFindApiKey).toHaveBeenCalledWith(API_KEY);
4040
});
4141
});

tests/auth/authentication/unit.test.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('authentication validation', () => {
2929
const response = await addHeaders(request.get(endpoint));
3030
expect(response.status).toBe(400);
3131
expect(response.body.message).toMatch(/authorization/);
32-
expect(getAccessTokenSpy).not.toBeCalled();
32+
expect(getAccessTokenSpy).not.toHaveBeenCalled();
3333
});
3434

3535
it('Should response with 400 if Authorization header do not have Bearer', async () => {
@@ -39,7 +39,7 @@ describe('authentication validation', () => {
3939
);
4040
expect(response.status).toBe(400);
4141
expect(response.body.message).toMatch(/authorization/);
42-
expect(getAccessTokenSpy).not.toBeCalled();
42+
expect(getAccessTokenSpy).not.toHaveBeenCalled();
4343
});
4444

4545
it('Should response with 401 if wrong Authorization header is provided', async () => {
@@ -49,25 +49,25 @@ describe('authentication validation', () => {
4949
);
5050
expect(response.status).toBe(401);
5151
expect(response.body.message).toMatch(/token/i);
52-
expect(getAccessTokenSpy).toBeCalledTimes(1);
53-
expect(getAccessTokenSpy).toBeCalledWith('Bearer 123');
54-
expect(getAccessTokenSpy).toReturnWith('123');
55-
expect(mockJwtValidate).toBeCalledTimes(1);
56-
expect(mockJwtValidate).toBeCalledWith('123');
57-
expect(mockUserFindById).not.toBeCalled();
52+
expect(getAccessTokenSpy).toHaveBeenCalledTimes(1);
53+
expect(getAccessTokenSpy).toHaveBeenCalledWith('Bearer 123');
54+
expect(getAccessTokenSpy).toHaveReturnedWith('123');
55+
expect(mockJwtValidate).toHaveBeenCalledTimes(1);
56+
expect(mockJwtValidate).toHaveBeenCalledWith('123');
57+
expect(mockUserFindById).not.toHaveBeenCalled();
5858
});
5959

6060
it('Should response with 404 if correct Authorization header is provided', async () => {
6161
const response = await addAuthHeaders(request.get(endpoint));
6262
expect(response.body.message).not.toMatch(/not registered/);
6363
expect(response.body.message).not.toMatch(/token/i);
6464
expect(response.status).toBe(404);
65-
expect(getAccessTokenSpy).toBeCalledTimes(1);
66-
expect(getAccessTokenSpy).toBeCalledWith(`Bearer ${ACCESS_TOKEN}`);
67-
expect(getAccessTokenSpy).toReturnWith(ACCESS_TOKEN);
68-
expect(mockJwtValidate).toBeCalledTimes(1);
69-
expect(mockJwtValidate).toBeCalledWith(ACCESS_TOKEN);
70-
expect(mockUserFindById).toBeCalledTimes(1);
71-
expect(mockKeystoreFindForKey).toBeCalledTimes(1);
65+
expect(getAccessTokenSpy).toHaveBeenCalledTimes(1);
66+
expect(getAccessTokenSpy).toHaveBeenCalledWith(`Bearer ${ACCESS_TOKEN}`);
67+
expect(getAccessTokenSpy).toHaveReturnedWith(ACCESS_TOKEN);
68+
expect(mockJwtValidate).toHaveBeenCalledTimes(1);
69+
expect(mockJwtValidate).toHaveBeenCalledWith(ACCESS_TOKEN);
70+
expect(mockUserFindById).toHaveBeenCalledTimes(1);
71+
expect(mockKeystoreFindForKey).toHaveBeenCalledTimes(1);
7272
});
7373
});

tests/auth/authorization/unit.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ describe('authentication validation for editor', () => {
2727
const response = await addAuthHeaders(request.get(endpoint));
2828
expect(response.status).toBe(401);
2929
expect(response.body.message).toMatch(/denied/);
30-
expect(mockRoleRepoFindByCodes).toBeCalledTimes(1);
31-
expect(mockUserFindById).toBeCalledTimes(1);
32-
expect(mockRoleRepoFindByCodes).toBeCalledWith([
30+
expect(mockRoleRepoFindByCodes).toHaveBeenCalledTimes(1);
31+
expect(mockUserFindById).toHaveBeenCalledTimes(1);
32+
expect(mockRoleRepoFindByCodes).toHaveBeenCalledWith([
3333
RoleCode.ADMIN,
3434
RoleCode.EDITOR,
3535
]);
@@ -51,8 +51,8 @@ describe('authentication validation for writer', () => {
5151
EDITOR_ACCESS_TOKEN,
5252
);
5353
expect(response.status).toBe(404);
54-
expect(mockRoleRepoFindByCodes).toBeCalledTimes(1);
55-
expect(mockUserFindById).toBeCalledTimes(1);
56-
expect(mockRoleRepoFindByCodes).toBeCalledWith([RoleCode.WRITER]);
54+
expect(mockRoleRepoFindByCodes).toHaveBeenCalledTimes(1);
55+
expect(mockUserFindById).toHaveBeenCalledTimes(1);
56+
expect(mockRoleRepoFindByCodes).toHaveBeenCalledWith([RoleCode.WRITER]);
5757
});
5858
});

tests/core/jwt/unit.test.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ describe('JWT class tests', () => {
2020
expect(e).toBeInstanceOf(BadTokenError);
2121
}
2222

23-
expect(readFileSpy).toBeCalledTimes(1);
23+
expect(readFileSpy).toHaveBeenCalledTimes(1);
2424
});
2525

2626
it('Should generate a token for JWT.encode', async () => {
2727
const payload = new JwtPayload(issuer, audience, subject, param, validity);
2828
const token = await JWT.encode(payload);
2929

3030
expect(typeof token).toBe('string');
31-
expect(readFileSpy).toBeCalledTimes(1);
31+
expect(readFileSpy).toHaveBeenCalledTimes(1);
3232
});
3333

3434
it('Should decode a valid token for JWT.decode', async () => {
@@ -37,7 +37,7 @@ describe('JWT class tests', () => {
3737
const decoded = await JWT.decode(token);
3838

3939
expect(decoded).toMatchObject(payload);
40-
expect(readFileSpy).toBeCalledTimes(2);
40+
expect(readFileSpy).toHaveBeenCalledTimes(2);
4141
});
4242

4343
it('Should parse an expired token for JWT.decode', async () => {
@@ -55,7 +55,7 @@ describe('JWT class tests', () => {
5555
const decoded = await JWT.decode(token);
5656

5757
expect(decoded).toMatchObject(payload);
58-
expect(readFileSpy).toBeCalledTimes(2);
58+
expect(readFileSpy).toHaveBeenCalledTimes(2);
5959
});
6060

6161
it('Should throw error for invalid token in JWT.validate', async () => {
@@ -65,7 +65,7 @@ describe('JWT class tests', () => {
6565
expect(e).toBeInstanceOf(BadTokenError);
6666
}
6767

68-
expect(readFileSpy).toBeCalledTimes(1);
68+
expect(readFileSpy).toHaveBeenCalledTimes(1);
6969
});
7070

7171
it('Should validate a valid token for JWT.validate', async () => {
@@ -74,7 +74,7 @@ describe('JWT class tests', () => {
7474
const decoded = await JWT.validate(token);
7575

7676
expect(decoded).toMatchObject(payload);
77-
expect(readFileSpy).toBeCalledTimes(2);
77+
expect(readFileSpy).toHaveBeenCalledTimes(2);
7878
});
7979

8080
it('Should validate a token expiry for JWT.validate', async () => {
@@ -94,6 +94,6 @@ describe('JWT class tests', () => {
9494
} catch (e) {
9595
expect(e).toBeInstanceOf(TokenExpiredError);
9696
}
97-
expect(readFileSpy).toBeCalledTimes(2);
97+
expect(readFileSpy).toHaveBeenCalledTimes(2);
9898
});
9999
});

tests/routes/access/login/integration.test.ts

+33-33
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ describe('Login basic route', () => {
5757
it('Should send error when empty body is sent', async () => {
5858
const response = await addHeaders(request.post(endpoint), apikey);
5959
expect(response.status).toBe(400);
60-
expect(userFindByEmailSpy).not.toBeCalled();
61-
expect(bcryptCompareSpy).not.toBeCalled();
62-
expect(keystoreCreateSpy).not.toBeCalled();
63-
expect(createTokensSpy).not.toBeCalled();
60+
expect(userFindByEmailSpy).not.toHaveBeenCalled();
61+
expect(bcryptCompareSpy).not.toHaveBeenCalled();
62+
expect(keystoreCreateSpy).not.toHaveBeenCalled();
63+
expect(createTokensSpy).not.toHaveBeenCalled();
6464
});
6565

6666
it('Should send error when email is only sent', async () => {
@@ -70,10 +70,10 @@ describe('Login basic route', () => {
7070
);
7171
expect(response.status).toBe(400);
7272
expect(response.body.message).toMatch(/password/);
73-
expect(userFindByEmailSpy).not.toBeCalled();
74-
expect(bcryptCompareSpy).not.toBeCalled();
75-
expect(keystoreCreateSpy).not.toBeCalled();
76-
expect(createTokensSpy).not.toBeCalled();
73+
expect(userFindByEmailSpy).not.toHaveBeenCalled();
74+
expect(bcryptCompareSpy).not.toHaveBeenCalled();
75+
expect(keystoreCreateSpy).not.toHaveBeenCalled();
76+
expect(createTokensSpy).not.toHaveBeenCalled();
7777
});
7878

7979
it('Should send error when password is only sent', async () => {
@@ -83,10 +83,10 @@ describe('Login basic route', () => {
8383
);
8484
expect(response.status).toBe(400);
8585
expect(response.body.message).toMatch(/email/);
86-
expect(userFindByEmailSpy).not.toBeCalled();
87-
expect(bcryptCompareSpy).not.toBeCalled();
88-
expect(keystoreCreateSpy).not.toBeCalled();
89-
expect(createTokensSpy).not.toBeCalled();
86+
expect(userFindByEmailSpy).not.toHaveBeenCalled();
87+
expect(bcryptCompareSpy).not.toHaveBeenCalled();
88+
expect(keystoreCreateSpy).not.toHaveBeenCalled();
89+
expect(createTokensSpy).not.toHaveBeenCalled();
9090
});
9191

9292
it('Should send error when email is not valid format', async () => {
@@ -96,10 +96,10 @@ describe('Login basic route', () => {
9696
);
9797
expect(response.status).toBe(400);
9898
expect(response.body.message).toMatch(/valid email/);
99-
expect(userFindByEmailSpy).not.toBeCalled();
100-
expect(bcryptCompareSpy).not.toBeCalled();
101-
expect(keystoreCreateSpy).not.toBeCalled();
102-
expect(createTokensSpy).not.toBeCalled();
99+
expect(userFindByEmailSpy).not.toHaveBeenCalled();
100+
expect(bcryptCompareSpy).not.toHaveBeenCalled();
101+
expect(keystoreCreateSpy).not.toHaveBeenCalled();
102+
expect(createTokensSpy).not.toHaveBeenCalled();
103103
});
104104

105105
it('Should send error when password is not valid format', async () => {
@@ -113,10 +113,10 @@ describe('Login basic route', () => {
113113
expect(response.status).toBe(400);
114114
expect(response.body.message).toMatch(/password length/);
115115
expect(response.body.message).toMatch(/6 char/);
116-
expect(userFindByEmailSpy).not.toBeCalled();
117-
expect(bcryptCompareSpy).not.toBeCalled();
118-
expect(keystoreCreateSpy).not.toBeCalled();
119-
expect(createTokensSpy).not.toBeCalled();
116+
expect(userFindByEmailSpy).not.toHaveBeenCalled();
117+
expect(bcryptCompareSpy).not.toHaveBeenCalled();
118+
expect(keystoreCreateSpy).not.toHaveBeenCalled();
119+
expect(createTokensSpy).not.toHaveBeenCalled();
120120
});
121121

122122
it('Should send error when user not registered for email', async () => {
@@ -129,10 +129,10 @@ describe('Login basic route', () => {
129129
);
130130
expect(response.status).toBe(400);
131131
expect(response.body.message).toMatch(/not registered/);
132-
expect(userFindByEmailSpy).toBeCalledTimes(1);
133-
expect(bcryptCompareSpy).not.toBeCalled();
134-
expect(keystoreCreateSpy).not.toBeCalled();
135-
expect(createTokensSpy).not.toBeCalled();
132+
expect(userFindByEmailSpy).toHaveBeenCalledTimes(1);
133+
expect(bcryptCompareSpy).not.toHaveBeenCalled();
134+
expect(keystoreCreateSpy).not.toHaveBeenCalled();
135+
expect(createTokensSpy).not.toHaveBeenCalled();
136136
});
137137

138138
it('Should send error for wrong password', async () => {
@@ -145,10 +145,10 @@ describe('Login basic route', () => {
145145
);
146146
expect(response.status).toBe(401);
147147
expect(response.body.message).toMatch(/authentication failure/i);
148-
expect(userFindByEmailSpy).toBeCalledTimes(1);
149-
expect(bcryptCompareSpy).toBeCalledTimes(1);
150-
expect(keystoreCreateSpy).not.toBeCalled();
151-
expect(createTokensSpy).not.toBeCalled();
148+
expect(userFindByEmailSpy).toHaveBeenCalledTimes(1);
149+
expect(bcryptCompareSpy).toHaveBeenCalledTimes(1);
150+
expect(keystoreCreateSpy).not.toHaveBeenCalled();
151+
expect(createTokensSpy).not.toHaveBeenCalled();
152152
});
153153

154154
it('Should send success response for correct credentials', async () => {
@@ -172,12 +172,12 @@ describe('Login basic route', () => {
172172
expect(response.body.data.tokens).toHaveProperty('accessToken');
173173
expect(response.body.data.tokens).toHaveProperty('refreshToken');
174174

175-
expect(userFindByEmailSpy).toBeCalledTimes(1);
176-
expect(keystoreCreateSpy).toBeCalledTimes(1);
177-
expect(bcryptCompareSpy).toBeCalledTimes(1);
178-
expect(createTokensSpy).toBeCalledTimes(1);
175+
expect(userFindByEmailSpy).toHaveBeenCalledTimes(1);
176+
expect(keystoreCreateSpy).toHaveBeenCalledTimes(1);
177+
expect(bcryptCompareSpy).toHaveBeenCalledTimes(1);
178+
expect(createTokensSpy).toHaveBeenCalledTimes(1);
179179

180-
expect(bcryptCompareSpy).toBeCalledWith(password, user.password);
180+
expect(bcryptCompareSpy).toHaveBeenCalledWith(password, user.password);
181181
});
182182
});
183183

0 commit comments

Comments
 (0)