Skip to content

Commit b9779c5

Browse files
committed
fix tests
1 parent e0a6d9e commit b9779c5

File tree

6 files changed

+16
-13
lines changed

6 files changed

+16
-13
lines changed

tests/auth/authorization/mock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const mockUserFindById = jest.fn(async (id: Types.ObjectId) => {
4444
});
4545

4646
export const mockRoleRepoFindByCode = jest.fn(
47-
async (code: string): Promise<Role> => {
47+
async (code: string): Promise<Role | null> => {
4848
switch (code) {
4949
case RoleCode.WRITER:
5050
return {

tests/routes/v1/blog/blogDetail/mock.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const BLOG_ID = new Types.ObjectId();
77
export const BLOG_URL = 'abc';
88

99
export const mockBlogFindByUrl = jest.fn(
10-
async (blogUrl: string): Promise<Blog> => {
10+
async (blogUrl: string): Promise<Blog | null> => {
1111
if (blogUrl === BLOG_URL)
1212
return {
1313
_id: BLOG_ID,
@@ -18,7 +18,7 @@ export const mockBlogFindByUrl = jest.fn(
1818
);
1919

2020
export const mockFindInfoWithTextById = jest.fn(
21-
async (id: Types.ObjectId): Promise<Blog> => {
21+
async (id: Types.ObjectId): Promise<Blog | null> => {
2222
if (BLOG_ID.equals(id))
2323
return {
2424
_id: BLOG_ID,

tests/routes/v1/blog/writer/mock.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const BLOG_ID_2 = new Types.ObjectId();
99
export const BLOG_URL = 'abc';
1010

1111
export const mockBlogFindUrlIfExists = jest.fn(
12-
async (blogUrl: string): Promise<Blog> => {
12+
async (blogUrl: string): Promise<Blog | null> => {
1313
if (blogUrl === BLOG_URL)
1414
return {
1515
_id: BLOG_ID,
@@ -29,7 +29,7 @@ export const mockBlogCreate = jest.fn(
2929
export const mockBlogUpdate = jest.fn(async (blog: Blog): Promise<Blog> => blog);
3030

3131
export const mockFindBlogAllDataById = jest.fn(
32-
async (id: Types.ObjectId): Promise<Blog> => {
32+
async (id: Types.ObjectId): Promise<Blog | null> => {
3333
if (BLOG_ID.equals(id))
3434
return {
3535
_id: BLOG_ID,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('Login basic route', () => {
2222
const password = '123456';
2323

2424
let user: User;
25-
let apikey: ApiKey;
25+
let apikey: ApiKey | null;
2626

2727
beforeAll(async () => {
2828
await UserModel.remove({}); // delete all data from user table
@@ -168,5 +168,5 @@ describe('Login basic route', () => {
168168
});
169169
});
170170

171-
export const addHeaders = (request: any, apikey: ApiKey) =>
172-
request.set('Content-Type', 'application/json').set('x-api-key', apikey.key);
171+
export const addHeaders = (request: any, apikey: ApiKey | null) =>
172+
request.set('Content-Type', 'application/json').set('x-api-key', apikey?.key);

tests/routes/v1/login/mock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const mockKeystoreCreate = jest.fn(
2525
);
2626

2727
export const mockUserFindByEmail = jest.fn(
28-
async (email: string): Promise<User> => {
28+
async (email: string): Promise<User | null> => {
2929
if (email === USER_EMAIL)
3030
return {
3131
_id: USER_ID,

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

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

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

0 commit comments

Comments
 (0)