@tomei/sso 0.3.4 → 0.6.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/__tests__/unit/components/login-user/login-user.spec.ts +530 -59
- package/dist/__tests__/unit/components/login-user/login-user.spec.js +465 -45
- package/dist/__tests__/unit/components/login-user/login-user.spec.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/src/components/login-user/login-user.d.ts +4 -2
- package/dist/src/components/login-user/login-user.js +131 -63
- package/dist/src/components/login-user/login-user.js.map +1 -1
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.js +0 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/session/interfaces/session-service.interface.d.ts +1 -0
- package/dist/src/session/session.service.d.ts +1 -0
- package/dist/src/session/session.service.js +12 -0
- package/dist/src/session/session.service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/index.ts +1 -1
- package/package.json +4 -1
- package/src/components/login-user/login-user.ts +179 -89
- package/src/index.ts +0 -1
- package/src/session/interfaces/session-service.interface.ts +1 -0
- package/src/session/session.service.ts +10 -0
- package/src/mail/index.ts +0 -2
- package/src/mail/interfaces/index.ts +0 -2
- package/src/mail/interfaces/send-mail.interface.ts +0 -8
- package/src/mail/interfaces/send-new-login-alert.interface.ts +0 -6
- package/src/mail/mail.service.ts +0 -33
- package/src/mail/mail.ts +0 -40
@@ -1,11 +1,16 @@
|
|
1
1
|
import { IUserSession } from '../../../../src/interfaces/user-session.interface';
|
2
|
-
import {
|
2
|
+
import {
|
3
|
+
LoginHistoryRepository,
|
4
|
+
SessionService,
|
5
|
+
SystemAccessRepository,
|
6
|
+
SystemRepository,
|
7
|
+
} from '../../../../src';
|
3
8
|
import { LoginUser } from '../../../../src/components/login-user/login-user';
|
4
9
|
import { UserRepository } from '../../../../src/components/login-user/user.repository';
|
5
10
|
import { PasswordHashService } from '../../../../src/components/password-hash/password-hash.service';
|
6
|
-
import {
|
11
|
+
import { Mailer } from '@tomei/mailer';
|
7
12
|
describe('login-user', () => {
|
8
|
-
|
13
|
+
let user = {
|
9
14
|
id: 755,
|
10
15
|
email: 'ezcash+florence@tomei.com.my',
|
11
16
|
password:
|
@@ -54,13 +59,12 @@ describe('login-user', () => {
|
|
54
59
|
updatedAt: new Date('2022-04-18T04:07:40.000Z'),
|
55
60
|
systemPrivilege: {
|
56
61
|
privilegeId: 'ckymxuh8t000137t011w89zgk',
|
57
|
-
systemId:
|
58
|
-
code: '
|
62
|
+
systemId: 175,
|
63
|
+
code: 'Terminate Data',
|
59
64
|
module: null,
|
60
|
-
description:
|
61
|
-
|
62
|
-
|
63
|
-
updatedAt: new Date('2022-01-20T12:16:26.000Z'),
|
65
|
+
description: 'Allows the user to terminate a loan.',
|
66
|
+
createdAt: new Date(),
|
67
|
+
updatedAt: new Date(),
|
64
68
|
},
|
65
69
|
},
|
66
70
|
],
|
@@ -131,18 +135,294 @@ describe('login-user', () => {
|
|
131
135
|
],
|
132
136
|
};
|
133
137
|
|
138
|
+
let ezcft = {
|
139
|
+
groupCode: 'EZCFT',
|
140
|
+
groupDescription: 'EZCASH FINANCE TEAM',
|
141
|
+
status: 'Active',
|
142
|
+
personInCharge: null,
|
143
|
+
fullPath: null,
|
144
|
+
parentGroupCode: 'EZCCS',
|
145
|
+
groupLevel: 2,
|
146
|
+
groupType: null,
|
147
|
+
allowInheritFromParentYN: 'Y',
|
148
|
+
createdById: '61',
|
149
|
+
createdAt: new Date(),
|
150
|
+
updatedById: '61',
|
151
|
+
updatedAt: new Date(),
|
152
|
+
departmentId: 110,
|
153
|
+
groupSystemPrivileges: [],
|
154
|
+
groupRolePrivileges: [
|
155
|
+
{
|
156
|
+
groupCode: 'EZCFT',
|
157
|
+
roleId: 'clcogtmco00013unyc4ngcnza',
|
158
|
+
privilegeId: 'clcogtntx00023unyg98a0ah0',
|
159
|
+
createdById: 74,
|
160
|
+
createdAt: new Date(),
|
161
|
+
systemId: 175,
|
162
|
+
systemPrivilege: {
|
163
|
+
privilegeId: 'clcogtntx00023unyg98a0ah0',
|
164
|
+
systemId: 175,
|
165
|
+
code: 'Terminate',
|
166
|
+
module: null,
|
167
|
+
description: 'Allows the user to terminate a loan.',
|
168
|
+
createdAt: new Date(),
|
169
|
+
updatedAt: new Date(),
|
170
|
+
},
|
171
|
+
},
|
172
|
+
{
|
173
|
+
groupCode: 'EZCFT',
|
174
|
+
roleId: 'clcogtmco00013unyc4ngcnza',
|
175
|
+
privilegeId: 'clcogtnys00043wp21ejm068j',
|
176
|
+
createdById: 74,
|
177
|
+
createdAt: new Date(),
|
178
|
+
systemId: 175,
|
179
|
+
systemPrivilege: {
|
180
|
+
privilegeId: 'clcogtnys00043wp21ejm068j',
|
181
|
+
systemId: 175,
|
182
|
+
code: 'Download - Agreement',
|
183
|
+
module: null,
|
184
|
+
description: 'Allows the user to download the agreement.',
|
185
|
+
createdAt: new Date(),
|
186
|
+
updatedAt: new Date(),
|
187
|
+
},
|
188
|
+
},
|
189
|
+
{
|
190
|
+
groupCode: 'EZCFT',
|
191
|
+
roleId: 'clcogtmco00013unyc4ngcnza',
|
192
|
+
privilegeId: 'clcogtoa100063wp2djq10roz',
|
193
|
+
createdById: 74,
|
194
|
+
createdAt: new Date(),
|
195
|
+
systemId: 175,
|
196
|
+
systemPrivilege: {
|
197
|
+
privilegeId: 'clcogtoa100063wp2djq10roz',
|
198
|
+
systemId: 175,
|
199
|
+
code: 'Disbursement - Confirmation',
|
200
|
+
module: null,
|
201
|
+
description:
|
202
|
+
'Allows the user to confirm the disbursement of the loan.',
|
203
|
+
createdAt: new Date(),
|
204
|
+
updatedAt: new Date(),
|
205
|
+
},
|
206
|
+
},
|
207
|
+
{
|
208
|
+
groupCode: 'EZCFT',
|
209
|
+
roleId: 'clcogtmco00013unyc4ngcnza',
|
210
|
+
privilegeId: 'clcogtob000053uny52atenxa',
|
211
|
+
createdById: 74,
|
212
|
+
createdAt: new Date(),
|
213
|
+
systemId: 175,
|
214
|
+
systemPrivilege: {
|
215
|
+
privilegeId: 'clcogtob000053uny52atenxa',
|
216
|
+
systemId: 175,
|
217
|
+
code: 'Invoice Payment Received',
|
218
|
+
module: null,
|
219
|
+
description:
|
220
|
+
'Allows the user to confirm payment receipt of an invoice.',
|
221
|
+
createdAt: new Date(),
|
222
|
+
updatedAt: new Date(),
|
223
|
+
},
|
224
|
+
},
|
225
|
+
],
|
226
|
+
};
|
227
|
+
|
228
|
+
const ezccs = {
|
229
|
+
groupCode: 'EZCCS',
|
230
|
+
groupDescription: 'EZCASH COMPANY SIGNER',
|
231
|
+
status: 'Active',
|
232
|
+
personInCharge: null,
|
233
|
+
fullPath: null,
|
234
|
+
parentGroupCode: 'EZCAT',
|
235
|
+
groupLevel: 1,
|
236
|
+
groupType: null,
|
237
|
+
allowInheritFromParentYN: 'Y',
|
238
|
+
createdById: '61',
|
239
|
+
createdAt: new Date(),
|
240
|
+
updatedById: '61',
|
241
|
+
updatedAt: new Date(),
|
242
|
+
departmentId: 110,
|
243
|
+
groupSystemPrivileges: [],
|
244
|
+
groupRolePrivileges: [
|
245
|
+
{
|
246
|
+
groupCode: 'EZCCS',
|
247
|
+
roleId: 'cl34552or00002vlubgs11tc9',
|
248
|
+
privilegeId: 'cldu3gd7t000g3spe55jmax51',
|
249
|
+
createdById: 700,
|
250
|
+
createdAt: new Date(),
|
251
|
+
systemId: 42,
|
252
|
+
systemPrivilege: {
|
253
|
+
privilegeId: 'cldu3gd7t000g3spe55jmax51',
|
254
|
+
systemId: 42,
|
255
|
+
code: 'View Customer',
|
256
|
+
module: null,
|
257
|
+
description: 'Allow to view customer details',
|
258
|
+
createdAt: new Date(),
|
259
|
+
updatedAt: new Date(),
|
260
|
+
},
|
261
|
+
},
|
262
|
+
{
|
263
|
+
groupCode: 'EZCCS',
|
264
|
+
roleId: 'clcogtm8000003unybenw69nl',
|
265
|
+
privilegeId: 'clcogtnsn00023wp21z5n28az',
|
266
|
+
createdById: 700,
|
267
|
+
createdAt: new Date(),
|
268
|
+
systemId: 175,
|
269
|
+
systemPrivilege: {
|
270
|
+
privilegeId: 'clcogtnsn00023wp21z5n28az',
|
271
|
+
systemId: 175,
|
272
|
+
code: 'Signer - Company',
|
273
|
+
module: null,
|
274
|
+
description:
|
275
|
+
'Allows the user to sign loan agreements on behalf of the company.',
|
276
|
+
createdAt: new Date(),
|
277
|
+
updatedAt: new Date(),
|
278
|
+
},
|
279
|
+
},
|
280
|
+
{
|
281
|
+
groupCode: 'EZCCS',
|
282
|
+
roleId: 'clcogtm8000003unybenw69nl',
|
283
|
+
privilegeId: 'clcogtnys00043wp21ejm068j',
|
284
|
+
createdById: 700,
|
285
|
+
createdAt: new Date(),
|
286
|
+
systemId: 175,
|
287
|
+
systemPrivilege: {
|
288
|
+
privilegeId: 'clcogtnys00043wp21ejm068j',
|
289
|
+
systemId: 175,
|
290
|
+
code: 'Download - Agreement',
|
291
|
+
module: null,
|
292
|
+
description: 'Allows the user to download the agreement.',
|
293
|
+
createdAt: new Date(),
|
294
|
+
updatedAt: new Date(),
|
295
|
+
},
|
296
|
+
},
|
297
|
+
{
|
298
|
+
groupCode: 'EZCCS',
|
299
|
+
roleId: 'clcogtm8000003unybenw69nl',
|
300
|
+
privilegeId: 'clcogtqb400074dn47ld564nt',
|
301
|
+
createdById: 700,
|
302
|
+
createdAt: new Date(),
|
303
|
+
systemId: 175,
|
304
|
+
systemPrivilege: {
|
305
|
+
privilegeId: 'clds7oql500003spe3hubafn6',
|
306
|
+
systemId: 175,
|
307
|
+
code: 'Loan - Retrieve List',
|
308
|
+
module: null,
|
309
|
+
description:
|
310
|
+
'Allows the user to retrieve the loan listing/search for all loans within the system.',
|
311
|
+
createdAt: new Date(),
|
312
|
+
updatedAt: new Date(),
|
313
|
+
},
|
314
|
+
},
|
315
|
+
],
|
316
|
+
};
|
317
|
+
|
318
|
+
const ezcat = {
|
319
|
+
groupCode: 'EZCAT',
|
320
|
+
groupDescription: 'EZC ATTESTATOR',
|
321
|
+
status: 'Active',
|
322
|
+
personInCharge: null,
|
323
|
+
fullPath: null,
|
324
|
+
parentGroupCode: null,
|
325
|
+
groupLevel: 0,
|
326
|
+
groupType: null,
|
327
|
+
allowInheritFromParentYN: 'Y',
|
328
|
+
createdById: '61',
|
329
|
+
createdAt: new Date(),
|
330
|
+
updatedById: '61',
|
331
|
+
updatedAt: new Date(),
|
332
|
+
departmentId: 110,
|
333
|
+
groupSystemPrivileges: [],
|
334
|
+
groupRolePrivileges: [
|
335
|
+
{
|
336
|
+
groupCode: 'EZCAT',
|
337
|
+
roleId: 'cl34552or00002vlubgs11tc9',
|
338
|
+
privilegeId: 'cldu3gd7t000g3spe55jmax51',
|
339
|
+
createdById: 700,
|
340
|
+
createdAt: new Date(),
|
341
|
+
systemId: 42,
|
342
|
+
systemPrivilege: {
|
343
|
+
privilegeId: 'cldu3gd7t000g3spe55jmax51',
|
344
|
+
systemId: 42,
|
345
|
+
code: 'View Customer',
|
346
|
+
module: null,
|
347
|
+
description: 'Allow to view customer details',
|
348
|
+
createdAt: new Date(),
|
349
|
+
updatedAt: new Date(),
|
350
|
+
},
|
351
|
+
},
|
352
|
+
{
|
353
|
+
groupCode: 'EZCAT',
|
354
|
+
roleId: 'clcogtmyx00014dn4798pel3n',
|
355
|
+
privilegeId: 'clcogtnuf00033wp27vwb1vwl',
|
356
|
+
createdById: 74,
|
357
|
+
createdAt: new Date(),
|
358
|
+
systemId: 175,
|
359
|
+
systemPrivilege: {
|
360
|
+
privilegeId: 'clcogtnuf00033wp27vwb1vwl',
|
361
|
+
systemId: 175,
|
362
|
+
code: 'Signing Session - Schedule',
|
363
|
+
module: null,
|
364
|
+
description:
|
365
|
+
'Allows the user to schedule or reschedule the signing session.',
|
366
|
+
createdAt: new Date(),
|
367
|
+
updatedAt: new Date(),
|
368
|
+
},
|
369
|
+
},
|
370
|
+
{
|
371
|
+
groupCode: 'EZCAT',
|
372
|
+
roleId: 'clcogtmyx00014dn4798pel3n',
|
373
|
+
privilegeId: 'clcogto8t00043unyd60c8j6r',
|
374
|
+
createdById: 74,
|
375
|
+
createdAt: new Date(),
|
376
|
+
systemId: 175,
|
377
|
+
systemPrivilege: {
|
378
|
+
privilegeId: 'clcogto8t00043unyd60c8j6r',
|
379
|
+
systemId: 175,
|
380
|
+
code: 'Signing Session - No Show',
|
381
|
+
module: null,
|
382
|
+
description:
|
383
|
+
'Allows the user to mark the signing session as "no show".',
|
384
|
+
createdAt: new Date(),
|
385
|
+
updatedAt: new Date(),
|
386
|
+
},
|
387
|
+
},
|
388
|
+
{
|
389
|
+
groupCode: 'EZCAT',
|
390
|
+
roleId: 'clcogtmyx00014dn4798pel3n',
|
391
|
+
privilegeId: 'clcogtobc00073wp21lanh2qw',
|
392
|
+
createdById: 74,
|
393
|
+
createdAt: new Date(),
|
394
|
+
systemId: 175,
|
395
|
+
systemPrivilege: {
|
396
|
+
privilegeId: 'clcogtobc00073wp21lanh2qw',
|
397
|
+
systemId: 175,
|
398
|
+
code: 'Setup Session',
|
399
|
+
module: null,
|
400
|
+
description:
|
401
|
+
'Allows the users to set up the predefined slots for the live attestation sessions.',
|
402
|
+
createdAt: new Date(),
|
403
|
+
updatedAt: new Date(),
|
404
|
+
},
|
405
|
+
},
|
406
|
+
],
|
407
|
+
};
|
408
|
+
|
409
|
+
let userUserGroups = [
|
410
|
+
{
|
411
|
+
userId: 755,
|
412
|
+
groupCode: 'EZCFT',
|
413
|
+
systemId: 175,
|
414
|
+
createdAt: new Date(),
|
415
|
+
updatedAt: new Date(),
|
416
|
+
userGroup: ezcft,
|
417
|
+
},
|
418
|
+
];
|
419
|
+
|
134
420
|
jest.mock('crypto', () => {
|
135
421
|
return {
|
136
422
|
randomUUID: jest.fn().mockReturnValue('ckymxuh8t000137t011w89zgk'),
|
137
423
|
};
|
138
424
|
});
|
139
425
|
|
140
|
-
jest
|
141
|
-
.spyOn(UserRepository.prototype, 'findOne')
|
142
|
-
.mockImplementation(async () => {
|
143
|
-
return user;
|
144
|
-
});
|
145
|
-
|
146
426
|
jest
|
147
427
|
.spyOn(PasswordHashService.prototype, 'verify')
|
148
428
|
.mockImplementation(async (password) => {
|
@@ -154,54 +434,80 @@ describe('login-user', () => {
|
|
154
434
|
});
|
155
435
|
|
156
436
|
jest
|
157
|
-
.spyOn(SystemRepository
|
437
|
+
.spyOn(SystemRepository.prototype, 'findOne')
|
158
438
|
.mockImplementation(async () => {
|
159
439
|
return system;
|
160
440
|
});
|
161
441
|
|
162
|
-
jest
|
163
|
-
.spyOn(MailService.prototype, 'sendNewLoginAlertEmail')
|
164
|
-
.mockImplementation(async () => {});
|
442
|
+
jest.spyOn(Mailer.prototype, 'sendMail').mockImplementation(async () => {});
|
165
443
|
|
166
|
-
jest
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
});
|
444
|
+
const getUserGroupFromDBMock = jest.spyOn(
|
445
|
+
LoginUser.prototype as any,
|
446
|
+
'getUserGroupFromDB',
|
447
|
+
);
|
171
448
|
|
172
|
-
jest
|
173
|
-
.
|
174
|
-
|
175
|
-
|
176
|
-
});
|
449
|
+
const getUserUserGroupFromDBMock = jest.spyOn(
|
450
|
+
LoginUser.prototype as any,
|
451
|
+
'getUserUserGroupFromDB',
|
452
|
+
);
|
177
453
|
|
178
|
-
jest
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
454
|
+
const userMock = jest.spyOn(UserRepository.prototype, 'findOne');
|
455
|
+
|
456
|
+
const retriveUserSessionMock = jest.spyOn(
|
457
|
+
SessionService.prototype,
|
458
|
+
'retrieveUserSession',
|
459
|
+
);
|
460
|
+
|
461
|
+
userMock.mockImplementation(async () => {
|
462
|
+
return user;
|
463
|
+
});
|
464
|
+
|
465
|
+
getUserGroupFromDBMock.mockImplementation(async (groupCode) => {
|
466
|
+
if (groupCode === 'EZCFT') {
|
467
|
+
return ezcft;
|
468
|
+
} else if (groupCode === 'EZCCS') {
|
469
|
+
return ezccs;
|
470
|
+
} else if (groupCode === 'EZCAT') {
|
471
|
+
return ezcat;
|
472
|
+
}
|
188
473
|
});
|
189
474
|
|
190
|
-
|
191
|
-
|
192
|
-
const result = await loginUser.login(
|
193
|
-
'EZC',
|
194
|
-
'ezcash+florence@tomei.com.my',
|
195
|
-
'Abcd@1234',
|
196
|
-
'1.1.1.1',
|
197
|
-
);
|
198
|
-
expect(result).toEqual('ckymxuh8t000137t011w89zgk');
|
475
|
+
getUserUserGroupFromDBMock.mockImplementation(async () => {
|
476
|
+
return userUserGroups;
|
199
477
|
});
|
200
478
|
|
201
|
-
|
479
|
+
describe('login', () => {
|
202
480
|
jest
|
203
|
-
.spyOn(
|
204
|
-
.
|
481
|
+
.spyOn(SystemAccessRepository.prototype, 'findOne')
|
482
|
+
.mockImplementation(async () => {
|
483
|
+
return systemAccess;
|
484
|
+
});
|
485
|
+
|
486
|
+
jest
|
487
|
+
.spyOn(LoginHistoryRepository.prototype, 'findAll')
|
488
|
+
.mockImplementation(async () => {
|
489
|
+
const data = [];
|
490
|
+
return data;
|
491
|
+
});
|
492
|
+
|
493
|
+
it('should return login-user service when instansiated', async () => {
|
494
|
+
const loginUser = await LoginUser.init();
|
495
|
+
expect(loginUser).toBeDefined();
|
496
|
+
});
|
497
|
+
|
498
|
+
it('should able to do login process when no session is already available', async () => {
|
499
|
+
const loginUser = await LoginUser.init('755');
|
500
|
+
const result = await loginUser.login(
|
501
|
+
'EZC',
|
502
|
+
'ezcash+florence@tomei.com.my',
|
503
|
+
'Abcd@1234',
|
504
|
+
'1.1.1.1',
|
505
|
+
);
|
506
|
+
expect(result).toEqual('ckymxuh8t000137t011w89zgk');
|
507
|
+
});
|
508
|
+
|
509
|
+
it('should able to do login process when session is already available', async () => {
|
510
|
+
retriveUserSessionMock.mockImplementationOnce(async (userId: string) => {
|
205
511
|
if (userId === '755') {
|
206
512
|
return session;
|
207
513
|
} else {
|
@@ -211,13 +517,178 @@ describe('login-user', () => {
|
|
211
517
|
}
|
212
518
|
});
|
213
519
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
520
|
+
const loginUser = await LoginUser.init('755');
|
521
|
+
const result = await loginUser.login(
|
522
|
+
'EZC',
|
523
|
+
'ezcash+florence@tomei.com.my',
|
524
|
+
'Abcd@1234',
|
525
|
+
'1.1.1.1',
|
526
|
+
);
|
527
|
+
expect(result).toEqual('ckymxuh8t000137t011w89zgk');
|
528
|
+
});
|
222
529
|
});
|
530
|
+
|
531
|
+
describe('getPrivileges', () => {
|
532
|
+
it('should be able to login when user only have one user group with level 1 or higher', async () => {
|
533
|
+
const loginUser = await LoginUser.init('755');
|
534
|
+
const result = await loginUser['getPrivileges']('EZC');
|
535
|
+
expect(getUserGroupFromDBMock).toBeCalledTimes(2);
|
536
|
+
expect(result).toEqual([
|
537
|
+
'View Customer',
|
538
|
+
'Signer - Company',
|
539
|
+
'Download - Agreement',
|
540
|
+
'Loan - Retrieve List',
|
541
|
+
'Signing Session - Schedule',
|
542
|
+
'Signing Session - No Show',
|
543
|
+
'Setup Session',
|
544
|
+
'Terminate',
|
545
|
+
'Disbursement - Confirmation',
|
546
|
+
'Invoice Payment Received',
|
547
|
+
'Terminate Data',
|
548
|
+
]);
|
549
|
+
});
|
550
|
+
|
551
|
+
it('should be able to login when user only have multiple user user group', async () => {
|
552
|
+
const tempUserUserGroups = userUserGroups;
|
553
|
+
userUserGroups.push(userUserGroups[0]);
|
554
|
+
|
555
|
+
const loginUser = await LoginUser.init('755');
|
556
|
+
const result = await loginUser['getPrivileges']('EZC');
|
557
|
+
expect(getUserUserGroupFromDBMock).toBeCalledTimes(1);
|
558
|
+
expect(getUserGroupFromDBMock).toBeCalledTimes(4);
|
559
|
+
expect(result).toEqual([
|
560
|
+
'View Customer',
|
561
|
+
'Signer - Company',
|
562
|
+
'Download - Agreement',
|
563
|
+
'Loan - Retrieve List',
|
564
|
+
'Signing Session - Schedule',
|
565
|
+
'Signing Session - No Show',
|
566
|
+
'Setup Session',
|
567
|
+
'Terminate',
|
568
|
+
'Disbursement - Confirmation',
|
569
|
+
'Invoice Payment Received',
|
570
|
+
'Terminate Data',
|
571
|
+
]);
|
572
|
+
|
573
|
+
userUserGroups = tempUserUserGroups;
|
574
|
+
});
|
575
|
+
|
576
|
+
it('should be able to login when user only have user privilege', async () => {
|
577
|
+
const tempUserUserGroup = userUserGroups;
|
578
|
+
userUserGroups = [];
|
579
|
+
|
580
|
+
const loginUser = await LoginUser.init('755');
|
581
|
+
const result = await loginUser['getPrivileges']('EZC');
|
582
|
+
expect(getUserGroupFromDBMock).toBeCalledTimes(0);
|
583
|
+
expect(result).toEqual(['Terminate Data']);
|
584
|
+
|
585
|
+
userUserGroups = tempUserUserGroup;
|
586
|
+
});
|
587
|
+
|
588
|
+
it('should be able to login when user only have one user group with no parent', async () => {
|
589
|
+
const tempEzcft = ezcft;
|
590
|
+
ezcft.groupLevel = 0;
|
591
|
+
const tempUser = user;
|
592
|
+
user.userSystemPrivileges = [];
|
593
|
+
|
594
|
+
const loginUser = await LoginUser.init('755');
|
595
|
+
const result = await loginUser['getPrivileges']('EZC');
|
596
|
+
expect(getUserGroupFromDBMock).toBeCalledTimes(0);
|
597
|
+
expect(result).toEqual([
|
598
|
+
'Terminate',
|
599
|
+
'Download - Agreement',
|
600
|
+
'Disbursement - Confirmation',
|
601
|
+
'Invoice Payment Received',
|
602
|
+
]);
|
603
|
+
|
604
|
+
ezcft = tempEzcft;
|
605
|
+
user = tempUser;
|
606
|
+
});
|
607
|
+
|
608
|
+
it('should be able to login when user only have one user group that cannot inherit privilege', async () => {
|
609
|
+
const tempEzcft = ezcft;
|
610
|
+
ezcft.groupLevel = 1;
|
611
|
+
ezcft.allowInheritFromParentYN = 'N';
|
612
|
+
const tempUser = user;
|
613
|
+
user.userSystemPrivileges = [];
|
614
|
+
|
615
|
+
const loginUser = await LoginUser.init('755');
|
616
|
+
const result = await loginUser['getPrivileges']('EZC');
|
617
|
+
expect(getUserGroupFromDBMock).toBeCalledTimes(0);
|
618
|
+
expect(result).toEqual([
|
619
|
+
'Terminate',
|
620
|
+
'Download - Agreement',
|
621
|
+
'Disbursement - Confirmation',
|
622
|
+
'Invoice Payment Received',
|
623
|
+
]);
|
624
|
+
|
625
|
+
ezcft = tempEzcft;
|
626
|
+
user = tempUser;
|
627
|
+
});
|
628
|
+
|
629
|
+
it('should be able to login when user dont have user privilage or user usergroup', async () => {
|
630
|
+
const tempUser = user;
|
631
|
+
user.userSystemPrivileges = [];
|
632
|
+
const tempUserUserGroup = userUserGroups;
|
633
|
+
userUserGroups = [];
|
634
|
+
|
635
|
+
const loginUser = await LoginUser.init('755');
|
636
|
+
const result = await loginUser['getPrivileges']('EZC');
|
637
|
+
expect(getUserGroupFromDBMock).toBeCalledTimes(0);
|
638
|
+
expect(result).toEqual([]);
|
639
|
+
|
640
|
+
userUserGroups = tempUserUserGroup;
|
641
|
+
user = tempUser;
|
642
|
+
});
|
643
|
+
});
|
644
|
+
|
645
|
+
describe('checkPrivileges', () => {
|
646
|
+
let isCorrect = true;
|
647
|
+
retriveUserSessionMock.mockImplementation(async (userId: string) => {
|
648
|
+
if (userId && userId == '755' && isCorrect === true) {
|
649
|
+
return session;
|
650
|
+
} else {
|
651
|
+
return {
|
652
|
+
systemLogins: [],
|
653
|
+
};
|
654
|
+
}
|
655
|
+
});
|
656
|
+
|
657
|
+
afterEach(() => {
|
658
|
+
isCorrect = true;
|
659
|
+
});
|
660
|
+
|
661
|
+
afterAll(() => {
|
662
|
+
jest.restoreAllMocks();
|
663
|
+
});
|
664
|
+
|
665
|
+
it('should return false if user session not found', async () => {
|
666
|
+
isCorrect = false;
|
667
|
+
const loginUser = await LoginUser.init('755');
|
668
|
+
const result = await loginUser.checkPrivileges('EZC', 'Terminate');
|
669
|
+
expect(result).toEqual(false);
|
670
|
+
});
|
671
|
+
|
672
|
+
it('should return false if system login not found', async () => {
|
673
|
+
isCorrect = false;
|
674
|
+
const loginUser = await LoginUser.init('755');
|
675
|
+
const result = await loginUser.checkPrivileges('EZC', 'Terminate');
|
676
|
+
expect(result).toEqual(false);
|
677
|
+
});
|
678
|
+
|
679
|
+
it('should return false if privilege not found', async () => {
|
680
|
+
isCorrect = false;
|
681
|
+
const loginUser = await LoginUser.init('755');
|
682
|
+
const result = await loginUser.checkPrivileges('EZC', 'Not Terminate');
|
683
|
+
expect(result).toEqual(false);
|
684
|
+
});
|
685
|
+
|
686
|
+
it('should return true if privilege found', async () => {
|
687
|
+
const loginUser = await LoginUser.init('755');
|
688
|
+
const result = await loginUser.checkPrivileges('EZC', 'Terminate');
|
689
|
+
expect(result).toEqual(true);
|
690
|
+
});
|
691
|
+
});
|
692
|
+
|
693
|
+
|
223
694
|
});
|