|
1 | 1 | import { addAuthHeaders } from '../authentication/mock';
|
2 | 2 |
|
3 | 3 | // import the mock for the current test after all other mock imports
|
4 |
| -// this will prevent the different implementations by the other mock |
5 |
| -import { mockRoleRepoFindByCode, mockUserFindById, EDITOR_ACCESS_TOKEN } from './mock'; |
| 4 | +// this will prevent the different implementations for same function by the other mocks |
| 5 | +import { mockRoleRepoFindByCodes, mockUserFindById, EDITOR_ACCESS_TOKEN } from './mock'; |
6 | 6 |
|
7 | 7 | import app from '../../../src/app';
|
8 | 8 | import supertest from 'supertest';
|
9 | 9 | import { RoleCode } from '../../../src/database/model/Role';
|
10 | 10 |
|
11 | 11 | describe('authentication validation for editor', () => {
|
12 |
| - const endpoint = '/v1/editor/blog/test'; |
| 12 | + const endpoint = '/v1/blog/editor/test'; |
13 | 13 | const request = supertest(app);
|
14 | 14 |
|
15 | 15 | beforeEach(() => {
|
16 |
| - mockRoleRepoFindByCode.mockClear(); |
| 16 | + mockRoleRepoFindByCodes.mockClear(); |
17 | 17 | mockUserFindById.mockClear();
|
18 | 18 | });
|
19 | 19 |
|
20 | 20 | it('Should response with 401 if user do not have editor role', async () => {
|
21 | 21 | const response = await addAuthHeaders(request.get(endpoint));
|
22 | 22 | expect(response.status).toBe(401);
|
23 | 23 | expect(response.body.message).toMatch(/denied/);
|
24 |
| - expect(mockRoleRepoFindByCode).toBeCalledTimes(1); |
| 24 | + expect(mockRoleRepoFindByCodes).toBeCalledTimes(1); |
25 | 25 | expect(mockUserFindById).toBeCalledTimes(1);
|
26 |
| - expect(mockRoleRepoFindByCode).toBeCalledWith(RoleCode.EDITOR); |
| 26 | + expect(mockRoleRepoFindByCodes).toBeCalledWith([RoleCode.ADMIN, RoleCode.EDITOR]); |
27 | 27 | });
|
28 | 28 | });
|
29 | 29 |
|
30 | 30 | describe('authentication validation for writer', () => {
|
31 |
| - const endpoint = '/v1/writer/blog/test'; |
| 31 | + const endpoint = '/v1/blog/writer/test'; |
32 | 32 | const request = supertest(app);
|
33 | 33 |
|
34 | 34 | beforeEach(() => {
|
35 |
| - mockRoleRepoFindByCode.mockClear(); |
| 35 | + mockRoleRepoFindByCodes.mockClear(); |
36 | 36 | mockUserFindById.mockClear();
|
37 | 37 | });
|
38 | 38 |
|
39 | 39 | it('Should response with 404 if user have writer role', async () => {
|
40 | 40 | const response = await addAuthHeaders(request.get(endpoint), EDITOR_ACCESS_TOKEN);
|
41 | 41 | expect(response.status).toBe(404);
|
42 |
| - expect(mockRoleRepoFindByCode).toBeCalledTimes(1); |
| 42 | + expect(mockRoleRepoFindByCodes).toBeCalledTimes(1); |
43 | 43 | expect(mockUserFindById).toBeCalledTimes(1);
|
44 |
| - expect(mockRoleRepoFindByCode).toBeCalledWith(RoleCode.WRITER); |
| 44 | + expect(mockRoleRepoFindByCodes).toBeCalledWith([RoleCode.WRITER]); |
45 | 45 | });
|
46 | 46 | });
|
0 commit comments