express-generator-typescript 2.7.14 → 2.7.15
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/lib/project-files/src/main.ts +2 -2
- package/lib/project-files/src/models/{User.ts → UserModel.ts} +10 -11
- package/lib/project-files/src/models/common/{IModel.ts → types.ts} +2 -2
- package/lib/project-files/src/repos/MockOrm.ts +14 -13
- package/lib/project-files/src/repos/UserRepo.ts +9 -9
- package/lib/project-files/src/repos/common/database.json +22 -1
- package/lib/project-files/src/repos/common/database.test.json +1 -1
- package/lib/project-files/src/routes/UserRoutes.ts +7 -7
- package/lib/project-files/src/routes/apiRouter.ts +2 -2
- package/lib/project-files/src/services/UserService.ts +6 -6
- package/lib/project-files/tests/common/comparators.ts +3 -3
- package/lib/project-files/tests/common/error-utils.ts +3 -3
- package/lib/project-files/tests/common/supertest-types.ts +2 -2
- package/lib/project-files/tests/users.test.ts +9 -9
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@ import server from './server';
|
|
|
7
7
|
Constants
|
|
8
8
|
******************************************************************************/
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const SERVER_START_MESSAGE =
|
|
11
11
|
'Express server started on port: ' + EnvVars.Port.toString();
|
|
12
12
|
|
|
13
13
|
/******************************************************************************
|
|
@@ -19,6 +19,6 @@ server.listen(EnvVars.Port, (err) => {
|
|
|
19
19
|
if (!!err) {
|
|
20
20
|
logger.err(err.message);
|
|
21
21
|
} else {
|
|
22
|
-
logger.info(
|
|
22
|
+
logger.info(SERVER_START_MESSAGE);
|
|
23
23
|
}
|
|
24
24
|
});
|
|
@@ -3,20 +3,20 @@ import { parseObject, Schema, testObject } from 'jet-validators/utils';
|
|
|
3
3
|
|
|
4
4
|
import { transformIsDate } from '@src/common/utils/validators';
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { Entity } from './common/types';
|
|
7
7
|
|
|
8
8
|
/******************************************************************************
|
|
9
9
|
Constants
|
|
10
10
|
******************************************************************************/
|
|
11
11
|
|
|
12
|
-
const GetDefaults = ():
|
|
12
|
+
const GetDefaults = (): User => ({
|
|
13
13
|
id: 0,
|
|
14
14
|
name: '',
|
|
15
15
|
email: '',
|
|
16
16
|
created: new Date(),
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
-
const schema: Schema<
|
|
19
|
+
const schema: Schema<User> = {
|
|
20
20
|
id: isUnsignedInteger,
|
|
21
21
|
name: isString,
|
|
22
22
|
email: isString,
|
|
@@ -30,21 +30,20 @@ const schema: Schema<IUser> = {
|
|
|
30
30
|
/**
|
|
31
31
|
* @entity users
|
|
32
32
|
*/
|
|
33
|
-
export
|
|
33
|
+
export type User = Entity & {
|
|
34
34
|
name: string;
|
|
35
35
|
email: string;
|
|
36
|
-
}
|
|
36
|
+
};
|
|
37
37
|
|
|
38
38
|
/******************************************************************************
|
|
39
39
|
Setup
|
|
40
40
|
******************************************************************************/
|
|
41
41
|
|
|
42
|
-
|
|
43
42
|
// Set the "parseUser" function
|
|
44
|
-
const parseUser = parseObject<
|
|
43
|
+
const parseUser = parseObject<User>(schema);
|
|
45
44
|
|
|
46
45
|
// For the APIs make sure the right fields are complete
|
|
47
|
-
const
|
|
46
|
+
const isCompleteUser = testObject<User>({
|
|
48
47
|
...schema,
|
|
49
48
|
name: isNonEmptyString,
|
|
50
49
|
email: isNonEmptyString,
|
|
@@ -57,7 +56,7 @@ const testIsCompleteUser = testObject<IUser>({
|
|
|
57
56
|
/**
|
|
58
57
|
* New user object.
|
|
59
58
|
*/
|
|
60
|
-
function
|
|
59
|
+
function newUser(user?: Partial<User>): User {
|
|
61
60
|
return parseUser({ ...GetDefaults(), ...user }, (errors) => {
|
|
62
61
|
throw new Error('Setup new user failed ' + JSON.stringify(errors, null, 2));
|
|
63
62
|
});
|
|
@@ -68,6 +67,6 @@ function __new__(user?: Partial<IUser>): IUser {
|
|
|
68
67
|
******************************************************************************/
|
|
69
68
|
|
|
70
69
|
export default {
|
|
71
|
-
new:
|
|
72
|
-
isComplete:
|
|
70
|
+
new: newUser,
|
|
71
|
+
isComplete: isCompleteUser,
|
|
73
72
|
} as const;
|
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import jsonfile from 'jsonfile';
|
|
2
2
|
|
|
3
3
|
import EnvVars, { NodeEnvs } from '@src/common/constants/env';
|
|
4
|
-
import {
|
|
4
|
+
import { User } from '@src/models/UserModel';
|
|
5
5
|
|
|
6
6
|
/******************************************************************************
|
|
7
7
|
Constants
|
|
8
8
|
******************************************************************************/
|
|
9
9
|
|
|
10
|
-
const DATABASE_FILE_PATH =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
const DATABASE_FILE_PATH =
|
|
11
|
+
__dirname +
|
|
12
|
+
'/common' +
|
|
13
|
+
(EnvVars.NodeEnv === NodeEnvs.TEST
|
|
14
|
+
? '/database.test.json'
|
|
15
|
+
: '/database.json');
|
|
15
16
|
|
|
16
17
|
/******************************************************************************
|
|
17
18
|
Types
|
|
18
19
|
******************************************************************************/
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
users:
|
|
22
|
-
}
|
|
21
|
+
type Database = {
|
|
22
|
+
users: User[];
|
|
23
|
+
};
|
|
23
24
|
|
|
24
25
|
/******************************************************************************
|
|
25
26
|
Functions
|
|
@@ -28,14 +29,14 @@ interface IDatabase {
|
|
|
28
29
|
/**
|
|
29
30
|
* Fetch the json from the file.
|
|
30
31
|
*/
|
|
31
|
-
function openDb(): Promise<
|
|
32
|
-
return jsonfile.readFile(DATABASE_FILE_PATH) as Promise<
|
|
32
|
+
function openDb(): Promise<Database> {
|
|
33
|
+
return jsonfile.readFile(DATABASE_FILE_PATH) as Promise<Database>;
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
/**
|
|
36
37
|
* Update the file.
|
|
37
38
|
*/
|
|
38
|
-
function saveDb(db:
|
|
39
|
+
function saveDb(db: Database): Promise<void> {
|
|
39
40
|
return jsonfile.writeFile(DATABASE_FILE_PATH, db);
|
|
40
41
|
}
|
|
41
42
|
|
|
@@ -43,7 +44,7 @@ function saveDb(db: IDatabase): Promise<void> {
|
|
|
43
44
|
* Empty the database
|
|
44
45
|
*/
|
|
45
46
|
function cleanDb(): Promise<void> {
|
|
46
|
-
return jsonfile.writeFile(
|
|
47
|
+
return jsonfile.writeFile(DATABASE_FILE_PATH, {});
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
/******************************************************************************
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getRandomInt } from '@src/common/utils/number-utils';
|
|
2
|
-
import {
|
|
2
|
+
import { User } from '@src/models/UserModel';
|
|
3
3
|
|
|
4
4
|
import orm from './MockOrm';
|
|
5
5
|
|
|
@@ -10,7 +10,7 @@ import orm from './MockOrm';
|
|
|
10
10
|
/**
|
|
11
11
|
* Get one user.
|
|
12
12
|
*/
|
|
13
|
-
async function getOne(email: string): Promise<
|
|
13
|
+
async function getOne(email: string): Promise<User | null> {
|
|
14
14
|
const db = await orm.openDb();
|
|
15
15
|
for (const user of db.users) {
|
|
16
16
|
if (user.email === email) {
|
|
@@ -36,7 +36,7 @@ async function persists(id: number): Promise<boolean> {
|
|
|
36
36
|
/**
|
|
37
37
|
* Get all users.
|
|
38
38
|
*/
|
|
39
|
-
async function getAll(): Promise<
|
|
39
|
+
async function getAll(): Promise<User[]> {
|
|
40
40
|
const db = await orm.openDb();
|
|
41
41
|
return db.users;
|
|
42
42
|
}
|
|
@@ -44,7 +44,7 @@ async function getAll(): Promise<IUser[]> {
|
|
|
44
44
|
/**
|
|
45
45
|
* Add one user.
|
|
46
46
|
*/
|
|
47
|
-
async function add(user:
|
|
47
|
+
async function add(user: User): Promise<void> {
|
|
48
48
|
const db = await orm.openDb();
|
|
49
49
|
user.id = getRandomInt();
|
|
50
50
|
db.users.push(user);
|
|
@@ -54,7 +54,7 @@ async function add(user: IUser): Promise<void> {
|
|
|
54
54
|
/**
|
|
55
55
|
* Update a user.
|
|
56
56
|
*/
|
|
57
|
-
async function update(user:
|
|
57
|
+
async function update(user: User): Promise<void> {
|
|
58
58
|
const db = await orm.openDb();
|
|
59
59
|
for (let i = 0; i < db.users.length; i++) {
|
|
60
60
|
if (db.users[i].id === user.id) {
|
|
@@ -86,7 +86,7 @@ async function __delete__(id: number): Promise<void> {
|
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
88
|
* @testOnly
|
|
89
|
-
*
|
|
89
|
+
*
|
|
90
90
|
* Delete every user record.
|
|
91
91
|
*/
|
|
92
92
|
async function deleteAllUsers(): Promise<void> {
|
|
@@ -97,13 +97,13 @@ async function deleteAllUsers(): Promise<void> {
|
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
99
|
* @testOnly
|
|
100
|
-
*
|
|
100
|
+
*
|
|
101
101
|
* Insert multiple users. Can't do multiple at once cause using a plain file
|
|
102
102
|
* for now.
|
|
103
103
|
*/
|
|
104
104
|
async function insertMultiple(
|
|
105
|
-
users:
|
|
106
|
-
): Promise<
|
|
105
|
+
users: User[] | readonly User[],
|
|
106
|
+
): Promise<User[]> {
|
|
107
107
|
const db = await orm.openDb(),
|
|
108
108
|
usersF = [...users];
|
|
109
109
|
for (const user of usersF) {
|
|
@@ -1 +1,22 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"users": [
|
|
3
|
+
{
|
|
4
|
+
"id": 366115170645,
|
|
5
|
+
"name": "Sean Maxwell",
|
|
6
|
+
"email": "smaxwell@example.com",
|
|
7
|
+
"created": "2024-03-22T05:14:36.252Z"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": 310946254456,
|
|
11
|
+
"name": "John Smith",
|
|
12
|
+
"email": "john.smith@example.com",
|
|
13
|
+
"created": "2024-03-22T05:20:55.079Z"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"id": 143027113460,
|
|
17
|
+
"name": "Gordan Freeman",
|
|
18
|
+
"email": "nova@prospect.com",
|
|
19
|
+
"created": "2024-03-22T05:42:18.895Z"
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"users":[{"id":
|
|
1
|
+
{"users":[{"id":146631637670,"name":"Bill","email":"sean.maxwell@gmail.com","created":"2026-01-26T00:52:08.804Z"},{"id":498481378998,"name":"John Smith","email":"john.smith@gmail.com","created":"2026-01-26T00:52:08.804Z"},{"id":878476468362,"name":"Gordan Freeman","email":"gordan.freeman@gmail.com","created":"2026-01-26T00:52:08.804Z"}]}
|
|
@@ -2,7 +2,7 @@ import { isNumber } from 'jet-validators';
|
|
|
2
2
|
import { transform } from 'jet-validators/utils';
|
|
3
3
|
|
|
4
4
|
import HttpStatusCodes from '@src/common/constants/HttpStatusCodes';
|
|
5
|
-
import
|
|
5
|
+
import UserModel from '@src/models/UserModel';
|
|
6
6
|
import UserService from '@src/services/UserService';
|
|
7
7
|
|
|
8
8
|
import { IReq, IRes } from './common/express-types';
|
|
@@ -12,9 +12,9 @@ import parseReq from './common/parseReq';
|
|
|
12
12
|
Constants
|
|
13
13
|
******************************************************************************/
|
|
14
14
|
|
|
15
|
-
const
|
|
16
|
-
add: parseReq({ user:
|
|
17
|
-
update: parseReq({ user:
|
|
15
|
+
const reqValidators = {
|
|
16
|
+
add: parseReq({ user: UserModel.isComplete }),
|
|
17
|
+
update: parseReq({ user: UserModel.isComplete }),
|
|
18
18
|
delete: parseReq({ id: transform(Number, isNumber) }),
|
|
19
19
|
} as const;
|
|
20
20
|
|
|
@@ -38,7 +38,7 @@ async function getAll(_: IReq, res: IRes) {
|
|
|
38
38
|
* @route POST /api/users/add
|
|
39
39
|
*/
|
|
40
40
|
async function add(req: IReq, res: IRes) {
|
|
41
|
-
const { user } =
|
|
41
|
+
const { user } = reqValidators.add(req.body);
|
|
42
42
|
await UserService.addOne(user);
|
|
43
43
|
res.status(HttpStatusCodes.CREATED).end();
|
|
44
44
|
}
|
|
@@ -49,7 +49,7 @@ async function add(req: IReq, res: IRes) {
|
|
|
49
49
|
* @route PUT /api/users/update
|
|
50
50
|
*/
|
|
51
51
|
async function update(req: IReq, res: IRes) {
|
|
52
|
-
const { user } =
|
|
52
|
+
const { user } = reqValidators.update(req.body);
|
|
53
53
|
await UserService.updateOne(user);
|
|
54
54
|
res.status(HttpStatusCodes.OK).end();
|
|
55
55
|
}
|
|
@@ -60,7 +60,7 @@ async function update(req: IReq, res: IRes) {
|
|
|
60
60
|
* @route DELETE /api/users/delete/:id
|
|
61
61
|
*/
|
|
62
62
|
async function __delete__(req: IReq, res: IRes) {
|
|
63
|
-
const { id } =
|
|
63
|
+
const { id } = reqValidators.delete(req.params);
|
|
64
64
|
await UserService.delete(id);
|
|
65
65
|
res.status(HttpStatusCodes.OK).end();
|
|
66
66
|
}
|
|
@@ -10,7 +10,7 @@ import UserRoutes from './UserRoutes';
|
|
|
10
10
|
|
|
11
11
|
const apiRouter = Router();
|
|
12
12
|
|
|
13
|
-
// ----------------------- Add UserRouter
|
|
13
|
+
// ----------------------- Add UserRouter --------------------------------- //
|
|
14
14
|
|
|
15
15
|
const userRouter = Router();
|
|
16
16
|
|
|
@@ -22,7 +22,7 @@ userRouter.delete(Paths.Users.Delete, UserRoutes.delete);
|
|
|
22
22
|
apiRouter.use(Paths.Users._, userRouter);
|
|
23
23
|
|
|
24
24
|
/******************************************************************************
|
|
25
|
-
Export
|
|
25
|
+
Export
|
|
26
26
|
******************************************************************************/
|
|
27
27
|
|
|
28
28
|
export default apiRouter;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import HttpStatusCodes from '@src/common/constants/HttpStatusCodes';
|
|
2
2
|
import { RouteError } from '@src/common/utils/route-errors';
|
|
3
|
-
import {
|
|
3
|
+
import { User } from '@src/models/UserModel';
|
|
4
4
|
import UserRepo from '@src/repos/UserRepo';
|
|
5
5
|
|
|
6
6
|
/******************************************************************************
|
|
@@ -18,21 +18,21 @@ const Errors = {
|
|
|
18
18
|
/**
|
|
19
19
|
* Get all users.
|
|
20
20
|
*/
|
|
21
|
-
function getAll(): Promise<
|
|
21
|
+
function getAll(): Promise<User[]> {
|
|
22
22
|
return UserRepo.getAll();
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Add one user.
|
|
27
27
|
*/
|
|
28
|
-
function addOne(user:
|
|
28
|
+
function addOne(user: User): Promise<void> {
|
|
29
29
|
return UserRepo.add(user);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Update one user.
|
|
34
34
|
*/
|
|
35
|
-
async function updateOne(user:
|
|
35
|
+
async function updateOne(user: User): Promise<void> {
|
|
36
36
|
const persists = await UserRepo.persists(user.id);
|
|
37
37
|
if (!persists) {
|
|
38
38
|
throw new RouteError(HttpStatusCodes.NOT_FOUND, Errors.USER_NOT_FOUND);
|
|
@@ -43,7 +43,7 @@ async function updateOne(user: IUser): Promise<void> {
|
|
|
43
43
|
/**
|
|
44
44
|
* Delete a user by their id.
|
|
45
45
|
*/
|
|
46
|
-
async function
|
|
46
|
+
async function deleteOne(id: number): Promise<void> {
|
|
47
47
|
const persists = await UserRepo.persists(id);
|
|
48
48
|
if (!persists) {
|
|
49
49
|
throw new RouteError(HttpStatusCodes.NOT_FOUND, Errors.USER_NOT_FOUND);
|
|
@@ -60,5 +60,5 @@ export default {
|
|
|
60
60
|
getAll,
|
|
61
61
|
addOne,
|
|
62
62
|
updateOne,
|
|
63
|
-
delete:
|
|
63
|
+
delete: deleteOne,
|
|
64
64
|
} as const;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { User } from '@src/models/UserModel';
|
|
2
2
|
|
|
3
3
|
/******************************************************************************
|
|
4
4
|
Types
|
|
5
5
|
******************************************************************************/
|
|
6
6
|
|
|
7
|
-
type UserArray =
|
|
7
|
+
type UserArray = User[] | readonly User[];
|
|
8
8
|
|
|
9
9
|
/******************************************************************************
|
|
10
10
|
Functions
|
|
@@ -31,7 +31,7 @@ export function compareUserArrays(a: UserArray, b: UserArray): boolean {
|
|
|
31
31
|
/**
|
|
32
32
|
* Sort user array by email.
|
|
33
33
|
*/
|
|
34
|
-
function sortByEmail(arr: UserArray):
|
|
34
|
+
function sortByEmail(arr: UserArray): User[] {
|
|
35
35
|
return [...arr].sort((x, y) => {
|
|
36
36
|
return x.email.localeCompare(y.email);
|
|
37
37
|
});
|
|
@@ -5,7 +5,7 @@ import { ParseError, parseJson } from 'jet-validators/utils';
|
|
|
5
5
|
Types
|
|
6
6
|
******************************************************************************/
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
type ValidationError = {
|
|
9
9
|
message: string;
|
|
10
10
|
errors: ParseError[];
|
|
11
11
|
}
|
|
@@ -17,9 +17,9 @@ interface IValidationError {
|
|
|
17
17
|
/**
|
|
18
18
|
* JSON parse a validation error.
|
|
19
19
|
*/
|
|
20
|
-
export function parseValidationError(arg: unknown):
|
|
20
|
+
export function parseValidationError(arg: unknown): ValidationError {
|
|
21
21
|
if (!isString(arg)) {
|
|
22
22
|
throw new Error('Not a string');
|
|
23
23
|
}
|
|
24
|
-
return parseJson<
|
|
24
|
+
return parseJson<ValidationError>(arg);
|
|
25
25
|
}
|
|
@@ -6,10 +6,10 @@ import { Response } from 'supertest';
|
|
|
6
6
|
|
|
7
7
|
// Use generics to add properties to 'body'
|
|
8
8
|
export interface IRes<T = object> extends Omit<Response, 'body'> {
|
|
9
|
-
body: T & { error?: string |
|
|
9
|
+
body: T & { error?: string | ErrorObject };
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
interface
|
|
12
|
+
interface ErrorObject {
|
|
13
13
|
message: string;
|
|
14
14
|
[key: string]: unknown;
|
|
15
15
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import HttpStatusCodes from '@src/common/constants/HttpStatusCodes';
|
|
2
2
|
import { JetPaths as Paths } from '@src/common/constants/Paths';
|
|
3
3
|
import { ValidationError } from '@src/common/utils/route-errors';
|
|
4
|
-
import
|
|
4
|
+
import UserModel, { User } from '@src/models/UserModel';
|
|
5
5
|
import UserRepo from '@src/repos/UserRepo';
|
|
6
6
|
|
|
7
7
|
import { agent } from './support/agent';
|
|
@@ -15,9 +15,9 @@ import { compareUserArrays } from './common/comparators';
|
|
|
15
15
|
******************************************************************************/
|
|
16
16
|
|
|
17
17
|
const DUMMY_USERS = [
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
UserModel.new({ name: 'Sean Maxwell', email: 'sean.maxwell@gmail.com' }),
|
|
19
|
+
UserModel.new({ name: 'John Smith', email: 'john.smith@gmail.com' }),
|
|
20
|
+
UserModel.new({ name: 'Gordan Freeman', email: 'gordan.freeman@gmail.com' }),
|
|
21
21
|
] as const;
|
|
22
22
|
|
|
23
23
|
const { BAD_REQUEST, CREATED, OK, NOT_FOUND } = HttpStatusCodes;
|
|
@@ -30,7 +30,7 @@ const { BAD_REQUEST, CREATED, OK, NOT_FOUND } = HttpStatusCodes;
|
|
|
30
30
|
******************************************************************************/
|
|
31
31
|
|
|
32
32
|
describe('UserRouter', () => {
|
|
33
|
-
let dbUsers:
|
|
33
|
+
let dbUsers: User[] = [];
|
|
34
34
|
|
|
35
35
|
beforeEach(async () => {
|
|
36
36
|
await UserRepo.deleteAllUsers();
|
|
@@ -42,7 +42,7 @@ describe('UserRouter', () => {
|
|
|
42
42
|
'should return a JSON object with all the users and a status code of ' +
|
|
43
43
|
`"${OK}" if the request was successful.`,
|
|
44
44
|
async () => {
|
|
45
|
-
const res: IRes<{ users:
|
|
45
|
+
const res: IRes<{ users: User[] }> = await agent.get(Paths.Users.Get);
|
|
46
46
|
expect(res.status).toBe(OK);
|
|
47
47
|
expect(compareUserArrays(res.body.users, DUMMY_USERS)).toBeTruthy();
|
|
48
48
|
},
|
|
@@ -54,7 +54,7 @@ describe('UserRouter', () => {
|
|
|
54
54
|
`should return a status code of "${CREATED}" if the request was ` +
|
|
55
55
|
'successful.',
|
|
56
56
|
async () => {
|
|
57
|
-
const user =
|
|
57
|
+
const user = UserModel.new({ name: 'a', email: 'a@a.com' }),
|
|
58
58
|
res = await agent.post(Paths.Users.Add).send({ user });
|
|
59
59
|
expect(res.status).toBe(CREATED);
|
|
60
60
|
},
|
|
@@ -87,7 +87,7 @@ describe('UserRouter', () => {
|
|
|
87
87
|
'should return a JSON object with an error message and a status code ' +
|
|
88
88
|
`of "${BAD_REQUEST}" if id is the wrong data type`,
|
|
89
89
|
async () => {
|
|
90
|
-
const user =
|
|
90
|
+
const user = UserModel.new();
|
|
91
91
|
user.id = '5' as unknown as number;
|
|
92
92
|
const res: IRes = await agent.put(Paths.Users.Update).send({ user });
|
|
93
93
|
expect(res.status).toBe(BAD_REQUEST);
|
|
@@ -102,7 +102,7 @@ describe('UserRouter', () => {
|
|
|
102
102
|
`"${UserService.Errors.USER_NOT_FOUND}" and a status code of ` +
|
|
103
103
|
`"${NOT_FOUND}" if the id was not found.`,
|
|
104
104
|
async () => {
|
|
105
|
-
const user =
|
|
105
|
+
const user = UserModel.new({ id: 4, name: 'a', email: 'a@a.com' }),
|
|
106
106
|
res: IRes = await agent.put(Paths.Users.Update).send({ user });
|
|
107
107
|
expect(res.status).toBe(NOT_FOUND);
|
|
108
108
|
expect(res.body.error).toBe(UserService.Errors.USER_NOT_FOUND);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-generator-typescript",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.15",
|
|
4
4
|
"description": "Generate new Express applications similar to express-generate which but sets it up to use TypeScript instead",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"express-generator-typescript": "node bin/cli.js",
|