Skip to content

Commit df551e5

Browse files
committed
Another round of typecheck.
Signed-off-by: Eric Le Ponner <eric.leponner@icloud.com>
1 parent 3ed6581 commit df551e5

11 files changed

Lines changed: 227 additions & 225 deletions

back-end/apps/api/test/spec/auth.e2e-spec.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ describe('Auth (e2e)', () => {
134134
{
135135
email: validEmail,
136136
},
137-
null,
137+
undefined,
138138
adminAuthToken,
139139
)
140140
.expect(201)
@@ -152,12 +152,12 @@ describe('Auth (e2e)', () => {
152152
const usersEndpoint = new Endpoint(server, '/users');
153153
const loginEndpoint = new Endpoint(server, '/auth/login');
154154

155-
const user = await getUser('userNew');
155+
const user = (await getUser('userNew'))!;
156156

157157
await usersEndpoint.delete(`${user.id}`, adminAuthToken).expect(200);
158158

159159
await endpoint
160-
.post({ email: user.email }, null, adminAuthToken)
160+
.post({ email: user.email }, undefined, adminAuthToken)
161161
.expect(201)
162162
.then(res => {
163163
expect(res.body).toEqual({
@@ -176,10 +176,10 @@ describe('Auth (e2e)', () => {
176176
it('(POST) should update password and resend email if users status is NEW and the sender is an admin', async () => {
177177
const userRepo = await getRepository(User);
178178

179-
const user = await getUser('userNew');
179+
const user = (await getUser('userNew'))!;
180180

181181
await endpoint
182-
.post({ email: user.email }, null, adminAuthToken)
182+
.post({ email: user.email }, undefined, adminAuthToken)
183183
.expect(201)
184184
.then(res => {
185185
expect(res.body).toEqual({
@@ -197,13 +197,13 @@ describe('Auth (e2e)', () => {
197197
});
198198

199199
it('(POST) should not register new user if already exists', async () => {
200-
const user = await getUser('user');
200+
const user = (await getUser('user'))!;
201201
await endpoint
202202
.post(
203203
{
204204
email: user.email,
205205
},
206-
null,
206+
undefined,
207207
adminAuthToken,
208208
)
209209
.expect(422);
@@ -223,7 +223,7 @@ describe('Auth (e2e)', () => {
223223
{
224224
email: validEmail,
225225
},
226-
null,
226+
undefined,
227227
userAuthToken,
228228
)
229229
.expect(403);
@@ -235,15 +235,15 @@ describe('Auth (e2e)', () => {
235235
{
236236
email: invalidEmail,
237237
},
238-
null,
238+
undefined,
239239
adminAuthToken,
240240
)
241241
.expect(400);
242242
});
243243

244244
it('(POST) should throw on missing email', async () => {
245245
await endpoint
246-
.post({}, null, adminAuthToken)
246+
.post({}, undefined, adminAuthToken)
247247
.expect(400)
248248
.expect({ statusCode: 400, message: 'No email specified.' });
249249
});
@@ -267,7 +267,7 @@ describe('Auth (e2e)', () => {
267267
oldPassword: dummy.password,
268268
newPassword: 'newPassword',
269269
},
270-
null,
270+
undefined,
271271
userAuthToken,
272272
)
273273
.expect(200);
@@ -284,7 +284,7 @@ describe('Auth (e2e)', () => {
284284
oldPassword: 'invalid',
285285
newPassword: 'newPassword',
286286
},
287-
null,
287+
undefined,
288288
userAuthToken,
289289
)
290290
.expect(400);
@@ -297,7 +297,7 @@ describe('Auth (e2e)', () => {
297297
oldPassword: dummy.password,
298298
newPassword: dummy.password,
299299
},
300-
null,
300+
undefined,
301301
userAuthToken,
302302
)
303303
.expect(400);
@@ -312,19 +312,19 @@ describe('Auth (e2e)', () => {
312312
});
313313

314314
it('(PATCH) should register new user if sender is admin', async () => {
315-
const user = await getUser('userNew');
315+
const user = (await getUser('userNew'))!;
316316

317-
return endpoint.patch({ id: user.id }, null, adminAuthToken).expect(200);
317+
return endpoint.patch({ id: user.id }, undefined, adminAuthToken).expect(200);
318318
});
319319

320320
it('(PATCH) should not register new user if sender is NOT admin', async () => {
321-
const user = await getUser('userNew');
321+
const user = (await getUser('userNew'))!;
322322

323-
return endpoint.patch({ id: user.id }, null, userAuthToken).expect(403);
323+
return endpoint.patch({ id: user.id }, undefined, userAuthToken).expect(403);
324324
});
325325

326326
it('(PATCH) should throw on invalid user id', async () => {
327-
await endpoint.patch({ id: 333333 }, null, adminAuthToken).expect(400);
327+
await endpoint.patch({ id: 333333 }, undefined, adminAuthToken).expect(400);
328328
});
329329
});
330330

@@ -336,7 +336,7 @@ describe('Auth (e2e)', () => {
336336
});
337337

338338
it('(POST) should mark the token as blacklisted', async () => {
339-
await endpoint.post({}, null, userAuthToken).expect(200);
339+
await endpoint.post({}, undefined, userAuthToken).expect(200);
340340
await request(server).get('/transactions/history?page=1&size=99').expect(401);
341341
});
342342

back-end/apps/api/test/spec/notification-preferences.e2e-spec.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ describe('Notification Preferences (e2e)', () => {
2929
adminAuthToken = await login(app, 'admin');
3030
userAuthToken = await login(app, 'user');
3131

32-
admin = await getUser('admin');
33-
user = await getUser('user');
32+
admin = (await getUser('admin'))!;
33+
user = (await getUser('user'))!;
3434
});
3535

3636
afterAll(async () => {
@@ -61,7 +61,7 @@ describe('Notification Preferences (e2e)', () => {
6161
email: false,
6262
inApp: false,
6363
},
64-
null,
64+
undefined,
6565
userAuthToken,
6666
);
6767

@@ -93,7 +93,7 @@ describe('Notification Preferences (e2e)', () => {
9393
email: false,
9494
inApp: false,
9595
},
96-
null,
96+
undefined,
9797
userAuthToken,
9898
);
9999

@@ -124,7 +124,7 @@ describe('Notification Preferences (e2e)', () => {
124124
type: NotificationType.TRANSACTION_CREATED,
125125
email: true,
126126
},
127-
null,
127+
undefined,
128128
userAuthToken,
129129
);
130130

@@ -155,7 +155,7 @@ describe('Notification Preferences (e2e)', () => {
155155
type: NotificationType.TRANSACTION_CREATED,
156156
inApp: true,
157157
},
158-
null,
158+
undefined,
159159
userAuthToken,
160160
);
161161

@@ -186,7 +186,7 @@ describe('Notification Preferences (e2e)', () => {
186186
{
187187
type: NotificationType.TRANSACTION_CREATED,
188188
},
189-
null,
189+
undefined,
190190
userAuthToken,
191191
)
192192
.expect(200);
@@ -213,23 +213,22 @@ describe('Notification Preferences (e2e)', () => {
213213
});
214214

215215
it('(PATCH) should throw if invalid body is passed', async () => {
216-
await endpoint.patch({ email: 'sad' }, null, userAuthToken).expect(400);
216+
await endpoint.patch({ email: 'sad' }, undefined, userAuthToken).expect(400);
217217

218-
await endpoint.patch({ inApp: 'sad' }, null, userAuthToken).expect(400);
218+
await endpoint.patch({ inApp: 'sad' }, undefined, userAuthToken).expect(400);
219219

220-
await endpoint.patch({ email: true, inApp: false }, null, userAuthToken).expect(400);
220+
await endpoint.patch({ email: true, inApp: false }, undefined, userAuthToken).expect(400);
221221
});
222222

223223
it('(PATCH) should NOT update the preferences if the user is not authenticated', async () => {
224-
await endpoint.patch({ email: true }, null).expect(401);
224+
await endpoint.patch({ email: true }, undefined).expect(401);
225225
});
226226

227227
it('(GET) should create the preferences if they do not exist', async () => {
228-
let preferences = await getPreferences(admin.id);
228+
const preferences = (await getPreferences(admin.id))!;
229229
expect(preferences).toEqual([]);
230230

231-
const { status, body } = await endpoint.get(null, adminAuthToken);
232-
preferences = await getPreferences(admin.id);
231+
const { status, body } = await endpoint.get(undefined, adminAuthToken);
233232

234233
expect(status).toBe(200);
235234
expect(body.length).toBe(Object.values(NotificationType).length);
@@ -249,9 +248,9 @@ describe('Notification Preferences (e2e)', () => {
249248
});
250249

251250
it('(GET) should return the preferences', async () => {
252-
const preferences = await getPreferences(user.id);
251+
const preferences = (await getPreferences(user.id))!;
253252

254-
const { status, body } = await endpoint.get(null, userAuthToken);
253+
const { status, body } = await endpoint.get(undefined, userAuthToken);
255254

256255
expect(status).toBe(200);
257256
expect(body.length).toBe(Object.values(NotificationType).length);
@@ -266,7 +265,7 @@ describe('Notification Preferences (e2e)', () => {
266265
});
267266

268267
it('(GET) should return the preferences for a given type', async () => {
269-
const { status, body } = await endpoint.get(null, userAuthToken, '?type=TRANSACTION_CREATED');
268+
const { status, body } = await endpoint.get(undefined, userAuthToken, '?type=TRANSACTION_CREATED');
270269

271270
expect(status).toBe(200);
272271
expect(body).toEqual([
@@ -280,11 +279,11 @@ describe('Notification Preferences (e2e)', () => {
280279
});
281280

282281
it('(GET) should throw if invalid query is passed', async () => {
283-
await endpoint.get(null, userAuthToken, '?type=INVALID').expect(400);
282+
await endpoint.get(undefined, userAuthToken, '?type=INVALID').expect(400);
284283
});
285284

286285
it('(GET) should not return the preferences if the user is not authenticated', async () => {
287-
await endpoint.get(null).expect(401);
286+
await endpoint.get(undefined).expect(401);
288287
});
289288
});
290289
});

back-end/apps/api/test/spec/notification-receiver.e2e-spec.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ describe('Notification Receiver (e2e)', () => {
2828

2929
userAuthToken = await login(app, 'user');
3030

31-
admin = await getUser('admin');
32-
user = await getUser('user');
31+
admin = (await getUser('admin'))!;
32+
user = (await getUser('user'))!;
3333
});
3434

3535
afterAll(async () => {
@@ -48,7 +48,7 @@ describe('Notification Receiver (e2e)', () => {
4848
where: { userId: user.id },
4949
});
5050

51-
const { status, body } = await endpoint.get(null, userAuthToken, '?page=1&size=10');
51+
const { status, body } = await endpoint.get(undefined, userAuthToken, '?page=1&size=10');
5252

5353
expect(status).toBe(200);
5454
expect(body.totalItems).toEqual(notificationForUser.length);
@@ -62,7 +62,7 @@ describe('Notification Receiver (e2e)', () => {
6262
});
6363

6464
const { status, body } = await endpoint.get(
65-
null,
65+
undefined,
6666
userAuthToken,
6767
'?page=1&size=10&filter=isRead:eq:false',
6868
);
@@ -84,7 +84,7 @@ describe('Notification Receiver (e2e)', () => {
8484
});
8585

8686
const { status, body } = await endpoint.get(
87-
null,
87+
undefined,
8888
userAuthToken,
8989
'?page=1&size=10&filter=type:eq:TRANSACTION_CREATED',
9090
);
@@ -108,7 +108,7 @@ describe('Notification Receiver (e2e)', () => {
108108
where: { userId: user.id },
109109
});
110110

111-
const { status, text } = await endpoint.get(null, userAuthToken);
111+
const { status, text } = await endpoint.get(undefined, userAuthToken);
112112

113113
expect(status).toBe(200);
114114
expect(text).toBe(countForUser.toString());
@@ -119,7 +119,11 @@ describe('Notification Receiver (e2e)', () => {
119119
where: { userId: user.id, isRead: false },
120120
});
121121

122-
const { status, text } = await endpoint.get(null, userAuthToken, '?filter=isRead:eq:false');
122+
const { status, text } = await endpoint.get(
123+
undefined,
124+
userAuthToken,
125+
'?filter=isRead:eq:false',
126+
);
123127

124128
expect(status).toBe(200);
125129
expect(text).toBe(countForUser.toString());
@@ -136,7 +140,7 @@ describe('Notification Receiver (e2e)', () => {
136140
});
137141

138142
const { status, text } = await endpoint.get(
139-
null,
143+
undefined,
140144
userAuthToken,
141145
'?filter=type:eq:TRANSACTION_CREATED',
142146
);
@@ -199,9 +203,9 @@ describe('Notification Receiver (e2e)', () => {
199203
userAuthToken,
200204
);
201205

202-
const notification = await entityManager.findOne(NotificationReceiver, {
206+
const notification = (await entityManager.findOne(NotificationReceiver, {
203207
where: { id: notificationForUser[0].id },
204-
});
208+
}))!;
205209

206210
expect(status).toBe(200);
207211
expect(body.id).toEqual(notificationForUser[0].id);
@@ -222,9 +226,9 @@ describe('Notification Receiver (e2e)', () => {
222226
userAuthToken,
223227
);
224228

225-
const notification = await entityManager.findOne(NotificationReceiver, {
229+
const notification = (await entityManager.findOne(NotificationReceiver, {
226230
where: { id: notificationForAdmin[0].id },
227-
});
231+
}))!;
228232

229233
expect(status).toBe(400);
230234
expect(notification.isRead).toEqual(false);

0 commit comments

Comments
 (0)