typescript-express-starter 9.1.2 → 9.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.kr.md +6 -0
- package/README.md +6 -0
- package/lib/default/jest.config.js +1 -1
- package/lib/default/package.json +39 -39
- package/lib/default/src/services/auth.service.ts +6 -6
- package/lib/default/src/services/users.service.ts +6 -6
- package/lib/graphql/jest.config.js +1 -1
- package/lib/graphql/package.json +42 -42
- package/lib/graphql/src/repositories/auth.repository.ts +7 -7
- package/lib/graphql/src/repositories/users.repository.ts +8 -8
- package/lib/knex/jest.config.js +1 -1
- package/lib/knex/knexfile.ts +4 -2
- package/lib/knex/package.json +42 -42
- package/lib/knex/src/databases/migrations/20210713110926_initial.ts +1 -1
- package/lib/knex/src/services/auth.service.ts +7 -7
- package/lib/knex/src/services/users.service.ts +6 -6
- package/lib/mikro-orm/package.json +40 -40
- package/lib/mikro-orm/src/services/auth.service.ts +7 -7
- package/lib/mikro-orm/src/services/users.service.ts +8 -8
- package/lib/mongoose/jest.config.js +1 -1
- package/lib/mongoose/package.json +41 -41
- package/lib/mongoose/src/databases/index.ts +1 -2
- package/lib/mongoose/src/services/auth.service.ts +7 -7
- package/lib/mongoose/src/services/users.service.ts +8 -8
- package/lib/prisma/jest.config.js +1 -1
- package/lib/prisma/package.json +41 -41
- package/lib/prisma/src/services/auth.service.ts +7 -7
- package/lib/prisma/src/services/users.service.ts +8 -8
- package/lib/routing-controllers/jest.config.js +1 -1
- package/lib/routing-controllers/package.json +40 -40
- package/lib/routing-controllers/src/services/auth.service.ts +7 -7
- package/lib/routing-controllers/src/services/users.service.ts +6 -6
- package/lib/sequelize/jest.config.js +1 -1
- package/lib/sequelize/package.json +43 -43
- package/lib/sequelize/src/services/auth.service.ts +7 -7
- package/lib/sequelize/src/services/users.service.ts +8 -8
- package/lib/starter.js +4 -4
- package/lib/typegoose/jest.config.js +1 -1
- package/lib/typegoose/package.json +39 -39
- package/lib/typegoose/src/middlewares/validation.middleware.ts +3 -3
- package/lib/typegoose/src/services/auth.service.ts +7 -7
- package/lib/typegoose/src/services/users.service.ts +8 -8
- package/lib/typeorm/jest.config.js +1 -1
- package/lib/typeorm/package.json +41 -41
- package/lib/typeorm/src/databases/index.ts +1 -1
- package/lib/typeorm/src/services/auth.service.ts +7 -7
- package/lib/typeorm/src/services/users.service.ts +8 -8
- package/lib/typeorm/src/tests/auth.test.ts +5 -6
- package/lib/typeorm/src/tests/users.test.ts +29 -33
- package/package.json +2 -3
|
@@ -10,10 +10,10 @@ import { isEmpty } from '@utils/util';
|
|
|
10
10
|
|
|
11
11
|
class AuthService {
|
|
12
12
|
public async signup(userData: CreateUserDto): Promise<User> {
|
|
13
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
13
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
14
14
|
|
|
15
15
|
const findUser: User = await userModel.findOne({ email: userData.email });
|
|
16
|
-
if (findUser) throw new HttpException(409, `
|
|
16
|
+
if (findUser) throw new HttpException(409, `This email ${userData.email} already exists`);
|
|
17
17
|
|
|
18
18
|
const hashedPassword = await hash(userData.password, 10);
|
|
19
19
|
const createUserData: User = await userModel.create({ ...userData, password: hashedPassword });
|
|
@@ -22,13 +22,13 @@ class AuthService {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
public async login(userData: CreateUserDto): Promise<{ cookie: string; findUser: User }> {
|
|
25
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
25
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
26
26
|
|
|
27
27
|
const findUser: User = await userModel.findOne({ email: userData.email });
|
|
28
|
-
if (!findUser) throw new HttpException(409, `
|
|
28
|
+
if (!findUser) throw new HttpException(409, `This email ${userData.email} was not found`);
|
|
29
29
|
|
|
30
30
|
const isPasswordMatching: boolean = await compare(userData.password, findUser.password);
|
|
31
|
-
if (!isPasswordMatching) throw new HttpException(409, "
|
|
31
|
+
if (!isPasswordMatching) throw new HttpException(409, "Password is not matching");
|
|
32
32
|
|
|
33
33
|
const tokenData = this.createToken(findUser);
|
|
34
34
|
const cookie = this.createCookie(tokenData);
|
|
@@ -37,10 +37,10 @@ class AuthService {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
public async logout(userData: User): Promise<User> {
|
|
40
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
40
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
41
41
|
|
|
42
42
|
const findUser: User = await userModel.findOne({ email: userData.email, password: userData.password });
|
|
43
|
-
if (!findUser) throw new HttpException(409, `
|
|
43
|
+
if (!findUser) throw new HttpException(409, `This email ${userData.email} was not found`);
|
|
44
44
|
|
|
45
45
|
return findUser;
|
|
46
46
|
}
|
|
@@ -14,19 +14,19 @@ class UserService {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
public async findUserById(userId: string): Promise<User> {
|
|
17
|
-
if (isEmpty(userId)) throw new HttpException(400, "
|
|
17
|
+
if (isEmpty(userId)) throw new HttpException(400, "UserId is empty");
|
|
18
18
|
|
|
19
19
|
const findUser: User = await userModel.findOne({ _id: userId });
|
|
20
|
-
if (!findUser) throw new HttpException(409, "
|
|
20
|
+
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
21
21
|
|
|
22
22
|
return findUser;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
public async createUser(userData: CreateUserDto): Promise<User> {
|
|
26
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
26
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
27
27
|
|
|
28
28
|
const findUser: User = await userModel.findOne({ email: userData.email });
|
|
29
|
-
if (findUser) throw new HttpException(409, `
|
|
29
|
+
if (findUser) throw new HttpException(409, `This email ${userData.email} already exists`);
|
|
30
30
|
|
|
31
31
|
const hashedPassword = await hash(userData.password, 10);
|
|
32
32
|
const createUserData: User = await userModel.create({ ...userData, password: hashedPassword });
|
|
@@ -35,11 +35,11 @@ class UserService {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
public async updateUser(userId: string, userData: CreateUserDto): Promise<User> {
|
|
38
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
38
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
39
39
|
|
|
40
40
|
if (userData.email) {
|
|
41
41
|
const findUser: User = await userModel.findOne({ email: userData.email });
|
|
42
|
-
if (findUser && findUser._id != userId) throw new HttpException(409, `
|
|
42
|
+
if (findUser && findUser._id != userId) throw new HttpException(409, `This email ${userData.email} already exists`);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
if (userData.password) {
|
|
@@ -48,14 +48,14 @@ class UserService {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
const updateUserById: User = await userModel.findByIdAndUpdate(userId, { userData });
|
|
51
|
-
if (!updateUserById) throw new HttpException(409, "
|
|
51
|
+
if (!updateUserById) throw new HttpException(409, "User doesn't exist");
|
|
52
52
|
|
|
53
53
|
return updateUserById;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
public async deleteUser(userId: string): Promise<User> {
|
|
57
57
|
const deleteUserById: User = await userModel.findByIdAndDelete(userId);
|
|
58
|
-
if (!deleteUserById) throw new HttpException(409, "
|
|
58
|
+
if (!deleteUserById) throw new HttpException(409, "User doesn't exist");
|
|
59
59
|
|
|
60
60
|
return deleteUserById;
|
|
61
61
|
}
|
package/lib/typeorm/package.json
CHANGED
|
@@ -18,60 +18,60 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"bcrypt": "^5.0.1",
|
|
20
20
|
"class-transformer": "^0.5.1",
|
|
21
|
-
"class-validator": "^0.13.
|
|
21
|
+
"class-validator": "^0.13.2",
|
|
22
22
|
"compression": "^1.7.4",
|
|
23
|
-
"cookie-parser": "^1.4.
|
|
23
|
+
"cookie-parser": "^1.4.6",
|
|
24
24
|
"cors": "^2.8.5",
|
|
25
|
-
"dotenv": "^
|
|
26
|
-
"envalid": "^7.1
|
|
27
|
-
"express": "^4.
|
|
28
|
-
"helmet": "^
|
|
25
|
+
"dotenv": "^16.0.1",
|
|
26
|
+
"envalid": "^7.3.1",
|
|
27
|
+
"express": "^4.18.1",
|
|
28
|
+
"helmet": "^5.1.1",
|
|
29
29
|
"hpp": "^0.2.3",
|
|
30
30
|
"jsonwebtoken": "^8.5.1",
|
|
31
31
|
"morgan": "^1.10.0",
|
|
32
|
-
"pg": "^8.
|
|
32
|
+
"pg": "^8.7.3",
|
|
33
33
|
"reflect-metadata": "^0.1.13",
|
|
34
|
-
"swagger-jsdoc": "^6.
|
|
35
|
-
"swagger-ui-express": "^4.
|
|
36
|
-
"typeorm": "^0.2.
|
|
37
|
-
"winston": "^3.
|
|
38
|
-
"winston-daily-rotate-file": "^4.
|
|
34
|
+
"swagger-jsdoc": "^6.2.1",
|
|
35
|
+
"swagger-ui-express": "^4.5.0",
|
|
36
|
+
"typeorm": "^0.2.45",
|
|
37
|
+
"winston": "^3.8.1",
|
|
38
|
+
"winston-daily-rotate-file": "^4.7.1"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@swc/cli": "^0.1.
|
|
42
|
-
"@swc/core": "^1.2.
|
|
41
|
+
"@swc/cli": "^0.1.57",
|
|
42
|
+
"@swc/core": "^1.2.220",
|
|
43
43
|
"@types/bcrypt": "^5.0.0",
|
|
44
|
-
"@types/compression": "^1.7.
|
|
45
|
-
"@types/cookie-parser": "^1.4.
|
|
46
|
-
"@types/cors": "^2.8.
|
|
44
|
+
"@types/compression": "^1.7.2",
|
|
45
|
+
"@types/cookie-parser": "^1.4.3",
|
|
46
|
+
"@types/cors": "^2.8.12",
|
|
47
47
|
"@types/express": "^4.17.13",
|
|
48
|
-
"@types/hpp": "^0.2.
|
|
49
|
-
"@types/jest": "
|
|
50
|
-
"@types/jsonwebtoken": "^8.5.
|
|
48
|
+
"@types/hpp": "^0.2.2",
|
|
49
|
+
"@types/jest": "^28.1.6",
|
|
50
|
+
"@types/jsonwebtoken": "^8.5.8",
|
|
51
51
|
"@types/morgan": "^1.9.3",
|
|
52
|
-
"@types/node": "^
|
|
53
|
-
"@types/supertest": "^2.0.
|
|
52
|
+
"@types/node": "^17.0.45",
|
|
53
|
+
"@types/supertest": "^2.0.12",
|
|
54
54
|
"@types/swagger-jsdoc": "^6.0.1",
|
|
55
55
|
"@types/swagger-ui-express": "^4.1.3",
|
|
56
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
57
|
-
"@typescript-eslint/parser": "^
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "^5.29.0",
|
|
57
|
+
"@typescript-eslint/parser": "^5.29.0",
|
|
58
58
|
"cross-env": "^7.0.3",
|
|
59
|
-
"eslint": "^
|
|
60
|
-
"eslint-config-prettier": "^8.
|
|
61
|
-
"eslint-plugin-prettier": "^
|
|
62
|
-
"husky": "^
|
|
63
|
-
"jest": "^
|
|
64
|
-
"lint-staged": "^
|
|
59
|
+
"eslint": "^8.20.0",
|
|
60
|
+
"eslint-config-prettier": "^8.5.0",
|
|
61
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
62
|
+
"husky": "^8.0.1",
|
|
63
|
+
"jest": "^28.1.1",
|
|
64
|
+
"lint-staged": "^13.0.3",
|
|
65
65
|
"node-config": "^0.0.2",
|
|
66
|
-
"node-gyp": "^
|
|
67
|
-
"nodemon": "^2.0.
|
|
68
|
-
"pm2": "^5.
|
|
69
|
-
"prettier": "^2.
|
|
70
|
-
"supertest": "^6.2.
|
|
71
|
-
"ts-jest": "^
|
|
72
|
-
"ts-node": "^10.
|
|
73
|
-
"tsc-alias": "^1.
|
|
74
|
-
"tsconfig-paths": "^
|
|
75
|
-
"typescript": "^4.
|
|
66
|
+
"node-gyp": "^9.1.0",
|
|
67
|
+
"nodemon": "^2.0.19",
|
|
68
|
+
"pm2": "^5.2.0",
|
|
69
|
+
"prettier": "^2.7.1",
|
|
70
|
+
"supertest": "^6.2.4",
|
|
71
|
+
"ts-jest": "^28.0.7",
|
|
72
|
+
"ts-node": "^10.9.1",
|
|
73
|
+
"tsc-alias": "^1.7.0",
|
|
74
|
+
"tsconfig-paths": "^4.0.0",
|
|
75
|
+
"typescript": "^4.7.4"
|
|
76
76
|
}
|
|
77
|
-
}
|
|
77
|
+
}
|
|
@@ -5,7 +5,7 @@ import { DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_DATABASE } from '@config';
|
|
|
5
5
|
export const dbConnection: ConnectionOptions = {
|
|
6
6
|
type: 'postgres',
|
|
7
7
|
host: DB_HOST,
|
|
8
|
-
port: DB_PORT,
|
|
8
|
+
port: Number(DB_PORT),
|
|
9
9
|
username: DB_USER,
|
|
10
10
|
password: DB_PASSWORD,
|
|
11
11
|
database: DB_DATABASE,
|
|
@@ -12,10 +12,10 @@ import { isEmpty } from '@utils/util';
|
|
|
12
12
|
@EntityRepository()
|
|
13
13
|
class AuthService extends Repository<UserEntity> {
|
|
14
14
|
public async signup(userData: CreateUserDto): Promise<User> {
|
|
15
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
15
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
16
16
|
|
|
17
17
|
const findUser: User = await UserEntity.findOne({ where: { email: userData.email } });
|
|
18
|
-
if (findUser) throw new HttpException(409, `
|
|
18
|
+
if (findUser) throw new HttpException(409, `This email ${userData.email} already exists`);
|
|
19
19
|
|
|
20
20
|
const hashedPassword = await hash(userData.password, 10);
|
|
21
21
|
const createUserData: User = await UserEntity.create({ ...userData, password: hashedPassword }).save();
|
|
@@ -23,13 +23,13 @@ class AuthService extends Repository<UserEntity> {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
public async login(userData: CreateUserDto): Promise<{ cookie: string; findUser: User }> {
|
|
26
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
26
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
27
27
|
|
|
28
28
|
const findUser: User = await UserEntity.findOne({ where: { email: userData.email } });
|
|
29
|
-
if (!findUser) throw new HttpException(409, `
|
|
29
|
+
if (!findUser) throw new HttpException(409, `This email ${userData.email} was not found`);
|
|
30
30
|
|
|
31
31
|
const isPasswordMatching: boolean = await compare(userData.password, findUser.password);
|
|
32
|
-
if (!isPasswordMatching) throw new HttpException(409, "
|
|
32
|
+
if (!isPasswordMatching) throw new HttpException(409, "Password not matching");
|
|
33
33
|
|
|
34
34
|
const tokenData = this.createToken(findUser);
|
|
35
35
|
const cookie = this.createCookie(tokenData);
|
|
@@ -38,10 +38,10 @@ class AuthService extends Repository<UserEntity> {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
public async logout(userData: User): Promise<User> {
|
|
41
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
41
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
42
42
|
|
|
43
43
|
const findUser: User = await UserEntity.findOne({ where: { email: userData.email, password: userData.password } });
|
|
44
|
-
if (!findUser) throw new HttpException(409, "
|
|
44
|
+
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
45
45
|
|
|
46
46
|
return findUser;
|
|
47
47
|
}
|
|
@@ -14,19 +14,19 @@ class UserService extends Repository<UserEntity> {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
public async findUserById(userId: number): Promise<User> {
|
|
17
|
-
if (isEmpty(userId)) throw new HttpException(400, "
|
|
17
|
+
if (isEmpty(userId)) throw new HttpException(400, "UserId is empty");
|
|
18
18
|
|
|
19
19
|
const findUser: User = await UserEntity.findOne({ where: { id: userId } });
|
|
20
|
-
if (!findUser) throw new HttpException(409, "
|
|
20
|
+
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
21
21
|
|
|
22
22
|
return findUser;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
public async createUser(userData: CreateUserDto): Promise<User> {
|
|
26
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
26
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
27
27
|
|
|
28
28
|
const findUser: User = await UserEntity.findOne({ where: { email: userData.email } });
|
|
29
|
-
if (findUser) throw new HttpException(409, `
|
|
29
|
+
if (findUser) throw new HttpException(409, `This email ${userData.email} already exists`);
|
|
30
30
|
|
|
31
31
|
const hashedPassword = await hash(userData.password, 10);
|
|
32
32
|
const createUserData: User = await UserEntity.create({ ...userData, password: hashedPassword }).save();
|
|
@@ -35,10 +35,10 @@ class UserService extends Repository<UserEntity> {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
public async updateUser(userId: number, userData: CreateUserDto): Promise<User> {
|
|
38
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
38
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
39
39
|
|
|
40
40
|
const findUser: User = await UserEntity.findOne({ where: { id: userId } });
|
|
41
|
-
if (!findUser) throw new HttpException(409, "
|
|
41
|
+
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
42
42
|
|
|
43
43
|
const hashedPassword = await hash(userData.password, 10);
|
|
44
44
|
await UserEntity.update(userId, { ...userData, password: hashedPassword });
|
|
@@ -48,10 +48,10 @@ class UserService extends Repository<UserEntity> {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
public async deleteUser(userId: number): Promise<User> {
|
|
51
|
-
if (isEmpty(userId)) throw new HttpException(400, "
|
|
51
|
+
if (isEmpty(userId)) throw new HttpException(400, "UserId is empty");
|
|
52
52
|
|
|
53
53
|
const findUser: User = await UserEntity.findOne({ where: { id: userId } });
|
|
54
|
-
if (!findUser) throw new HttpException(409, "
|
|
54
|
+
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
55
55
|
|
|
56
56
|
await UserEntity.delete({ id: userId });
|
|
57
57
|
return findUser;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import bcrypt from 'bcrypt';
|
|
2
2
|
import request from 'supertest';
|
|
3
|
-
import { createConnection,
|
|
3
|
+
import { createConnection, getConnection, Repository } from 'typeorm';
|
|
4
4
|
import App from '@/app';
|
|
5
5
|
import { dbConnection } from '@databases';
|
|
6
6
|
import { CreateUserDto } from '@dtos/users.dto';
|
|
7
|
+
import { UserEntity } from '@entities/users.entity';
|
|
7
8
|
import AuthRoute from '@routes/auth.route';
|
|
8
9
|
|
|
9
10
|
beforeAll(async () => {
|
|
@@ -11,7 +12,7 @@ beforeAll(async () => {
|
|
|
11
12
|
});
|
|
12
13
|
|
|
13
14
|
afterAll(async () => {
|
|
14
|
-
await
|
|
15
|
+
await getConnection().close();
|
|
15
16
|
});
|
|
16
17
|
|
|
17
18
|
describe('Testing Auth', () => {
|
|
@@ -23,8 +24,7 @@ describe('Testing Auth', () => {
|
|
|
23
24
|
};
|
|
24
25
|
|
|
25
26
|
const authRoute = new AuthRoute();
|
|
26
|
-
const
|
|
27
|
-
const userRepository = getRepository(users);
|
|
27
|
+
const userRepository = new Repository<UserEntity>();
|
|
28
28
|
|
|
29
29
|
userRepository.findOne = jest.fn().mockReturnValue(null);
|
|
30
30
|
userRepository.save = jest.fn().mockReturnValue({
|
|
@@ -46,8 +46,7 @@ describe('Testing Auth', () => {
|
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
const authRoute = new AuthRoute();
|
|
49
|
-
const
|
|
50
|
-
const userRepository = getRepository(users);
|
|
49
|
+
const userRepository = new Repository<UserEntity>();
|
|
51
50
|
|
|
52
51
|
userRepository.findOne = jest.fn().mockReturnValue({
|
|
53
52
|
id: 1,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import bcrypt from 'bcrypt';
|
|
2
2
|
import request from 'supertest';
|
|
3
|
-
import { createConnection,
|
|
3
|
+
import { createConnection, getConnection, Repository } from 'typeorm';
|
|
4
4
|
import App from '@/app';
|
|
5
5
|
import { dbConnection } from '@databases';
|
|
6
6
|
import { CreateUserDto } from '@dtos/users.dto';
|
|
7
|
+
import { UserEntity } from '@entities/users.entity';
|
|
7
8
|
import UserRoute from '@routes/users.route';
|
|
8
9
|
|
|
9
10
|
beforeAll(async () => {
|
|
@@ -11,15 +12,36 @@ beforeAll(async () => {
|
|
|
11
12
|
});
|
|
12
13
|
|
|
13
14
|
afterAll(async () => {
|
|
14
|
-
await
|
|
15
|
+
await getConnection().close();
|
|
15
16
|
});
|
|
16
17
|
|
|
17
18
|
describe('Testing Users', () => {
|
|
19
|
+
describe('[POST] /users', () => {
|
|
20
|
+
it('response Create user', async () => {
|
|
21
|
+
const userData: CreateUserDto = {
|
|
22
|
+
email: 'test@email.com',
|
|
23
|
+
password: 'q1w2e3r4!',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const usersRoute = new UserRoute();
|
|
27
|
+
const userRepository = new Repository<UserEntity>();
|
|
28
|
+
|
|
29
|
+
userRepository.findOne = jest.fn().mockReturnValue(null);
|
|
30
|
+
userRepository.save = jest.fn().mockReturnValue({
|
|
31
|
+
id: 1,
|
|
32
|
+
email: userData.email,
|
|
33
|
+
password: await bcrypt.hash(userData.password, 10),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const app = new App([usersRoute]);
|
|
37
|
+
return request(app.getServer()).post(`${usersRoute.path}`).send(userData).expect(201);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
18
41
|
describe('[GET] /users', () => {
|
|
19
42
|
it('response findAll users', async () => {
|
|
20
43
|
const usersRoute = new UserRoute();
|
|
21
|
-
const
|
|
22
|
-
const userRepository = getRepository(users);
|
|
44
|
+
const userRepository = new Repository<UserEntity>();
|
|
23
45
|
|
|
24
46
|
userRepository.find = jest.fn().mockReturnValue([
|
|
25
47
|
{
|
|
@@ -49,8 +71,7 @@ describe('Testing Users', () => {
|
|
|
49
71
|
const userId = 1;
|
|
50
72
|
|
|
51
73
|
const usersRoute = new UserRoute();
|
|
52
|
-
const
|
|
53
|
-
const userRepository = getRepository(users);
|
|
74
|
+
const userRepository = new Repository<UserEntity>();
|
|
54
75
|
|
|
55
76
|
userRepository.findOne = jest.fn().mockReturnValue({
|
|
56
77
|
id: userId,
|
|
@@ -63,29 +84,6 @@ describe('Testing Users', () => {
|
|
|
63
84
|
});
|
|
64
85
|
});
|
|
65
86
|
|
|
66
|
-
describe('[POST] /users', () => {
|
|
67
|
-
it('response Create user', async () => {
|
|
68
|
-
const userData: CreateUserDto = {
|
|
69
|
-
email: 'test@email.com',
|
|
70
|
-
password: 'q1w2e3r4!',
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const usersRoute = new UserRoute();
|
|
74
|
-
const users = usersRoute.usersController.userService.users;
|
|
75
|
-
const userRepository = getRepository(users);
|
|
76
|
-
|
|
77
|
-
userRepository.findOne = jest.fn().mockReturnValue(null);
|
|
78
|
-
userRepository.save = jest.fn().mockReturnValue({
|
|
79
|
-
id: 1,
|
|
80
|
-
email: userData.email,
|
|
81
|
-
password: await bcrypt.hash(userData.password, 10),
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
const app = new App([usersRoute]);
|
|
85
|
-
return request(app.getServer()).post(`${usersRoute.path}`).send(userData).expect(201);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
87
|
describe('[PUT] /users/:id', () => {
|
|
90
88
|
it('response Update user', async () => {
|
|
91
89
|
const userId = 1;
|
|
@@ -95,8 +93,7 @@ describe('Testing Users', () => {
|
|
|
95
93
|
};
|
|
96
94
|
|
|
97
95
|
const usersRoute = new UserRoute();
|
|
98
|
-
const
|
|
99
|
-
const userRepository = getRepository(users);
|
|
96
|
+
const userRepository = new Repository<UserEntity>();
|
|
100
97
|
|
|
101
98
|
userRepository.findOne = jest.fn().mockReturnValue({
|
|
102
99
|
id: userId,
|
|
@@ -124,8 +121,7 @@ describe('Testing Users', () => {
|
|
|
124
121
|
const userId = 1;
|
|
125
122
|
|
|
126
123
|
const usersRoute = new UserRoute();
|
|
127
|
-
const
|
|
128
|
-
const userRepository = getRepository(users);
|
|
124
|
+
const userRepository = new Repository<UserEntity>();
|
|
129
125
|
|
|
130
126
|
userRepository.findOne = jest.fn().mockReturnValue({
|
|
131
127
|
id: userId,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-express-starter",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.2.0",
|
|
4
4
|
"description": "Quick and Easy TypeScript Express Starter",
|
|
5
5
|
"author": "AGUMON <ljlm0402@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,14 +36,13 @@
|
|
|
36
36
|
"start": "node bin/cli.js"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"chalk": "^
|
|
39
|
+
"chalk": "^4.1.2",
|
|
40
40
|
"edit-json-file": "^1.5.0",
|
|
41
41
|
"gitignore": "^0.6.0",
|
|
42
42
|
"inquirer": "^6.5.2",
|
|
43
43
|
"ncp": "^2.0.0",
|
|
44
44
|
"ora": "^4.0.3"
|
|
45
45
|
},
|
|
46
|
-
"devDependencies": {},
|
|
47
46
|
"publishConfig": {
|
|
48
47
|
"access": "public"
|
|
49
48
|
},
|