Skip to content

Commit 46e42ac

Browse files
committed
formatting fixes
1 parent f7c2578 commit 46e42ac

File tree

11 files changed

+114
-134
lines changed

11 files changed

+114
-134
lines changed

addons/init-mongo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function seed(dbName, user, password) {
2929
db.users.insert({
3030
name: 'Admin',
3131
32-
password: '$2a$10$psWmSrmtyZYvtIt/FuJL1OLqsK3iR1fZz5.wUYFuSNkkt.EOX9mLa' // hash of password: changeit
32+
password: '$2a$10$psWmSrmtyZYvtIt/FuJL1OLqsK3iR1fZz5.wUYFuSNkkt.EOX9mLa', // hash of password: changeit
3333
});
3434
}
3535

src/database/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ process.on('SIGINT', () => {
6262
Logger.info('Mongoose default connection disconnected through app termination');
6363
process.exit(0);
6464
});
65-
});
65+
});

src/database/repository/BlogRepo.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ export default class BlogRepo {
4343

4444
public static findBlogAllDataById(id: Types.ObjectId): Promise<Blog | null> {
4545
return BlogModel.findOne({ _id: id, status: true })
46-
.select(
47-
'+text +draftText +isSubmitted +isDraft +isPublished +status +createdBy +updatedBy',
48-
)
46+
.select('+text +draftText +isSubmitted +isDraft +isPublished +status +createdBy +updatedBy')
4947
.populate('author', this.AUTHOR_DETAIL)
5048
.lean()
5149
.exec();

src/database/repository/UserRepo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import User, { UserModel } from '../model/User';
2-
import Role, { RoleModel } from '../model/Role';
2+
import { RoleModel } from '../model/Role';
33
import { InternalError } from '../../core/ApiError';
44
import { Types } from 'mongoose';
55
import KeystoreRepo from './KeystoreRepo';

src/routes/v1/access/login.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import validator from '../../../helpers/validator';
99
import schema from './schema';
1010
import asyncHandler from '../../../helpers/asyncHandler';
1111
import bcrypt from 'bcrypt';
12-
import _ from 'lodash';
1312
import { getUserData } from './utils';
1413
import { PublicRequest } from '../../../types/app-request';
1514

src/routes/v1/access/signup.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import validator from '../../../helpers/validator';
1010
import schema from './schema';
1111
import asyncHandler from '../../../helpers/asyncHandler';
1212
import bcrypt from 'bcrypt';
13-
import _ from 'lodash';
1413
import { RoleCode } from '../../../database/model/Role';
1514
import { getUserData } from './utils';
1615

tests/auth/authentication/mock.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,18 @@ export const mockUserFindById = jest.fn(async (id: Types.ObjectId) => {
2020
else return null;
2121
});
2222

23-
export const mockJwtValidate = jest.fn(
24-
async (token: string): Promise<JwtPayload> => {
25-
if (token === ACCESS_TOKEN)
26-
return {
27-
iss: tokenInfo.issuer,
28-
aud: tokenInfo.audience,
29-
sub: USER_ID.toHexString(),
30-
iat: 1,
31-
exp: 2,
32-
prm: 'abcdef',
33-
} as JwtPayload;
34-
throw new BadTokenError();
35-
},
36-
);
23+
export const mockJwtValidate = jest.fn(async (token: string): Promise<JwtPayload> => {
24+
if (token === ACCESS_TOKEN)
25+
return {
26+
iss: tokenInfo.issuer,
27+
aud: tokenInfo.audience,
28+
sub: USER_ID.toHexString(),
29+
iat: 1,
30+
exp: 2,
31+
prm: 'abcdef',
32+
} as JwtPayload;
33+
throw new BadTokenError();
34+
});
3735

3836
export const mockKeystoreFindForKey = jest.fn(
3937
async (client: User, key: string): Promise<Keystore> =>

tests/auth/authorization/mock.ts

Lines changed: 47 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -43,58 +43,54 @@ export const mockUserFindById = jest.fn(async (id: Types.ObjectId) => {
4343
else return null;
4444
});
4545

46-
export const mockRoleRepoFindByCode = jest.fn(
47-
async (code: string): Promise<Role | null> => {
48-
switch (code) {
49-
case RoleCode.WRITER:
50-
return {
51-
_id: WRITER_ROLE_ID,
52-
code: RoleCode.WRITER,
53-
status: true,
54-
} as Role;
55-
case RoleCode.EDITOR:
56-
return {
57-
_id: EDITOR_ROLE_ID,
58-
code: RoleCode.EDITOR,
59-
status: true,
60-
} as Role;
61-
case RoleCode.LEARNER:
62-
return {
63-
_id: LEARNER_ROLE_ID,
64-
code: RoleCode.LEARNER,
65-
status: true,
66-
} as Role;
67-
}
68-
return null;
69-
},
70-
);
71-
72-
export const mockJwtValidate = jest.fn(
73-
async (token: string): Promise<JwtPayload> => {
74-
let subject = null;
75-
switch (token) {
76-
case ACCESS_TOKEN:
77-
subject = USER_ID.toHexString();
78-
break;
79-
case WRITER_ACCESS_TOKEN:
80-
subject = USER_ID_WRITER.toHexString();
81-
break;
82-
case EDITOR_ACCESS_TOKEN:
83-
subject = USER_ID_EDITOR.toHexString();
84-
break;
85-
}
86-
if (subject)
46+
export const mockRoleRepoFindByCode = jest.fn(async (code: string): Promise<Role | null> => {
47+
switch (code) {
48+
case RoleCode.WRITER:
8749
return {
88-
iss: tokenInfo.issuer,
89-
aud: tokenInfo.audience,
90-
sub: subject,
91-
iat: 1,
92-
exp: 2,
93-
prm: 'abcdef',
94-
} as JwtPayload;
95-
throw new BadTokenError();
96-
},
97-
);
50+
_id: WRITER_ROLE_ID,
51+
code: RoleCode.WRITER,
52+
status: true,
53+
} as Role;
54+
case RoleCode.EDITOR:
55+
return {
56+
_id: EDITOR_ROLE_ID,
57+
code: RoleCode.EDITOR,
58+
status: true,
59+
} as Role;
60+
case RoleCode.LEARNER:
61+
return {
62+
_id: LEARNER_ROLE_ID,
63+
code: RoleCode.LEARNER,
64+
status: true,
65+
} as Role;
66+
}
67+
return null;
68+
});
69+
70+
export const mockJwtValidate = jest.fn(async (token: string): Promise<JwtPayload> => {
71+
let subject = null;
72+
switch (token) {
73+
case ACCESS_TOKEN:
74+
subject = USER_ID.toHexString();
75+
break;
76+
case WRITER_ACCESS_TOKEN:
77+
subject = USER_ID_WRITER.toHexString();
78+
break;
79+
case EDITOR_ACCESS_TOKEN:
80+
subject = USER_ID_EDITOR.toHexString();
81+
break;
82+
}
83+
if (subject)
84+
return {
85+
iss: tokenInfo.issuer,
86+
aud: tokenInfo.audience,
87+
sub: subject,
88+
iat: 1,
89+
exp: 2,
90+
prm: 'abcdef',
91+
} as JwtPayload;
92+
throw new BadTokenError();
93+
});
9894

9995
jest.mock('../../../src/database/repository/UserRepo', () => ({
10096
get findById() {

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@ jest.unmock('../../../../../src/database/repository/BlogRepo');
66
export const BLOG_ID = new Types.ObjectId();
77
export const BLOG_URL = 'abc';
88

9-
export const mockBlogFindByUrl = jest.fn(
10-
async (blogUrl: string): Promise<Blog | null> => {
11-
if (blogUrl === BLOG_URL)
12-
return {
13-
_id: BLOG_ID,
14-
blogUrl: blogUrl,
15-
} as Blog;
16-
return null;
17-
},
18-
);
9+
export const mockBlogFindByUrl = jest.fn(async (blogUrl: string): Promise<Blog | null> => {
10+
if (blogUrl === BLOG_URL)
11+
return {
12+
_id: BLOG_ID,
13+
blogUrl: blogUrl,
14+
} as Blog;
15+
return null;
16+
});
1917

2018
export const mockFindInfoWithTextById = jest.fn(
2119
async (id: Types.ObjectId): Promise<Blog | null> => {

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

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,41 @@ export const BLOG_ID = new Types.ObjectId();
88
export const BLOG_ID_2 = new Types.ObjectId();
99
export const BLOG_URL = 'abc';
1010

11-
export const mockBlogFindUrlIfExists = jest.fn(
12-
async (blogUrl: string): Promise<Blog | null> => {
13-
if (blogUrl === BLOG_URL)
14-
return {
15-
_id: BLOG_ID,
16-
blogUrl: blogUrl,
17-
} as Blog;
18-
return null;
19-
},
20-
);
11+
export const mockBlogFindUrlIfExists = jest.fn(async (blogUrl: string): Promise<Blog | null> => {
12+
if (blogUrl === BLOG_URL)
13+
return {
14+
_id: BLOG_ID,
15+
blogUrl: blogUrl,
16+
} as Blog;
17+
return null;
18+
});
2119

22-
export const mockBlogCreate = jest.fn(
23-
async (blog: Blog): Promise<Blog> => {
24-
blog._id = BLOG_ID;
25-
return blog;
26-
},
27-
);
20+
export const mockBlogCreate = jest.fn(async (blog: Blog): Promise<Blog> => {
21+
blog._id = BLOG_ID;
22+
return blog;
23+
});
2824

2925
export const mockBlogUpdate = jest.fn(async (blog: Blog): Promise<Blog> => blog);
3026

31-
export const mockFindBlogAllDataById = jest.fn(
32-
async (id: Types.ObjectId): Promise<Blog | null> => {
33-
if (BLOG_ID.equals(id))
34-
return {
35-
_id: BLOG_ID,
36-
author: { _id: USER_ID_WRITER },
37-
isDraft: true,
38-
isSubmitted: false,
39-
isPublished: false,
40-
} as Blog;
41-
if (BLOG_ID_2.equals(id))
42-
return {
43-
_id: BLOG_ID,
44-
author: { _id: new Types.ObjectId() },
45-
isDraft: true,
46-
isSubmitted: false,
47-
isPublished: false,
48-
} as Blog;
49-
return null;
50-
},
51-
);
27+
export const mockFindBlogAllDataById = jest.fn(async (id: Types.ObjectId): Promise<Blog | null> => {
28+
if (BLOG_ID.equals(id))
29+
return {
30+
_id: BLOG_ID,
31+
author: { _id: USER_ID_WRITER },
32+
isDraft: true,
33+
isSubmitted: false,
34+
isPublished: false,
35+
} as Blog;
36+
if (BLOG_ID_2.equals(id))
37+
return {
38+
_id: BLOG_ID,
39+
author: { _id: new Types.ObjectId() },
40+
isDraft: true,
41+
isSubmitted: false,
42+
isPublished: false,
43+
} as Blog;
44+
return null;
45+
});
5246

5347
jest.mock('../../../../../src/database/repository/BlogRepo', () => ({
5448
get findUrlIfExists() {

0 commit comments

Comments
 (0)