express-generator-typescript 2.4.6 → 2.4.7

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.
@@ -54,7 +54,7 @@
54
54
  "@types/jsonwebtoken": "^8.5.9",
55
55
  "@types/morgan": "^1.9.3",
56
56
  "@types/node": "^18.7.14",
57
- "@types/supertest": "^2.0.12",
57
+ "@types/supertest": "^6.0.2",
58
58
  "@typescript-eslint/eslint-plugin": "^5.36.1",
59
59
  "@typescript-eslint/parser": "^5.36.1",
60
60
  "eslint": "^8.23.0",
@@ -63,7 +63,7 @@
63
63
  "fs-extra": "^10.1.0",
64
64
  "jasmine": "^4.3.0",
65
65
  "nodemon": "^2.0.19",
66
- "supertest": "^6.2.4",
66
+ "supertest": "^6.3.4",
67
67
  "ts-node": "^10.9.1",
68
68
  "tsconfig-paths": "^4.1.0",
69
69
  "typescript": "^4.8.2"
@@ -1,11 +1,12 @@
1
- import supertest, { SuperTest, Test, Response } from 'supertest';
1
+ import supertest, { Test, Response } from 'supertest';
2
+ import TestAgent from 'supertest/lib/agent';
2
3
  import { defaultErrMsg as ValidatorErr } from 'jet-validator';
3
4
  import insertUrlParams from 'inserturlparams';
4
5
 
5
6
  import app from '@src/server';
6
7
 
7
8
  import UserRepo from '@src/repos/UserRepo';
8
- import User from '@src/models/User';
9
+ import User, { IUser } from '@src/models/User';
9
10
  import HttpStatusCodes from '@src/constants/HttpStatusCodes';
10
11
  import { USER_NOT_FOUND_ERR } from '@src/services/UserService';
11
12
 
@@ -36,11 +37,21 @@ const DummyUserData = {
36
37
  } as const;
37
38
 
38
39
 
40
+ // **** Types **** //
41
+
42
+ type TRes = Omit<Response, 'body'> & {
43
+ body: {
44
+ users: IUser[];
45
+ error: string;
46
+ }
47
+ };
48
+
49
+
39
50
  // **** Tests **** //
40
51
 
41
52
  describe('UserRouter', () => {
42
53
 
43
- let agent: SuperTest<Test>;
54
+ let agent: TestAgent<Test>;
44
55
 
45
56
  // Run before all tests
46
57
  beforeAll((done) => {
@@ -60,7 +71,7 @@ describe('UserRouter', () => {
60
71
  spyOn(UserRepo, 'getAll').and.resolveTo([...DummyGetAllUsers]);
61
72
  // Call API
62
73
  callApi()
63
- .end((_: Error, res: Response) => {
74
+ .end((_: Error, res: TRes) => {
64
75
  expect(res.status).toBe(OK);
65
76
  for (let i = 0; i < res.body.users.length; i++) {
66
77
  const user = res.body.users[i];
@@ -88,7 +99,7 @@ describe('UserRouter', () => {
88
99
  spyOn(UserRepo, 'add').and.resolveTo();
89
100
  // Call api
90
101
  callApi(DummyUserData)
91
- .end((_: Error, res: Response) => {
102
+ .end((_: Error, res: TRes) => {
92
103
  expect(res.status).toBe(CREATED);
93
104
  expect(res.body.error).toBeUndefined();
94
105
  done();
@@ -101,7 +112,7 @@ describe('UserRouter', () => {
101
112
  'param was missing.', (done) => {
102
113
  // Call api
103
114
  callApi({})
104
- .end((_: Error, res: Response) => {
115
+ .end((_: Error, res: TRes) => {
105
116
  expect(res.status).toBe(BAD_REQUEST);
106
117
  expect(res.body.error).toBe(ERROR_MSG);
107
118
  done();
@@ -127,7 +138,7 @@ describe('UserRouter', () => {
127
138
  spyOn(UserRepo, 'persists').and.resolveTo(true);
128
139
  // Call api
129
140
  callApi(DummyUserData)
130
- .end((_: Error, res: Response) => {
141
+ .end((_: Error, res: TRes) => {
131
142
  expect(res.status).toBe(OK);
132
143
  expect(res.body.error).toBeUndefined();
133
144
  done();
@@ -140,7 +151,7 @@ describe('UserRouter', () => {
140
151
  'param was missing.', (done) => {
141
152
  // Call api
142
153
  callApi({})
143
- .end((_: Error, res: Response) => {
154
+ .end((_: Error, res: TRes) => {
144
155
  expect(res.status).toBe(BAD_REQUEST);
145
156
  expect(res.body.error).toBe(ERROR_MSG);
146
157
  done();
@@ -153,7 +164,7 @@ describe('UserRouter', () => {
153
164
  'was not found.', (done) => {
154
165
  // Call api
155
166
  callApi(DummyUserData)
156
- .end((_: Error, res: Response) => {
167
+ .end((_: Error, res: TRes) => {
157
168
  expect(res.status).toBe(NOT_FOUND);
158
169
  expect(res.body.error).toBe(USER_NOT_FOUND_ERR);
159
170
  done();
@@ -178,7 +189,7 @@ describe('UserRouter', () => {
178
189
  spyOn(UserRepo, 'persists').and.resolveTo(true);
179
190
  // Call api
180
191
  callApi(5)
181
- .end((_: Error, res: Response) => {
192
+ .end((_: Error, res: TRes) => {
182
193
  expect(res.status).toBe(OK);
183
194
  expect(res.body.error).toBeUndefined();
184
195
  done();
@@ -190,7 +201,7 @@ describe('UserRouter', () => {
190
201
  `"${USER_NOT_FOUND_ERR}" and a status code of "${NOT_FOUND}" if the id ` +
191
202
  'was not found.', (done) => {
192
203
  callApi(-1)
193
- .end((_: Error, res: Response) => {
204
+ .end((_: Error, res: TRes) => {
194
205
  expect(res.status).toBe(NOT_FOUND);
195
206
  expect(res.body.error).toBe(USER_NOT_FOUND_ERR);
196
207
  done();
@@ -199,9 +210,10 @@ describe('UserRouter', () => {
199
210
 
200
211
  // Invalid param
201
212
  it(`should return a status code of "${BAD_REQUEST}" and return an error ` +
202
- `message of "${VALIDATOR_ERR}" if the id was not a valid number`, (done) => {
213
+ `message of "${VALIDATOR_ERR}" if the id was not a valid number`,
214
+ (done) => {
203
215
  callApi('horse' as unknown as number)
204
- .end((_: Error, res: Response) => {
216
+ .end((_: Error, res: TRes) => {
205
217
  expect(res.status).toBe(BAD_REQUEST);
206
218
  expect(res.body.error).toBe(VALIDATOR_ERR);
207
219
  done();
@@ -54,7 +54,7 @@
54
54
  "@types/jsonwebtoken": "^8.5.9",
55
55
  "@types/morgan": "^1.9.3",
56
56
  "@types/node": "^18.7.14",
57
- "@types/supertest": "^2.0.12",
57
+ "@types/supertest": "^6.0.2",
58
58
  "@typescript-eslint/eslint-plugin": "^5.36.1",
59
59
  "@typescript-eslint/parser": "^5.36.1",
60
60
  "eslint": "^8.23.0",
@@ -63,7 +63,7 @@
63
63
  "fs-extra": "^10.1.0",
64
64
  "jasmine": "^4.3.0",
65
65
  "nodemon": "^2.0.19",
66
- "supertest": "^6.2.4",
66
+ "supertest": "^6.3.4",
67
67
  "ts-node": "^10.9.1",
68
68
  "tsconfig-paths": "^4.1.0",
69
69
  "typescript": "^4.8.2"
@@ -1,4 +1,5 @@
1
- import { SuperTest, Test, Response } from 'supertest';
1
+ import { Test, Response } from 'supertest';
2
+ import TestAgent from 'supertest/lib/agent';
2
3
 
3
4
  import User, { UserRoles } from '@src/models/User';
4
5
  import UserRepo from '@src/repos/UserRepo';
@@ -20,7 +21,7 @@ const LoginCreds = {
20
21
  /**
21
22
  * Login a user.
22
23
  */
23
- function login(beforeAgent: SuperTest<Test>, done: (arg: string) => void) {
24
+ function login(beforeAgent: TestAgent<Test>, done: (arg: string) => void) {
24
25
  // Setup dummy data
25
26
  const role = UserRoles.Admin,
26
27
  pwdHash = PwdUtil.hashSync(LoginCreds.password),
@@ -1,4 +1,4 @@
1
- import supertest, { SuperTest, Test, Response } from 'supertest';
1
+ import supertest, { Test, Response } from 'supertest';
2
2
 
3
3
  import app from '@src/server';
4
4
 
@@ -12,6 +12,7 @@ import HttpStatusCodes from '@src/constants/HttpStatusCodes';
12
12
 
13
13
  import Paths from 'spec/support/Paths';
14
14
  import { TReqBody } from 'spec/support/types';
15
+ import TestAgent from 'supertest/lib/agent';
15
16
 
16
17
 
17
18
  // **** Variables **** //
@@ -29,11 +30,20 @@ const LoginCreds = {
29
30
  } as const;
30
31
 
31
32
 
33
+ // **** Types **** //
34
+
35
+ type TRes = Omit<Response, 'body'> & {
36
+ body: {
37
+ error: string;
38
+ }
39
+ };
40
+
41
+
32
42
  // **** Tests **** //
33
43
 
34
44
  describe('AuthRouter', () => {
35
45
 
36
- let agent: SuperTest<Test>;
46
+ let agent: TestAgent<Test>;
37
47
 
38
48
  // Run before all tests
39
49
  beforeAll((done) => {
@@ -79,7 +89,7 @@ describe('AuthRouter', () => {
79
89
  spyOn(UserRepo, 'getOne').and.resolveTo(null);
80
90
  // Call
81
91
  callApi(LoginCreds)
82
- .end((_: Error, res: Response) => {
92
+ .end((_: Error, res: TRes) => {
83
93
  expect(res.status).toBe(UNAUTHORIZED);
84
94
  expect(res.body.error).toBe(EMAIL_NOT_FOUND_ERR);
85
95
  done();
@@ -98,7 +108,7 @@ describe('AuthRouter', () => {
98
108
  spyOn(UserRepo, 'getOne').and.resolveTo(loginUser);
99
109
  // Call API
100
110
  callApi(LoginCreds)
101
- .end((_: Error, res: Response) => {
111
+ .end((_: Error, res: TRes) => {
102
112
  expect(res.status).toBe(UNAUTHORIZED);
103
113
  expect(res.body.error).toBe(Errors.Unauth);
104
114
  done();
@@ -1,11 +1,12 @@
1
- import supertest, { SuperTest, Test, Response } from 'supertest';
1
+ import supertest, { Test, Response } from 'supertest';
2
+ import TestAgent from 'supertest/lib/agent';
2
3
  import { defaultErrMsg as ValidatorErr } from 'jet-validator';
3
4
  import insertUrlParams from 'inserturlparams';
4
5
 
5
6
  import app from '@src/server';
6
7
 
7
8
  import UserRepo from '@src/repos/UserRepo';
8
- import User from '@src/models/User';
9
+ import User, { IUser } from '@src/models/User';
9
10
  import HttpStatusCodes from '@src/constants/HttpStatusCodes';
10
11
  import { USER_NOT_FOUND_ERR } from '@src/services/UserService';
11
12
 
@@ -37,11 +38,21 @@ const DummyUserData = {
37
38
  } as const;
38
39
 
39
40
 
41
+ // **** Types **** //
42
+
43
+ type TRes = Omit<Response, 'body'> & {
44
+ body: {
45
+ users: IUser[];
46
+ error: string;
47
+ }
48
+ };
49
+
50
+
40
51
  // **** Tests **** //
41
52
 
42
53
  describe('UserRouter', () => {
43
54
 
44
- let agent: SuperTest<Test>,
55
+ let agent: TestAgent<Test>,
45
56
  jwtCookie: string;
46
57
 
47
58
  // Run before all tests
@@ -68,7 +79,7 @@ describe('UserRouter', () => {
68
79
  spyOn(UserRepo, 'getAll').and.resolveTo([...DummyGetAllUsers]);
69
80
  // Call API
70
81
  callApi()
71
- .end((_: Error, res: Response) => {
82
+ .end((_: Error, res: TRes) => {
72
83
  expect(res.status).toBe(OK);
73
84
  for (let i = 0; i < res.body.users.length; i++) {
74
85
  const user = res.body.users[i];
@@ -97,7 +108,7 @@ describe('UserRouter', () => {
97
108
  spyOn(UserRepo, 'add').and.resolveTo();
98
109
  // Call api
99
110
  callApi(DummyUserData)
100
- .end((_: Error, res: Response) => {
111
+ .end((_: Error, res: TRes) => {
101
112
  expect(res.status).toBe(CREATED);
102
113
  expect(res.body.error).toBeUndefined();
103
114
  done();
@@ -110,7 +121,7 @@ describe('UserRouter', () => {
110
121
  'param was missing.', (done) => {
111
122
  // Call api
112
123
  callApi({})
113
- .end((_: Error, res: Response) => {
124
+ .end((_: Error, res: TRes) => {
114
125
  expect(res.status).toBe(BAD_REQUEST);
115
126
  expect(res.body.error).toBe(ERROR_MSG);
116
127
  done();
@@ -137,7 +148,7 @@ describe('UserRouter', () => {
137
148
  spyOn(UserRepo, 'persists').and.resolveTo(true);
138
149
  // Call api
139
150
  callApi(DummyUserData)
140
- .end((_: Error, res: Response) => {
151
+ .end((_: Error, res: TRes) => {
141
152
  expect(res.status).toBe(OK);
142
153
  expect(res.body.error).toBeUndefined();
143
154
  done();
@@ -150,7 +161,7 @@ describe('UserRouter', () => {
150
161
  'param was missing.', (done) => {
151
162
  // Call api
152
163
  callApi({})
153
- .end((_: Error, res: Response) => {
164
+ .end((_: Error, res: TRes) => {
154
165
  expect(res.status).toBe(BAD_REQUEST);
155
166
  expect(res.body.error).toBe(ERROR_MSG);
156
167
  done();
@@ -163,7 +174,7 @@ describe('UserRouter', () => {
163
174
  'was not found.', (done) => {
164
175
  // Call api
165
176
  callApi(DummyUserData)
166
- .end((_: Error, res: Response) => {
177
+ .end((_: Error, res: TRes) => {
167
178
  expect(res.status).toBe(NOT_FOUND);
168
179
  expect(res.body.error).toBe(USER_NOT_FOUND_ERR);
169
180
  done();
@@ -189,7 +200,7 @@ describe('UserRouter', () => {
189
200
  spyOn(UserRepo, 'persists').and.resolveTo(true);
190
201
  // Call api
191
202
  callApi(5)
192
- .end((_: Error, res: Response) => {
203
+ .end((_: Error, res: TRes) => {
193
204
  expect(res.status).toBe(OK);
194
205
  expect(res.body.error).toBeUndefined();
195
206
  done();
@@ -201,7 +212,7 @@ describe('UserRouter', () => {
201
212
  `"${USER_NOT_FOUND_ERR}" and a status code of "${NOT_FOUND}" if the id ` +
202
213
  'was not found.', (done) => {
203
214
  callApi(-1)
204
- .end((_: Error, res: Response) => {
215
+ .end((_: Error, res: TRes) => {
205
216
  expect(res.status).toBe(NOT_FOUND);
206
217
  expect(res.body.error).toBe(USER_NOT_FOUND_ERR);
207
218
  done();
@@ -210,9 +221,10 @@ describe('UserRouter', () => {
210
221
 
211
222
  // Invalid param
212
223
  it(`should return a status code of "${BAD_REQUEST}" and return an error ` +
213
- `message of "${VALIDATOR_ERR}" if the id was not a valid number`, (done) => {
224
+ `message of "${VALIDATOR_ERR}" if the id was not a valid number`,
225
+ (done) => {
214
226
  callApi('horse' as unknown as number)
215
- .end((_: Error, res: Response) => {
227
+ .end((_: Error, res: TRes) => {
216
228
  expect(res.status).toBe(BAD_REQUEST);
217
229
  expect(res.body.error).toBe(VALIDATOR_ERR);
218
230
  done();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-generator-typescript",
3
- "version": "2.4.6",
3
+ "version": "2.4.7",
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",