express-generator-typescript 2.4.1 → 2.4.2
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/build.ts +1 -0
- package/lib/project-files/spec/tests/users.spec.ts +12 -6
- package/lib/project-files/src/other/classes.ts +4 -2
- package/lib/project-files-auth/build.ts +1 -0
- package/lib/project-files-auth/spec/tests/users.spec.ts +12 -6
- package/lib/project-files-auth/src/other/classes.ts +4 -2
- package/package.json +1 -1
|
@@ -82,6 +82,8 @@ describe('UserRouter', () => {
|
|
|
82
82
|
// Test add user
|
|
83
83
|
describe(`"POST:${Add}"`, () => {
|
|
84
84
|
|
|
85
|
+
const ERROR_MSG = `${ValidatorErr}"user".`;
|
|
86
|
+
|
|
85
87
|
const callApi = (reqBody: TReqBody) =>
|
|
86
88
|
agent
|
|
87
89
|
.post(Add)
|
|
@@ -103,13 +105,13 @@ describe('UserRouter', () => {
|
|
|
103
105
|
|
|
104
106
|
// Missing param
|
|
105
107
|
it('should return a JSON object with an error message of ' +
|
|
106
|
-
`"${
|
|
108
|
+
`"${ERROR_MSG}" and a status code of "${BAD_REQUEST}" if the user ` +
|
|
107
109
|
'param was missing.', (done) => {
|
|
108
110
|
// Call api
|
|
109
111
|
callApi({})
|
|
110
112
|
.end((_: Error, res: Response) => {
|
|
111
113
|
expect(res.status).toBe(BAD_REQUEST);
|
|
112
|
-
expect(res.body.error).toBe(
|
|
114
|
+
expect(res.body.error).toBe(ERROR_MSG);
|
|
113
115
|
done();
|
|
114
116
|
});
|
|
115
117
|
});
|
|
@@ -118,6 +120,8 @@ describe('UserRouter', () => {
|
|
|
118
120
|
// ** Update users ** //
|
|
119
121
|
describe(`"PUT:${Update}"`, () => {
|
|
120
122
|
|
|
123
|
+
const ERROR_MSG = `${ValidatorErr}"user".`;
|
|
124
|
+
|
|
121
125
|
const callApi = (reqBody: TReqBody) =>
|
|
122
126
|
agent
|
|
123
127
|
.put(Update)
|
|
@@ -140,13 +144,13 @@ describe('UserRouter', () => {
|
|
|
140
144
|
|
|
141
145
|
// Param missing
|
|
142
146
|
it('should return a JSON object with an error message of ' +
|
|
143
|
-
`"${
|
|
147
|
+
`"${ERROR_MSG}" and a status code of "${BAD_REQUEST}" if the user ` +
|
|
144
148
|
'param was missing.', (done) => {
|
|
145
149
|
// Call api
|
|
146
150
|
callApi({})
|
|
147
151
|
.end((_: Error, res: Response) => {
|
|
148
152
|
expect(res.status).toBe(BAD_REQUEST);
|
|
149
|
-
expect(res.body.error).toBe(
|
|
153
|
+
expect(res.body.error).toBe(ERROR_MSG);
|
|
150
154
|
done();
|
|
151
155
|
});
|
|
152
156
|
});
|
|
@@ -168,6 +172,8 @@ describe('UserRouter', () => {
|
|
|
168
172
|
// ** Delete user ** //
|
|
169
173
|
describe(`"DELETE:${Delete}"`, () => {
|
|
170
174
|
|
|
175
|
+
const VALIDATOR_ERR = `${ValidatorErr}"id".`;
|
|
176
|
+
|
|
171
177
|
const callApi = (id: number) =>
|
|
172
178
|
agent
|
|
173
179
|
.delete(insertUrlParams(Delete, { id }));
|
|
@@ -201,11 +207,11 @@ describe('UserRouter', () => {
|
|
|
201
207
|
|
|
202
208
|
// Invalid param
|
|
203
209
|
it(`should return a status code of "${BAD_REQUEST}" and return an error ` +
|
|
204
|
-
`message of "${
|
|
210
|
+
`message of "${VALIDATOR_ERR}" if the id was not a valid number`, (done) => {
|
|
205
211
|
callApi('horse' as unknown as number)
|
|
206
212
|
.end((_: Error, res: Response) => {
|
|
207
213
|
expect(res.status).toBe(BAD_REQUEST);
|
|
208
|
-
expect(res.body.error).toBe(
|
|
214
|
+
expect(res.body.error).toBe(VALIDATOR_ERR);
|
|
209
215
|
done();
|
|
210
216
|
});
|
|
211
217
|
});
|
|
@@ -9,8 +9,10 @@ import HttpStatusCodes from '@src/constants/HttpStatusCodes';
|
|
|
9
9
|
* Error with status code and message
|
|
10
10
|
*/
|
|
11
11
|
export class RouteError extends Error {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
|
|
13
|
+
public status: HttpStatusCodes;
|
|
14
|
+
|
|
15
|
+
public constructor(status: HttpStatusCodes, message: string) {
|
|
14
16
|
super(message);
|
|
15
17
|
this.status = status;
|
|
16
18
|
}
|
|
@@ -90,6 +90,8 @@ describe('UserRouter', () => {
|
|
|
90
90
|
// Test add user
|
|
91
91
|
describe(`"POST:${Add}"`, () => {
|
|
92
92
|
|
|
93
|
+
const ERROR_MSG = `${ValidatorErr}"user".`;
|
|
94
|
+
|
|
93
95
|
const callApi = (reqBody: TReqBody) =>
|
|
94
96
|
agent
|
|
95
97
|
.post(Add)
|
|
@@ -112,13 +114,13 @@ describe('UserRouter', () => {
|
|
|
112
114
|
|
|
113
115
|
// Missing param
|
|
114
116
|
it('should return a JSON object with an error message of ' +
|
|
115
|
-
`"${
|
|
117
|
+
`"${ERROR_MSG}" and a status code of "${BAD_REQUEST}" if the user ` +
|
|
116
118
|
'param was missing.', (done) => {
|
|
117
119
|
// Call api
|
|
118
120
|
callApi({})
|
|
119
121
|
.end((_: Error, res: Response) => {
|
|
120
122
|
expect(res.status).toBe(BAD_REQUEST);
|
|
121
|
-
expect(res.body.error).toBe(
|
|
123
|
+
expect(res.body.error).toBe(ERROR_MSG);
|
|
122
124
|
done();
|
|
123
125
|
});
|
|
124
126
|
});
|
|
@@ -127,6 +129,8 @@ describe('UserRouter', () => {
|
|
|
127
129
|
// ** Update users ** //
|
|
128
130
|
describe(`"PUT:${Update}"`, () => {
|
|
129
131
|
|
|
132
|
+
const ERROR_MSG = `${ValidatorErr}"user".`;
|
|
133
|
+
|
|
130
134
|
const callApi = (reqBody: TReqBody) =>
|
|
131
135
|
agent
|
|
132
136
|
.put(Update)
|
|
@@ -150,13 +154,13 @@ describe('UserRouter', () => {
|
|
|
150
154
|
|
|
151
155
|
// Param missing
|
|
152
156
|
it('should return a JSON object with an error message of ' +
|
|
153
|
-
`"${
|
|
157
|
+
`"${ERROR_MSG}" and a status code of "${BAD_REQUEST}" if the user ` +
|
|
154
158
|
'param was missing.', (done) => {
|
|
155
159
|
// Call api
|
|
156
160
|
callApi({})
|
|
157
161
|
.end((_: Error, res: Response) => {
|
|
158
162
|
expect(res.status).toBe(BAD_REQUEST);
|
|
159
|
-
expect(res.body.error).toBe(
|
|
163
|
+
expect(res.body.error).toBe(ERROR_MSG);
|
|
160
164
|
done();
|
|
161
165
|
});
|
|
162
166
|
});
|
|
@@ -178,6 +182,8 @@ describe('UserRouter', () => {
|
|
|
178
182
|
// ** Delete user ** //
|
|
179
183
|
describe(`"DELETE:${Delete}"`, () => {
|
|
180
184
|
|
|
185
|
+
const VALIDATOR_ERR = `${ValidatorErr}"id".`;
|
|
186
|
+
|
|
181
187
|
const callApi = (id: number) =>
|
|
182
188
|
agent
|
|
183
189
|
.delete(insertUrlParams(Delete, { id }))
|
|
@@ -212,11 +218,11 @@ describe('UserRouter', () => {
|
|
|
212
218
|
|
|
213
219
|
// Invalid param
|
|
214
220
|
it(`should return a status code of "${BAD_REQUEST}" and return an error ` +
|
|
215
|
-
`message of "${
|
|
221
|
+
`message of "${VALIDATOR_ERR}" if the id was not a valid number`, (done) => {
|
|
216
222
|
callApi('horse' as unknown as number)
|
|
217
223
|
.end((_: Error, res: Response) => {
|
|
218
224
|
expect(res.status).toBe(BAD_REQUEST);
|
|
219
|
-
expect(res.body.error).toBe(
|
|
225
|
+
expect(res.body.error).toBe(VALIDATOR_ERR);
|
|
220
226
|
done();
|
|
221
227
|
});
|
|
222
228
|
});
|
|
@@ -9,8 +9,10 @@ import HttpStatusCodes from '@src/constants/HttpStatusCodes';
|
|
|
9
9
|
* Error with status code and message
|
|
10
10
|
*/
|
|
11
11
|
export class RouteError extends Error {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
|
|
13
|
+
public status: HttpStatusCodes;
|
|
14
|
+
|
|
15
|
+
public constructor(status: HttpStatusCodes, message: string) {
|
|
14
16
|
super(message);
|
|
15
17
|
this.status = status;
|
|
16
18
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-generator-typescript",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.2",
|
|
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",
|