@tomei/sso 0.16.3 → 0.16.5
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/.commitlintrc.json +22 -22
- package/.eslintrc +16 -16
- package/.eslintrc.js +35 -35
- package/.husky/commit-msg +15 -15
- package/.husky/pre-commit +7 -7
- package/.prettierrc +4 -4
- package/Jenkinsfile +57 -57
- package/README.md +23 -23
- package/__tests__/unit/components/login-user/login-user.spec.ts +742 -742
- package/__tests__/unit/components/password-hash/password-hash.service.spec.ts +31 -31
- package/__tests__/unit/redis-client/redis.service.spec.ts +23 -23
- package/__tests__/unit/session/session.service.spec.ts +47 -47
- package/__tests__/unit/system-privilege/system-privilage.spec.ts +91 -91
- package/create-sso-user.sql +39 -39
- package/dist/src/components/index.d.ts +3 -0
- package/dist/src/components/index.js +3 -0
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/components/sso-group/group.d.ts +26 -0
- package/dist/src/components/sso-group/group.js +66 -0
- package/dist/src/components/sso-group/group.js.map +1 -0
- package/dist/src/components/sso-group/group.repository.d.ts +5 -0
- package/dist/src/components/sso-group/group.repository.js +12 -0
- package/dist/src/components/sso-group/group.repository.js.map +1 -0
- package/dist/src/components/sso-group/index.d.ts +2 -0
- package/dist/src/components/sso-group/index.js +19 -0
- package/dist/src/components/sso-group/index.js.map +1 -0
- package/dist/src/components/sso-group-reporting-user/group-reporting-user.d.ts +23 -0
- package/dist/src/components/sso-group-reporting-user/group-reporting-user.js +64 -0
- package/dist/src/components/sso-group-reporting-user/group-reporting-user.js.map +1 -0
- package/dist/src/components/sso-group-reporting-user/group-reporting-user.repository.d.ts +5 -0
- package/dist/src/components/sso-group-reporting-user/group-reporting-user.repository.js +12 -0
- package/dist/src/components/sso-group-reporting-user/group-reporting-user.repository.js.map +1 -0
- package/dist/src/components/sso-group-reporting-user/index.d.ts +2 -0
- package/dist/src/components/sso-group-reporting-user/index.js +19 -0
- package/dist/src/components/sso-group-reporting-user/index.js.map +1 -0
- package/dist/src/components/sso-system/index.d.ts +2 -0
- package/dist/src/components/sso-system/index.js +19 -0
- package/dist/src/components/sso-system/index.js.map +1 -0
- package/dist/src/components/sso-system/system.d.ts +28 -0
- package/dist/src/components/sso-system/system.js +68 -0
- package/dist/src/components/sso-system/system.js.map +1 -0
- package/dist/src/components/sso-system/system.repository.d.ts +5 -0
- package/dist/src/components/sso-system/system.repository.js +12 -0
- package/dist/src/components/sso-system/system.repository.js.map +1 -0
- package/dist/src/components/staff/staff.js +1 -1
- package/dist/src/components/staff/staff.js.map +1 -1
- package/dist/src/enum/group-type.enum.d.ts +8 -0
- package/dist/src/enum/group-type.enum.js +13 -0
- package/dist/src/enum/group-type.enum.js.map +1 -0
- package/dist/src/enum/index.d.ts +1 -0
- package/dist/src/enum/index.js +1 -0
- package/dist/src/enum/index.js.map +1 -1
- package/dist/src/interfaces/group-reporting-user.interface.d.ts +11 -0
- package/dist/src/interfaces/group-reporting-user.interface.js +3 -0
- package/dist/src/interfaces/group-reporting-user.interface.js.map +1 -0
- package/dist/src/interfaces/group.interface.d.ts +14 -0
- package/dist/src/interfaces/group.interface.js +3 -0
- package/dist/src/interfaces/group.interface.js.map +1 -0
- package/dist/src/interfaces/index.d.ts +3 -0
- package/dist/src/interfaces/index.js +3 -0
- package/dist/src/interfaces/index.js.map +1 -1
- package/dist/src/interfaces/system.interface.d.ts +15 -0
- package/dist/src/interfaces/system.interface.js +3 -0
- package/dist/src/interfaces/system.interface.js.map +1 -0
- package/dist/src/models/sso-group-reporting-user.entity.d.ts +17 -0
- package/dist/src/models/sso-group-reporting-user.entity.js +105 -0
- package/dist/src/models/sso-group-reporting-user.entity.js.map +1 -0
- package/dist/src/models/sso-group.entity.d.ts +18 -0
- package/dist/src/models/sso-group.entity.js +111 -0
- package/dist/src/models/sso-group.entity.js.map +1 -0
- package/dist/src/models/sso-system.entity.d.ts +19 -0
- package/dist/src/models/sso-system.entity.js +122 -0
- package/dist/src/models/sso-system.entity.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/jest.config.js +13 -13
- package/migrations/20240314080603-create-user-table.js +108 -108
- package/migrations/20240314080604-create-user-user-group-table.js +55 -55
- package/migrations/20240314080605-create-login-history-table.js +49 -49
- package/migrations/20240527064925-create-system-table.js +78 -0
- package/migrations/20240527065342-create-group-table.js +84 -0
- package/migrations/20240527065633-create-group-reporting-user-table.js +72 -0
- package/package.json +80 -80
- package/sampledotenv +7 -7
- package/src/components/index.ts +5 -0
- package/src/components/sso-group/group.repository.ts +11 -0
- package/src/components/sso-group/group.ts +77 -0
- package/src/components/sso-group/index.ts +3 -0
- package/src/components/sso-group-reporting-user/group-reporting-user.repository.ts +11 -0
- package/src/components/sso-group-reporting-user/group-reporting-user.ts +79 -0
- package/src/components/sso-group-reporting-user/index.ts +3 -0
- package/src/components/sso-system/index.ts +3 -0
- package/src/components/sso-system/system.repository.ts +11 -0
- package/src/components/sso-system/system.ts +81 -0
- package/src/components/staff/staff.ts +3 -1
- package/src/enum/group-type.enum.ts +8 -0
- package/src/enum/index.ts +1 -0
- package/src/interfaces/group-reporting-user.interface.ts +13 -0
- package/src/interfaces/group.interface.ts +15 -0
- package/src/interfaces/index.ts +3 -0
- package/src/interfaces/system.interface.ts +15 -0
- package/src/models/sso-group-reporting-user.entity.ts +86 -0
- package/src/models/sso-group.entity.ts +91 -0
- package/src/models/sso-system.entity.ts +101 -0
- package/tsconfig.build.json +5 -5
- package/tsconfig.json +23 -23
@@ -1,742 +1,742 @@
|
|
1
|
-
import { IUserSession } from '../../../../src/interfaces/user-session.interface';
|
2
|
-
import {
|
3
|
-
LoginHistoryRepository,
|
4
|
-
SessionService,
|
5
|
-
SystemAccessRepository,
|
6
|
-
SystemRepository,
|
7
|
-
} from '../../../../src';
|
8
|
-
import { LoginUser } from '../../../../src/components/login-user/login-user';
|
9
|
-
import { UserRepository } from '../../../../src/components/login-user/user.repository';
|
10
|
-
import { PasswordHashService } from '../../../../src/components/password-hash/password-hash.service';
|
11
|
-
import { SMTPMailer } from '@tomei/mailer';
|
12
|
-
describe('login-user', () => {
|
13
|
-
let isSessionExist = true;
|
14
|
-
let user = {
|
15
|
-
id: 755,
|
16
|
-
Email: 'ezcash+florence@tomei.com.my',
|
17
|
-
Password:
|
18
|
-
'$argon2id$v=19$m=4096,t=3,p=1$571ilUAi9n5g393m/NqKbQ$2bMnLtMCIVTjHWHGEDxI2wo+A3mrL3N5rTxDJ6ydPi8',
|
19
|
-
Status: null,
|
20
|
-
DefaultPasswordChanged: false,
|
21
|
-
FirstLoginAt: new Date('2023-01-10T07:57:10.000Z'),
|
22
|
-
CreatedAt: new Date('2023-01-10T07:57:10.000Z'),
|
23
|
-
UpdatedAt: new Date('2023-01-10T08:58:15.000Z'),
|
24
|
-
GroupCode: 'EZCFT',
|
25
|
-
Staff: [
|
26
|
-
{
|
27
|
-
id: 740,
|
28
|
-
StaffId: 'EZC003',
|
29
|
-
FullName: 'EZC Florence',
|
30
|
-
PreferredName: 'EZC Florence',
|
31
|
-
Email: 'ezcash+florence@tomei.com.my',
|
32
|
-
StaffTypeId: 1,
|
33
|
-
JobTitle: 'EZC Finance',
|
34
|
-
CarPlate: '',
|
35
|
-
Mobile: '60123456',
|
36
|
-
Floor: null,
|
37
|
-
Extension: null,
|
38
|
-
IsCharge: false,
|
39
|
-
Status: 'active',
|
40
|
-
UserId: 755,
|
41
|
-
BuildingId: 20,
|
42
|
-
DepartmentId: 110,
|
43
|
-
CompanyId: 70,
|
44
|
-
CreatedById: 74,
|
45
|
-
UpdatedById: 74,
|
46
|
-
CcreatedAt: new Date('2023-01-10T07:57:10.000Z'),
|
47
|
-
UpdatedAt: new Date('2023-01-10T07:57:10.000Z'),
|
48
|
-
Image: null,
|
49
|
-
IdNo: '123123123',
|
50
|
-
FullAddress: 'Lorem Address',
|
51
|
-
},
|
52
|
-
],
|
53
|
-
SystemPrivileges: [
|
54
|
-
{
|
55
|
-
PrivilegeId: 'ckymxuh8t000137t011w89zgk',
|
56
|
-
SystemId: 175,
|
57
|
-
Code: 'Terminate Data',
|
58
|
-
Module: null,
|
59
|
-
Description: 'Allows the user to terminate a loan.',
|
60
|
-
CreatedAt: new Date(),
|
61
|
-
UpdatedAt: new Date(),
|
62
|
-
},
|
63
|
-
],
|
64
|
-
};
|
65
|
-
|
66
|
-
const system = {
|
67
|
-
id: 175,
|
68
|
-
Code: 'EZC',
|
69
|
-
Name: 'EzCash',
|
70
|
-
Description: 'Tomei Money Lending System',
|
71
|
-
AccessUrl: 'https://app.ezcash.com.my:22443/staff/login',
|
72
|
-
GooglePlayUrl: '',
|
73
|
-
AppleStoreUrl: '',
|
74
|
-
ApiKey: 'VqS9ks2Lwvqd7HrVUMMIP2q7zaEH689HCPaEaFUQLmiRoZnt',
|
75
|
-
Logo: 'https://sso-api.tomei.com.my/upload/2023/01/10/FJ3DoHdRZKjf2bGkgA4E-BrowserIcon.png',
|
76
|
-
Status: 'active',
|
77
|
-
Visible: true,
|
78
|
-
CreatedAt: new Date('2023-01-09T00:45:57.000Z'),
|
79
|
-
UpdatedAt: new Date('2023-01-10T06:28:56.000Z'),
|
80
|
-
ApiSecret:
|
81
|
-
'$argon2id$v=19$m=4096,t=3,p=1$lqxfk/ujftswf2jSEu156g$j2IShE/BZUUoH/1jrvt3GGRSy0rA8HilJvK17e6vdFY',
|
82
|
-
UpdatedById: 61,
|
83
|
-
CreatedById: 100,
|
84
|
-
};
|
85
|
-
|
86
|
-
const systemAccess = {
|
87
|
-
UserId: 755,
|
88
|
-
SystemId: 175,
|
89
|
-
UpdatedAt: new Date('2023-01-09T00:45:57.000'),
|
90
|
-
};
|
91
|
-
|
92
|
-
const session: IUserSession = {
|
93
|
-
systemLogins: [
|
94
|
-
{
|
95
|
-
id: '175',
|
96
|
-
code: 'EZC',
|
97
|
-
sessionId: 'ckymxuh8t000137t011w89zgk',
|
98
|
-
privileges: [
|
99
|
-
'Terminate',
|
100
|
-
'Download - Agreement',
|
101
|
-
'Disbursement - Confirmation',
|
102
|
-
'Invoice Payment Received',
|
103
|
-
'Download - Disbursement Receipt',
|
104
|
-
'Download - Stamping Receipt',
|
105
|
-
'Installment Payment Received',
|
106
|
-
'View Transaction History',
|
107
|
-
'Menu - Loans',
|
108
|
-
'Loan - Full Settlement',
|
109
|
-
'View Billing',
|
110
|
-
'Loan - Retrieve List',
|
111
|
-
'Loan - View Details',
|
112
|
-
'Loan - Retrieve Outstanding',
|
113
|
-
'Loan - View Mandate Details',
|
114
|
-
'Loan Document - Retrieve List',
|
115
|
-
'Loan Document - View',
|
116
|
-
'Loan Document - Download',
|
117
|
-
'Application - View Details',
|
118
|
-
'Simple Loan Schedule - Get Overdue Schedules',
|
119
|
-
'Simple Loan Schedule - Get Schedule Payment Details',
|
120
|
-
'Retrieve Media List',
|
121
|
-
'Retrieve Customer List',
|
122
|
-
'View Loan Activity',
|
123
|
-
'Activate Installment',
|
124
|
-
'Manual Payment Receipt',
|
125
|
-
'Customer Documents - View',
|
126
|
-
],
|
127
|
-
},
|
128
|
-
],
|
129
|
-
};
|
130
|
-
|
131
|
-
let ezcft = {
|
132
|
-
GroupCode: 'EZCFT',
|
133
|
-
GroupDescription: 'EZCASH FINANCE TEAM',
|
134
|
-
Status: 'Active',
|
135
|
-
PersonInCharge: null,
|
136
|
-
FullPath: null,
|
137
|
-
ParentGroupCode: 'EZCCS',
|
138
|
-
GroupLevel: 2,
|
139
|
-
GroupType: null,
|
140
|
-
AllowInheritFromParentYN: 'Y',
|
141
|
-
CreatedById: '61',
|
142
|
-
CreatedAt: new Date(),
|
143
|
-
UpdatedById: '61',
|
144
|
-
UpdatedAt: new Date(),
|
145
|
-
DepartmentId: 110,
|
146
|
-
GroupSystemPrivileges: [],
|
147
|
-
GroupRolePrivileges: [
|
148
|
-
{
|
149
|
-
GroupCode: 'EZCFT',
|
150
|
-
RoleId: 'clcogtmco00013unyc4ngcnza',
|
151
|
-
PrivilegeId: 'clcogtntx00023unyg98a0ah0',
|
152
|
-
CreatedById: 74,
|
153
|
-
CreatedAt: new Date(),
|
154
|
-
SystemId: 175,
|
155
|
-
SystemPrivilege: {
|
156
|
-
PrivilegeId: 'clcogtntx00023unyg98a0ah0',
|
157
|
-
SystemId: 175,
|
158
|
-
Code: 'Terminate',
|
159
|
-
Module: null,
|
160
|
-
Description: 'Allows the user to terminate a loan.',
|
161
|
-
CreatedAt: new Date(),
|
162
|
-
UpdatedAt: new Date(),
|
163
|
-
},
|
164
|
-
},
|
165
|
-
{
|
166
|
-
GroupCode: 'EZCFT',
|
167
|
-
RoleId: 'clcogtmco00013unyc4ngcnza',
|
168
|
-
PrivilegeId: 'clcogtnys00043wp21ejm068j',
|
169
|
-
CreatedById: 74,
|
170
|
-
CreatedAt: new Date(),
|
171
|
-
SystemId: 175,
|
172
|
-
SystemPrivilege: {
|
173
|
-
PrivilegeId: 'clcogtnys00043wp21ejm068j',
|
174
|
-
SystemId: 175,
|
175
|
-
Code: 'Download - Agreement',
|
176
|
-
Module: null,
|
177
|
-
Description: 'Allows the user to download the agreement.',
|
178
|
-
CreatedAt: new Date(),
|
179
|
-
UpdatedAt: new Date(),
|
180
|
-
},
|
181
|
-
},
|
182
|
-
{
|
183
|
-
GroupCode: 'EZCFT',
|
184
|
-
RoleId: 'clcogtmco00013unyc4ngcnza',
|
185
|
-
PrivilegeId: 'clcogtoa100063wp2djq10roz',
|
186
|
-
CreatedById: 74,
|
187
|
-
CreatedAt: new Date(),
|
188
|
-
SystemId: 175,
|
189
|
-
SystemPrivilege: {
|
190
|
-
PrivilegeId: 'clcogtoa100063wp2djq10roz',
|
191
|
-
SystemId: 175,
|
192
|
-
Code: 'Disbursement - Confirmation',
|
193
|
-
Module: null,
|
194
|
-
Description:
|
195
|
-
'Allows the user to confirm the disbursement of the loan.',
|
196
|
-
CreatedAt: new Date(),
|
197
|
-
UpdatedAt: new Date(),
|
198
|
-
},
|
199
|
-
},
|
200
|
-
{
|
201
|
-
GroupCode: 'EZCFT',
|
202
|
-
RoleId: 'clcogtmco00013unyc4ngcnza',
|
203
|
-
PrivilegeId: 'clcogtob000053uny52atenxa',
|
204
|
-
CreatedById: 74,
|
205
|
-
CreatedAt: new Date(),
|
206
|
-
SystemId: 175,
|
207
|
-
SystemPrivilege: {
|
208
|
-
PrivilegeId: 'clcogtob000053uny52atenxa',
|
209
|
-
SystemId: 175,
|
210
|
-
Code: 'Invoice Payment Received',
|
211
|
-
Module: null,
|
212
|
-
Description:
|
213
|
-
'Allows the user to confirm payment receipt of an invoice.',
|
214
|
-
CreatedAt: new Date(),
|
215
|
-
UpdatedAt: new Date(),
|
216
|
-
},
|
217
|
-
},
|
218
|
-
],
|
219
|
-
};
|
220
|
-
|
221
|
-
const ezccs = {
|
222
|
-
GroupCode: 'EZCCS',
|
223
|
-
GroupDescription: 'EZCASH COMPANY SIGNER',
|
224
|
-
Status: 'Active',
|
225
|
-
PersonInCharge: null,
|
226
|
-
FullPath: null,
|
227
|
-
ParentGroupCode: 'EZCAT',
|
228
|
-
GroupLevel: 1,
|
229
|
-
GroupType: null,
|
230
|
-
AllowInheritFromParentYN: 'Y',
|
231
|
-
CreatedById: '61',
|
232
|
-
CreatedAt: new Date(),
|
233
|
-
UpdatedById: '61',
|
234
|
-
UpdatedAt: new Date(),
|
235
|
-
DepartmentId: 110,
|
236
|
-
GroupSystemPrivileges: [],
|
237
|
-
GroupRolePrivileges: [
|
238
|
-
{
|
239
|
-
GroupCode: 'EZCCS',
|
240
|
-
RoleId: 'cl34552or00002vlubgs11tc9',
|
241
|
-
PrivilegeId: 'cldu3gd7t000g3spe55jmax51',
|
242
|
-
CreatedById: 700,
|
243
|
-
CreatedAt: new Date(),
|
244
|
-
SystemId: 42,
|
245
|
-
SystemPrivilege: {
|
246
|
-
PrivilegeId: 'cldu3gd7t000g3spe55jmax51',
|
247
|
-
SystemId: 42,
|
248
|
-
Code: 'View Customer',
|
249
|
-
Module: null,
|
250
|
-
Description: 'Allow to view customer details',
|
251
|
-
CreatedAt: new Date(),
|
252
|
-
UpdatedAt: new Date(),
|
253
|
-
},
|
254
|
-
},
|
255
|
-
{
|
256
|
-
GroupCode: 'EZCCS',
|
257
|
-
RoleId: 'clcogtm8000003unybenw69nl',
|
258
|
-
PrivilegeId: 'clcogtnsn00023wp21z5n28az',
|
259
|
-
CreatedById: 700,
|
260
|
-
CreatedAt: new Date(),
|
261
|
-
SystemId: 175,
|
262
|
-
SystemPrivilege: {
|
263
|
-
PrivilegeId: 'clcogtnsn00023wp21z5n28az',
|
264
|
-
SystemId: 175,
|
265
|
-
Code: 'Signer - Company',
|
266
|
-
Module: null,
|
267
|
-
Description:
|
268
|
-
'Allows the user to sign loan agreements on behalf of the company.',
|
269
|
-
CreatedAt: new Date(),
|
270
|
-
UpdatedAt: new Date(),
|
271
|
-
},
|
272
|
-
},
|
273
|
-
{
|
274
|
-
GroupCode: 'EZCCS',
|
275
|
-
RoleId: 'clcogtm8000003unybenw69nl',
|
276
|
-
PrivilegeId: 'clcogtnys00043wp21ejm068j',
|
277
|
-
CreatedById: 700,
|
278
|
-
CreatedAt: new Date(),
|
279
|
-
SystemId: 175,
|
280
|
-
SystemPrivilege: {
|
281
|
-
PrivilegeId: 'clcogtnys00043wp21ejm068j',
|
282
|
-
SystemId: 175,
|
283
|
-
Code: 'Download - Agreement',
|
284
|
-
Module: null,
|
285
|
-
Description: 'Allows the user to download the agreement.',
|
286
|
-
CreatedAt: new Date(),
|
287
|
-
UpdatedAt: new Date(),
|
288
|
-
},
|
289
|
-
},
|
290
|
-
{
|
291
|
-
GroupCode: 'EZCCS',
|
292
|
-
RoleId: 'clcogtm8000003unybenw69nl',
|
293
|
-
PrivilegeId: 'clcogtqb400074dn47ld564nt',
|
294
|
-
CreatedById: 700,
|
295
|
-
CreatedAt: new Date(),
|
296
|
-
SystemId: 175,
|
297
|
-
SystemPrivilege: {
|
298
|
-
PrivilegeId: 'clds7oql500003spe3hubafn6',
|
299
|
-
SystemId: 175,
|
300
|
-
Code: 'Loan - Retrieve List',
|
301
|
-
Module: null,
|
302
|
-
Description:
|
303
|
-
'Allows the user to retrieve the loan listing/search for all loans within the system.',
|
304
|
-
CreatedAt: new Date(),
|
305
|
-
UpdatedAt: new Date(),
|
306
|
-
},
|
307
|
-
},
|
308
|
-
],
|
309
|
-
};
|
310
|
-
|
311
|
-
const ezcat = {
|
312
|
-
GroupCode: 'EZCAT',
|
313
|
-
GroupDescription: 'EZC ATTESTATOR',
|
314
|
-
Status: 'Active',
|
315
|
-
PersonInCharge: null,
|
316
|
-
FullPath: null,
|
317
|
-
ParentGroupCode: null,
|
318
|
-
GroupLevel: 0,
|
319
|
-
GroupType: null,
|
320
|
-
AllowInheritFromParentYN: 'Y',
|
321
|
-
CreatedById: '61',
|
322
|
-
CreatedAt: new Date(),
|
323
|
-
UpdatedById: '61',
|
324
|
-
UpdatedAt: new Date(),
|
325
|
-
DepartmentId: 110,
|
326
|
-
GroupSystemPrivileges: [],
|
327
|
-
GroupRolePrivileges: [
|
328
|
-
{
|
329
|
-
GroupCode: 'EZCAT',
|
330
|
-
RoleId: 'cl34552or00002vlubgs11tc9',
|
331
|
-
PrivilegeId: 'cldu3gd7t000g3spe55jmax51',
|
332
|
-
CreatedById: 700,
|
333
|
-
CreatedAt: new Date(),
|
334
|
-
SystemId: 42,
|
335
|
-
SystemPrivilege: {
|
336
|
-
PrivilegeId: 'cldu3gd7t000g3spe55jmax51',
|
337
|
-
SystemId: 42,
|
338
|
-
Code: 'View Customer',
|
339
|
-
Module: null,
|
340
|
-
Description: 'Allow to view customer details',
|
341
|
-
CreatedAt: new Date(),
|
342
|
-
UpdatedAt: new Date(),
|
343
|
-
},
|
344
|
-
},
|
345
|
-
{
|
346
|
-
GroupCode: 'EZCAT',
|
347
|
-
RoleId: 'clcogtmyx00014dn4798pel3n',
|
348
|
-
PrivilegeId: 'clcogtnuf00033wp27vwb1vwl',
|
349
|
-
CreatedById: 74,
|
350
|
-
CreatedAt: new Date(),
|
351
|
-
SystemId: 175,
|
352
|
-
SystemPrivilege: {
|
353
|
-
PrivilegeId: 'clcogtnuf00033wp27vwb1vwl',
|
354
|
-
SystemId: 175,
|
355
|
-
Code: 'Signing Session - Schedule',
|
356
|
-
Module: null,
|
357
|
-
Description:
|
358
|
-
'Allows the user to schedule or reschedule the signing session.',
|
359
|
-
CreatedAt: new Date(),
|
360
|
-
UpdatedAt: new Date(),
|
361
|
-
},
|
362
|
-
},
|
363
|
-
{
|
364
|
-
GroupCode: 'EZCAT',
|
365
|
-
RoleId: 'clcogtmyx00014dn4798pel3n',
|
366
|
-
PrivilegeId: 'clcogto8t00043unyd60c8j6r',
|
367
|
-
CreatedById: 74,
|
368
|
-
CreatedAt: new Date(),
|
369
|
-
SystemId: 175,
|
370
|
-
SystemPrivilege: {
|
371
|
-
PrivilegeId: 'clcogto8t00043unyd60c8j6r',
|
372
|
-
SystemId: 175,
|
373
|
-
Code: 'Signing Session - No Show',
|
374
|
-
Module: null,
|
375
|
-
Description:
|
376
|
-
'Allows the user to mark the signing session as "no show".',
|
377
|
-
CreatedAt: new Date(),
|
378
|
-
UpdatedAt: new Date(),
|
379
|
-
},
|
380
|
-
},
|
381
|
-
{
|
382
|
-
GroupCode: 'EZCAT',
|
383
|
-
RoleId: 'clcogtmyx00014dn4798pel3n',
|
384
|
-
PrivilegeId: 'clcogtobc00073wp21lanh2qw',
|
385
|
-
CreatedById: 74,
|
386
|
-
CreatedAt: new Date(),
|
387
|
-
SystemId: 175,
|
388
|
-
SystemPrivilege: {
|
389
|
-
PrivilegeId: 'clcogtobc00073wp21lanh2qw',
|
390
|
-
SystemId: 175,
|
391
|
-
Code: 'Setup Session',
|
392
|
-
Module: null,
|
393
|
-
Description:
|
394
|
-
'Allows the users to set up the predefined slots for the live attestation sessions.',
|
395
|
-
CreatedAt: new Date(),
|
396
|
-
UpdatedAt: new Date(),
|
397
|
-
},
|
398
|
-
},
|
399
|
-
],
|
400
|
-
};
|
401
|
-
|
402
|
-
let userUserGroups = [
|
403
|
-
{
|
404
|
-
UserId: 755,
|
405
|
-
GroupCode: 'EZCFT',
|
406
|
-
SystemId: 175,
|
407
|
-
CreatedAt: new Date(),
|
408
|
-
UpdatedAt: new Date(),
|
409
|
-
UserGroup: ezcft,
|
410
|
-
},
|
411
|
-
];
|
412
|
-
|
413
|
-
jest.mock('crypto', () => {
|
414
|
-
return {
|
415
|
-
randomUUID: jest.fn().mockReturnValue('ckymxuh8t000137t011w89zgk'),
|
416
|
-
};
|
417
|
-
});
|
418
|
-
|
419
|
-
jest
|
420
|
-
.spyOn(PasswordHashService.prototype, 'verify')
|
421
|
-
.mockImplementation(async (password) => {
|
422
|
-
if (password === 'Abcd@1234') {
|
423
|
-
return true;
|
424
|
-
} else {
|
425
|
-
return false;
|
426
|
-
}
|
427
|
-
});
|
428
|
-
|
429
|
-
jest
|
430
|
-
.spyOn(SystemRepository.prototype, 'findOne')
|
431
|
-
.mockResolvedValue(system as any);
|
432
|
-
|
433
|
-
jest.spyOn(SMTPMailer.prototype, 'send').mockImplementation(async () => { });
|
434
|
-
|
435
|
-
const getUserGroupFromDBMock = jest.spyOn(
|
436
|
-
LoginUser.prototype as any,
|
437
|
-
'getUserGroupFromDB',
|
438
|
-
);
|
439
|
-
|
440
|
-
const getUserUserGroupFromDBMock = jest.spyOn(
|
441
|
-
LoginUser.prototype as any,
|
442
|
-
'getUserUserGroupFromDB',
|
443
|
-
);
|
444
|
-
|
445
|
-
const userMock = jest.spyOn(UserRepository.prototype, 'findOne');
|
446
|
-
|
447
|
-
jest
|
448
|
-
.spyOn(SessionService.prototype, 'retrieveUserSession')
|
449
|
-
.mockImplementation(async (userId: string) => {
|
450
|
-
if (userId && userId == '755' && isSessionExist === true) {
|
451
|
-
return session;
|
452
|
-
} else {
|
453
|
-
return {
|
454
|
-
systemLogins: [],
|
455
|
-
};
|
456
|
-
}
|
457
|
-
});
|
458
|
-
|
459
|
-
userMock.mockResolvedValue(user as any);
|
460
|
-
|
461
|
-
getUserGroupFromDBMock.mockImplementation(async (groupCode) => {
|
462
|
-
if (groupCode === 'EZCFT') {
|
463
|
-
return ezcft;
|
464
|
-
} else if (groupCode === 'EZCCS') {
|
465
|
-
return ezccs;
|
466
|
-
} else if (groupCode === 'EZCAT') {
|
467
|
-
return ezcat;
|
468
|
-
}
|
469
|
-
});
|
470
|
-
|
471
|
-
getUserUserGroupFromDBMock.mockImplementation(async () => {
|
472
|
-
return userUserGroups;
|
473
|
-
});
|
474
|
-
|
475
|
-
describe('login', () => {
|
476
|
-
jest.spyOn(SystemAccessRepository.prototype, 'findOne').mockResolvedValue({
|
477
|
-
...systemAccess,
|
478
|
-
get: () => {
|
479
|
-
return systemAccess;
|
480
|
-
},
|
481
|
-
} as any);
|
482
|
-
|
483
|
-
jest
|
484
|
-
.spyOn(LoginHistoryRepository.prototype, 'findAll')
|
485
|
-
.mockImplementation(async () => {
|
486
|
-
const data = [];
|
487
|
-
return data;
|
488
|
-
});
|
489
|
-
|
490
|
-
jest
|
491
|
-
.spyOn(LoginHistoryRepository.prototype, 'create')
|
492
|
-
.mockResolvedValue({} as any);
|
493
|
-
|
494
|
-
afterAll(() => {
|
495
|
-
jest.clearAllMocks();
|
496
|
-
});
|
497
|
-
|
498
|
-
it('should return login-user service when instansiated', async () => {
|
499
|
-
const sessionService = await SessionService.init();
|
500
|
-
const loginUser = await LoginUser.init(sessionService);
|
501
|
-
expect(loginUser).toBeDefined();
|
502
|
-
});
|
503
|
-
|
504
|
-
it('should able to do login process when no session is already available', async () => {
|
505
|
-
const sessionService = await SessionService.init();
|
506
|
-
const loginUser = await LoginUser.init(sessionService, 755);
|
507
|
-
const result = await loginUser.login(
|
508
|
-
'EZC',
|
509
|
-
'ezcash+florence@tomei.com.my',
|
510
|
-
'Abcd@1234',
|
511
|
-
'1.1.1.1',
|
512
|
-
);
|
513
|
-
expect(result).toEqual('755:ckymxuh8t000137t011w89zgk');
|
514
|
-
});
|
515
|
-
|
516
|
-
it('should able to do login process when session is already available', async () => {
|
517
|
-
const sessionService = await SessionService.init();
|
518
|
-
const loginUser = await LoginUser.init(sessionService, 755);
|
519
|
-
const result = await loginUser.login(
|
520
|
-
'EZC',
|
521
|
-
'ezcash+florence@tomei.com.my',
|
522
|
-
'Abcd@1234',
|
523
|
-
'1.1.1.1',
|
524
|
-
);
|
525
|
-
expect(result).toEqual('755:ckymxuh8t000137t011w89zgk');
|
526
|
-
});
|
527
|
-
});
|
528
|
-
|
529
|
-
describe('getPrivileges', () => {
|
530
|
-
afterAll(() => {
|
531
|
-
jest.clearAllMocks();
|
532
|
-
});
|
533
|
-
|
534
|
-
it('should be able to login when user only have one user group with level 1 or higher', async () => {
|
535
|
-
const sessionService = await SessionService.init();
|
536
|
-
const loginUser = await LoginUser.init(sessionService, 755);
|
537
|
-
const result = await loginUser['getPrivileges']('EZC');
|
538
|
-
expect(getUserGroupFromDBMock).toBeCalledTimes(2);
|
539
|
-
expect(result).toEqual([
|
540
|
-
'View Customer',
|
541
|
-
'Signer - Company',
|
542
|
-
'Download - Agreement',
|
543
|
-
'Loan - Retrieve List',
|
544
|
-
'Signing Session - Schedule',
|
545
|
-
'Signing Session - No Show',
|
546
|
-
'Setup Session',
|
547
|
-
'Terminate',
|
548
|
-
'Disbursement - Confirmation',
|
549
|
-
'Invoice Payment Received',
|
550
|
-
'Terminate Data',
|
551
|
-
]);
|
552
|
-
});
|
553
|
-
|
554
|
-
it('should be able to login when user only have multiple user user group', async () => {
|
555
|
-
const tempUserUserGroups = userUserGroups;
|
556
|
-
userUserGroups.push(userUserGroups[0]);
|
557
|
-
|
558
|
-
const sessionService = await SessionService.init();
|
559
|
-
const loginUser = await LoginUser.init(sessionService, 755);
|
560
|
-
const result = await loginUser['getPrivileges']('EZC');
|
561
|
-
expect(getUserUserGroupFromDBMock).toBeCalledTimes(1);
|
562
|
-
expect(getUserGroupFromDBMock).toBeCalledTimes(4);
|
563
|
-
expect(result).toEqual([
|
564
|
-
'View Customer',
|
565
|
-
'Signer - Company',
|
566
|
-
'Download - Agreement',
|
567
|
-
'Loan - Retrieve List',
|
568
|
-
'Signing Session - Schedule',
|
569
|
-
'Signing Session - No Show',
|
570
|
-
'Setup Session',
|
571
|
-
'Terminate',
|
572
|
-
'Disbursement - Confirmation',
|
573
|
-
'Invoice Payment Received',
|
574
|
-
'Terminate Data',
|
575
|
-
]);
|
576
|
-
|
577
|
-
userUserGroups = tempUserUserGroups;
|
578
|
-
});
|
579
|
-
|
580
|
-
it('should be able to login when user only have user privilege', async () => {
|
581
|
-
const tempUserUserGroup = userUserGroups;
|
582
|
-
userUserGroups = [];
|
583
|
-
|
584
|
-
const sessionService = await SessionService.init();
|
585
|
-
const loginUser = await LoginUser.init(sessionService, 755);
|
586
|
-
const result = await loginUser['getPrivileges']('EZC');
|
587
|
-
expect(getUserGroupFromDBMock).toBeCalledTimes(0);
|
588
|
-
expect(result).toEqual(['Terminate Data']);
|
589
|
-
|
590
|
-
userUserGroups = tempUserUserGroup;
|
591
|
-
});
|
592
|
-
|
593
|
-
it('should be able to login when user only have one user group with no parent', async () => {
|
594
|
-
const tempEzcft = ezcft;
|
595
|
-
ezcft.GroupLevel = 0;
|
596
|
-
const tempUser = user;
|
597
|
-
user.SystemPrivileges = [];
|
598
|
-
|
599
|
-
const sessionService = await SessionService.init();
|
600
|
-
const loginUser = await LoginUser.init(sessionService, 755);
|
601
|
-
const result = await loginUser['getPrivileges']('EZC');
|
602
|
-
expect(getUserGroupFromDBMock).toBeCalledTimes(0);
|
603
|
-
expect(result).toEqual([
|
604
|
-
'Terminate',
|
605
|
-
'Download - Agreement',
|
606
|
-
'Disbursement - Confirmation',
|
607
|
-
'Invoice Payment Received',
|
608
|
-
]);
|
609
|
-
|
610
|
-
ezcft = tempEzcft;
|
611
|
-
user = tempUser;
|
612
|
-
});
|
613
|
-
|
614
|
-
it('should be able to login when user only have one user group that cannot inherit privilege', async () => {
|
615
|
-
const tempEzcft = ezcft;
|
616
|
-
ezcft.GroupLevel = 1;
|
617
|
-
ezcft.AllowInheritFromParentYN = 'N';
|
618
|
-
const tempUser = user;
|
619
|
-
user.SystemPrivileges = [];
|
620
|
-
|
621
|
-
const sessionService = await SessionService.init();
|
622
|
-
const loginUser = await LoginUser.init(sessionService, 755);
|
623
|
-
const result = await loginUser['getPrivileges']('EZC');
|
624
|
-
expect(getUserGroupFromDBMock).toBeCalledTimes(0);
|
625
|
-
expect(result).toEqual([
|
626
|
-
'Terminate',
|
627
|
-
'Download - Agreement',
|
628
|
-
'Disbursement - Confirmation',
|
629
|
-
'Invoice Payment Received',
|
630
|
-
]);
|
631
|
-
|
632
|
-
ezcft = tempEzcft;
|
633
|
-
user = tempUser;
|
634
|
-
});
|
635
|
-
|
636
|
-
it('should be able to login when user dont have user privilage or user usergroup', async () => {
|
637
|
-
const tempUser = user;
|
638
|
-
user.SystemPrivileges = [];
|
639
|
-
const tempUserUserGroup = userUserGroups;
|
640
|
-
userUserGroups = [];
|
641
|
-
|
642
|
-
const sessionService = await SessionService.init();
|
643
|
-
const loginUser = await LoginUser.init(sessionService, 755);
|
644
|
-
const result = await loginUser['getPrivileges']('EZC');
|
645
|
-
expect(getUserGroupFromDBMock).toBeCalledTimes(0);
|
646
|
-
expect(result).toEqual([]);
|
647
|
-
|
648
|
-
userUserGroups = tempUserUserGroup;
|
649
|
-
user = tempUser;
|
650
|
-
});
|
651
|
-
});
|
652
|
-
|
653
|
-
describe('checkPrivileges', () => {
|
654
|
-
afterEach(() => {
|
655
|
-
isSessionExist = true;
|
656
|
-
});
|
657
|
-
|
658
|
-
it('should return false if user session not found', async () => {
|
659
|
-
isSessionExist = false;
|
660
|
-
const sessionService = await SessionService.init();
|
661
|
-
const loginUser = await LoginUser.init(sessionService, 755);
|
662
|
-
const result = await loginUser.checkPrivileges('EZC', 'Terminate');
|
663
|
-
expect(result).toEqual(false);
|
664
|
-
});
|
665
|
-
|
666
|
-
it('should return false if system login not found', async () => {
|
667
|
-
isSessionExist = false;
|
668
|
-
const sessionService = await SessionService.init();
|
669
|
-
const loginUser = await LoginUser.init(sessionService, 755);
|
670
|
-
const result = await loginUser.checkPrivileges('EZC', 'Terminate');
|
671
|
-
expect(result).toEqual(false);
|
672
|
-
});
|
673
|
-
|
674
|
-
it('should return false if privilege not found', async () => {
|
675
|
-
isSessionExist = false;
|
676
|
-
const sessionService = await SessionService.init();
|
677
|
-
const loginUser = await LoginUser.init(sessionService, 755);
|
678
|
-
const result = await loginUser.checkPrivileges('EZC', 'Not Terminate');
|
679
|
-
expect(result).toEqual(false);
|
680
|
-
});
|
681
|
-
|
682
|
-
it('should return true if privilege found', async () => {
|
683
|
-
const sessionService = await SessionService.init();
|
684
|
-
const loginUser = await LoginUser.init(sessionService, 755);
|
685
|
-
const result = await loginUser.checkPrivileges('EZC', 'Terminate');
|
686
|
-
expect(result).toEqual(true);
|
687
|
-
});
|
688
|
-
});
|
689
|
-
|
690
|
-
describe('checkSession', () => {
|
691
|
-
afterEach(() => {
|
692
|
-
isSessionExist = true;
|
693
|
-
});
|
694
|
-
|
695
|
-
it('it should returns session expired if user session not found inside session storage', async () => {
|
696
|
-
try {
|
697
|
-
isSessionExist = false;
|
698
|
-
const sessionService = await SessionService.init();
|
699
|
-
const loginUser = await LoginUser.init(sessionService, 755);
|
700
|
-
await loginUser.checkSession(
|
701
|
-
'EZC',
|
702
|
-
session.systemLogins[0].sessionId,
|
703
|
-
'755',
|
704
|
-
);
|
705
|
-
} catch (error) {
|
706
|
-
expect(error.message).toEqual('Session expired.');
|
707
|
-
}
|
708
|
-
});
|
709
|
-
|
710
|
-
it('it should returns session expired if sessionId not matched', async () => {
|
711
|
-
try {
|
712
|
-
const sessionService = await SessionService.init();
|
713
|
-
const loginUser = await LoginUser.init(sessionService, 755);
|
714
|
-
await loginUser.checkSession(
|
715
|
-
'NOTEZC',
|
716
|
-
session.systemLogins[0].sessionId,
|
717
|
-
'755',
|
718
|
-
);
|
719
|
-
} catch (error) {
|
720
|
-
expect(error.message).toEqual('Session expired.');
|
721
|
-
}
|
722
|
-
});
|
723
|
-
|
724
|
-
it('it should refresh session time-to-live if session valid', async () => {
|
725
|
-
jest
|
726
|
-
.spyOn(SessionService.prototype, 'refreshDuration')
|
727
|
-
.mockImplementationOnce(async (userId) => {
|
728
|
-
if (!userId || userId !== '755') {
|
729
|
-
throw new Error('Refresh session failed.');
|
730
|
-
}
|
731
|
-
});
|
732
|
-
const sessionService = await SessionService.init();
|
733
|
-
const loginUser = await LoginUser.init(sessionService, 755);
|
734
|
-
const result = await loginUser.checkSession(
|
735
|
-
'EZC',
|
736
|
-
session.systemLogins[0].sessionId,
|
737
|
-
'755',
|
738
|
-
);
|
739
|
-
expect(result).toEqual(session.systemLogins[0]);
|
740
|
-
});
|
741
|
-
});
|
742
|
-
});
|
1
|
+
import { IUserSession } from '../../../../src/interfaces/user-session.interface';
|
2
|
+
import {
|
3
|
+
LoginHistoryRepository,
|
4
|
+
SessionService,
|
5
|
+
SystemAccessRepository,
|
6
|
+
SystemRepository,
|
7
|
+
} from '../../../../src';
|
8
|
+
import { LoginUser } from '../../../../src/components/login-user/login-user';
|
9
|
+
import { UserRepository } from '../../../../src/components/login-user/user.repository';
|
10
|
+
import { PasswordHashService } from '../../../../src/components/password-hash/password-hash.service';
|
11
|
+
import { SMTPMailer } from '@tomei/mailer';
|
12
|
+
describe('login-user', () => {
|
13
|
+
let isSessionExist = true;
|
14
|
+
let user = {
|
15
|
+
id: 755,
|
16
|
+
Email: 'ezcash+florence@tomei.com.my',
|
17
|
+
Password:
|
18
|
+
'$argon2id$v=19$m=4096,t=3,p=1$571ilUAi9n5g393m/NqKbQ$2bMnLtMCIVTjHWHGEDxI2wo+A3mrL3N5rTxDJ6ydPi8',
|
19
|
+
Status: null,
|
20
|
+
DefaultPasswordChanged: false,
|
21
|
+
FirstLoginAt: new Date('2023-01-10T07:57:10.000Z'),
|
22
|
+
CreatedAt: new Date('2023-01-10T07:57:10.000Z'),
|
23
|
+
UpdatedAt: new Date('2023-01-10T08:58:15.000Z'),
|
24
|
+
GroupCode: 'EZCFT',
|
25
|
+
Staff: [
|
26
|
+
{
|
27
|
+
id: 740,
|
28
|
+
StaffId: 'EZC003',
|
29
|
+
FullName: 'EZC Florence',
|
30
|
+
PreferredName: 'EZC Florence',
|
31
|
+
Email: 'ezcash+florence@tomei.com.my',
|
32
|
+
StaffTypeId: 1,
|
33
|
+
JobTitle: 'EZC Finance',
|
34
|
+
CarPlate: '',
|
35
|
+
Mobile: '60123456',
|
36
|
+
Floor: null,
|
37
|
+
Extension: null,
|
38
|
+
IsCharge: false,
|
39
|
+
Status: 'active',
|
40
|
+
UserId: 755,
|
41
|
+
BuildingId: 20,
|
42
|
+
DepartmentId: 110,
|
43
|
+
CompanyId: 70,
|
44
|
+
CreatedById: 74,
|
45
|
+
UpdatedById: 74,
|
46
|
+
CcreatedAt: new Date('2023-01-10T07:57:10.000Z'),
|
47
|
+
UpdatedAt: new Date('2023-01-10T07:57:10.000Z'),
|
48
|
+
Image: null,
|
49
|
+
IdNo: '123123123',
|
50
|
+
FullAddress: 'Lorem Address',
|
51
|
+
},
|
52
|
+
],
|
53
|
+
SystemPrivileges: [
|
54
|
+
{
|
55
|
+
PrivilegeId: 'ckymxuh8t000137t011w89zgk',
|
56
|
+
SystemId: 175,
|
57
|
+
Code: 'Terminate Data',
|
58
|
+
Module: null,
|
59
|
+
Description: 'Allows the user to terminate a loan.',
|
60
|
+
CreatedAt: new Date(),
|
61
|
+
UpdatedAt: new Date(),
|
62
|
+
},
|
63
|
+
],
|
64
|
+
};
|
65
|
+
|
66
|
+
const system = {
|
67
|
+
id: 175,
|
68
|
+
Code: 'EZC',
|
69
|
+
Name: 'EzCash',
|
70
|
+
Description: 'Tomei Money Lending System',
|
71
|
+
AccessUrl: 'https://app.ezcash.com.my:22443/staff/login',
|
72
|
+
GooglePlayUrl: '',
|
73
|
+
AppleStoreUrl: '',
|
74
|
+
ApiKey: 'VqS9ks2Lwvqd7HrVUMMIP2q7zaEH689HCPaEaFUQLmiRoZnt',
|
75
|
+
Logo: 'https://sso-api.tomei.com.my/upload/2023/01/10/FJ3DoHdRZKjf2bGkgA4E-BrowserIcon.png',
|
76
|
+
Status: 'active',
|
77
|
+
Visible: true,
|
78
|
+
CreatedAt: new Date('2023-01-09T00:45:57.000Z'),
|
79
|
+
UpdatedAt: new Date('2023-01-10T06:28:56.000Z'),
|
80
|
+
ApiSecret:
|
81
|
+
'$argon2id$v=19$m=4096,t=3,p=1$lqxfk/ujftswf2jSEu156g$j2IShE/BZUUoH/1jrvt3GGRSy0rA8HilJvK17e6vdFY',
|
82
|
+
UpdatedById: 61,
|
83
|
+
CreatedById: 100,
|
84
|
+
};
|
85
|
+
|
86
|
+
const systemAccess = {
|
87
|
+
UserId: 755,
|
88
|
+
SystemId: 175,
|
89
|
+
UpdatedAt: new Date('2023-01-09T00:45:57.000'),
|
90
|
+
};
|
91
|
+
|
92
|
+
const session: IUserSession = {
|
93
|
+
systemLogins: [
|
94
|
+
{
|
95
|
+
id: '175',
|
96
|
+
code: 'EZC',
|
97
|
+
sessionId: 'ckymxuh8t000137t011w89zgk',
|
98
|
+
privileges: [
|
99
|
+
'Terminate',
|
100
|
+
'Download - Agreement',
|
101
|
+
'Disbursement - Confirmation',
|
102
|
+
'Invoice Payment Received',
|
103
|
+
'Download - Disbursement Receipt',
|
104
|
+
'Download - Stamping Receipt',
|
105
|
+
'Installment Payment Received',
|
106
|
+
'View Transaction History',
|
107
|
+
'Menu - Loans',
|
108
|
+
'Loan - Full Settlement',
|
109
|
+
'View Billing',
|
110
|
+
'Loan - Retrieve List',
|
111
|
+
'Loan - View Details',
|
112
|
+
'Loan - Retrieve Outstanding',
|
113
|
+
'Loan - View Mandate Details',
|
114
|
+
'Loan Document - Retrieve List',
|
115
|
+
'Loan Document - View',
|
116
|
+
'Loan Document - Download',
|
117
|
+
'Application - View Details',
|
118
|
+
'Simple Loan Schedule - Get Overdue Schedules',
|
119
|
+
'Simple Loan Schedule - Get Schedule Payment Details',
|
120
|
+
'Retrieve Media List',
|
121
|
+
'Retrieve Customer List',
|
122
|
+
'View Loan Activity',
|
123
|
+
'Activate Installment',
|
124
|
+
'Manual Payment Receipt',
|
125
|
+
'Customer Documents - View',
|
126
|
+
],
|
127
|
+
},
|
128
|
+
],
|
129
|
+
};
|
130
|
+
|
131
|
+
let ezcft = {
|
132
|
+
GroupCode: 'EZCFT',
|
133
|
+
GroupDescription: 'EZCASH FINANCE TEAM',
|
134
|
+
Status: 'Active',
|
135
|
+
PersonInCharge: null,
|
136
|
+
FullPath: null,
|
137
|
+
ParentGroupCode: 'EZCCS',
|
138
|
+
GroupLevel: 2,
|
139
|
+
GroupType: null,
|
140
|
+
AllowInheritFromParentYN: 'Y',
|
141
|
+
CreatedById: '61',
|
142
|
+
CreatedAt: new Date(),
|
143
|
+
UpdatedById: '61',
|
144
|
+
UpdatedAt: new Date(),
|
145
|
+
DepartmentId: 110,
|
146
|
+
GroupSystemPrivileges: [],
|
147
|
+
GroupRolePrivileges: [
|
148
|
+
{
|
149
|
+
GroupCode: 'EZCFT',
|
150
|
+
RoleId: 'clcogtmco00013unyc4ngcnza',
|
151
|
+
PrivilegeId: 'clcogtntx00023unyg98a0ah0',
|
152
|
+
CreatedById: 74,
|
153
|
+
CreatedAt: new Date(),
|
154
|
+
SystemId: 175,
|
155
|
+
SystemPrivilege: {
|
156
|
+
PrivilegeId: 'clcogtntx00023unyg98a0ah0',
|
157
|
+
SystemId: 175,
|
158
|
+
Code: 'Terminate',
|
159
|
+
Module: null,
|
160
|
+
Description: 'Allows the user to terminate a loan.',
|
161
|
+
CreatedAt: new Date(),
|
162
|
+
UpdatedAt: new Date(),
|
163
|
+
},
|
164
|
+
},
|
165
|
+
{
|
166
|
+
GroupCode: 'EZCFT',
|
167
|
+
RoleId: 'clcogtmco00013unyc4ngcnza',
|
168
|
+
PrivilegeId: 'clcogtnys00043wp21ejm068j',
|
169
|
+
CreatedById: 74,
|
170
|
+
CreatedAt: new Date(),
|
171
|
+
SystemId: 175,
|
172
|
+
SystemPrivilege: {
|
173
|
+
PrivilegeId: 'clcogtnys00043wp21ejm068j',
|
174
|
+
SystemId: 175,
|
175
|
+
Code: 'Download - Agreement',
|
176
|
+
Module: null,
|
177
|
+
Description: 'Allows the user to download the agreement.',
|
178
|
+
CreatedAt: new Date(),
|
179
|
+
UpdatedAt: new Date(),
|
180
|
+
},
|
181
|
+
},
|
182
|
+
{
|
183
|
+
GroupCode: 'EZCFT',
|
184
|
+
RoleId: 'clcogtmco00013unyc4ngcnza',
|
185
|
+
PrivilegeId: 'clcogtoa100063wp2djq10roz',
|
186
|
+
CreatedById: 74,
|
187
|
+
CreatedAt: new Date(),
|
188
|
+
SystemId: 175,
|
189
|
+
SystemPrivilege: {
|
190
|
+
PrivilegeId: 'clcogtoa100063wp2djq10roz',
|
191
|
+
SystemId: 175,
|
192
|
+
Code: 'Disbursement - Confirmation',
|
193
|
+
Module: null,
|
194
|
+
Description:
|
195
|
+
'Allows the user to confirm the disbursement of the loan.',
|
196
|
+
CreatedAt: new Date(),
|
197
|
+
UpdatedAt: new Date(),
|
198
|
+
},
|
199
|
+
},
|
200
|
+
{
|
201
|
+
GroupCode: 'EZCFT',
|
202
|
+
RoleId: 'clcogtmco00013unyc4ngcnza',
|
203
|
+
PrivilegeId: 'clcogtob000053uny52atenxa',
|
204
|
+
CreatedById: 74,
|
205
|
+
CreatedAt: new Date(),
|
206
|
+
SystemId: 175,
|
207
|
+
SystemPrivilege: {
|
208
|
+
PrivilegeId: 'clcogtob000053uny52atenxa',
|
209
|
+
SystemId: 175,
|
210
|
+
Code: 'Invoice Payment Received',
|
211
|
+
Module: null,
|
212
|
+
Description:
|
213
|
+
'Allows the user to confirm payment receipt of an invoice.',
|
214
|
+
CreatedAt: new Date(),
|
215
|
+
UpdatedAt: new Date(),
|
216
|
+
},
|
217
|
+
},
|
218
|
+
],
|
219
|
+
};
|
220
|
+
|
221
|
+
const ezccs = {
|
222
|
+
GroupCode: 'EZCCS',
|
223
|
+
GroupDescription: 'EZCASH COMPANY SIGNER',
|
224
|
+
Status: 'Active',
|
225
|
+
PersonInCharge: null,
|
226
|
+
FullPath: null,
|
227
|
+
ParentGroupCode: 'EZCAT',
|
228
|
+
GroupLevel: 1,
|
229
|
+
GroupType: null,
|
230
|
+
AllowInheritFromParentYN: 'Y',
|
231
|
+
CreatedById: '61',
|
232
|
+
CreatedAt: new Date(),
|
233
|
+
UpdatedById: '61',
|
234
|
+
UpdatedAt: new Date(),
|
235
|
+
DepartmentId: 110,
|
236
|
+
GroupSystemPrivileges: [],
|
237
|
+
GroupRolePrivileges: [
|
238
|
+
{
|
239
|
+
GroupCode: 'EZCCS',
|
240
|
+
RoleId: 'cl34552or00002vlubgs11tc9',
|
241
|
+
PrivilegeId: 'cldu3gd7t000g3spe55jmax51',
|
242
|
+
CreatedById: 700,
|
243
|
+
CreatedAt: new Date(),
|
244
|
+
SystemId: 42,
|
245
|
+
SystemPrivilege: {
|
246
|
+
PrivilegeId: 'cldu3gd7t000g3spe55jmax51',
|
247
|
+
SystemId: 42,
|
248
|
+
Code: 'View Customer',
|
249
|
+
Module: null,
|
250
|
+
Description: 'Allow to view customer details',
|
251
|
+
CreatedAt: new Date(),
|
252
|
+
UpdatedAt: new Date(),
|
253
|
+
},
|
254
|
+
},
|
255
|
+
{
|
256
|
+
GroupCode: 'EZCCS',
|
257
|
+
RoleId: 'clcogtm8000003unybenw69nl',
|
258
|
+
PrivilegeId: 'clcogtnsn00023wp21z5n28az',
|
259
|
+
CreatedById: 700,
|
260
|
+
CreatedAt: new Date(),
|
261
|
+
SystemId: 175,
|
262
|
+
SystemPrivilege: {
|
263
|
+
PrivilegeId: 'clcogtnsn00023wp21z5n28az',
|
264
|
+
SystemId: 175,
|
265
|
+
Code: 'Signer - Company',
|
266
|
+
Module: null,
|
267
|
+
Description:
|
268
|
+
'Allows the user to sign loan agreements on behalf of the company.',
|
269
|
+
CreatedAt: new Date(),
|
270
|
+
UpdatedAt: new Date(),
|
271
|
+
},
|
272
|
+
},
|
273
|
+
{
|
274
|
+
GroupCode: 'EZCCS',
|
275
|
+
RoleId: 'clcogtm8000003unybenw69nl',
|
276
|
+
PrivilegeId: 'clcogtnys00043wp21ejm068j',
|
277
|
+
CreatedById: 700,
|
278
|
+
CreatedAt: new Date(),
|
279
|
+
SystemId: 175,
|
280
|
+
SystemPrivilege: {
|
281
|
+
PrivilegeId: 'clcogtnys00043wp21ejm068j',
|
282
|
+
SystemId: 175,
|
283
|
+
Code: 'Download - Agreement',
|
284
|
+
Module: null,
|
285
|
+
Description: 'Allows the user to download the agreement.',
|
286
|
+
CreatedAt: new Date(),
|
287
|
+
UpdatedAt: new Date(),
|
288
|
+
},
|
289
|
+
},
|
290
|
+
{
|
291
|
+
GroupCode: 'EZCCS',
|
292
|
+
RoleId: 'clcogtm8000003unybenw69nl',
|
293
|
+
PrivilegeId: 'clcogtqb400074dn47ld564nt',
|
294
|
+
CreatedById: 700,
|
295
|
+
CreatedAt: new Date(),
|
296
|
+
SystemId: 175,
|
297
|
+
SystemPrivilege: {
|
298
|
+
PrivilegeId: 'clds7oql500003spe3hubafn6',
|
299
|
+
SystemId: 175,
|
300
|
+
Code: 'Loan - Retrieve List',
|
301
|
+
Module: null,
|
302
|
+
Description:
|
303
|
+
'Allows the user to retrieve the loan listing/search for all loans within the system.',
|
304
|
+
CreatedAt: new Date(),
|
305
|
+
UpdatedAt: new Date(),
|
306
|
+
},
|
307
|
+
},
|
308
|
+
],
|
309
|
+
};
|
310
|
+
|
311
|
+
const ezcat = {
|
312
|
+
GroupCode: 'EZCAT',
|
313
|
+
GroupDescription: 'EZC ATTESTATOR',
|
314
|
+
Status: 'Active',
|
315
|
+
PersonInCharge: null,
|
316
|
+
FullPath: null,
|
317
|
+
ParentGroupCode: null,
|
318
|
+
GroupLevel: 0,
|
319
|
+
GroupType: null,
|
320
|
+
AllowInheritFromParentYN: 'Y',
|
321
|
+
CreatedById: '61',
|
322
|
+
CreatedAt: new Date(),
|
323
|
+
UpdatedById: '61',
|
324
|
+
UpdatedAt: new Date(),
|
325
|
+
DepartmentId: 110,
|
326
|
+
GroupSystemPrivileges: [],
|
327
|
+
GroupRolePrivileges: [
|
328
|
+
{
|
329
|
+
GroupCode: 'EZCAT',
|
330
|
+
RoleId: 'cl34552or00002vlubgs11tc9',
|
331
|
+
PrivilegeId: 'cldu3gd7t000g3spe55jmax51',
|
332
|
+
CreatedById: 700,
|
333
|
+
CreatedAt: new Date(),
|
334
|
+
SystemId: 42,
|
335
|
+
SystemPrivilege: {
|
336
|
+
PrivilegeId: 'cldu3gd7t000g3spe55jmax51',
|
337
|
+
SystemId: 42,
|
338
|
+
Code: 'View Customer',
|
339
|
+
Module: null,
|
340
|
+
Description: 'Allow to view customer details',
|
341
|
+
CreatedAt: new Date(),
|
342
|
+
UpdatedAt: new Date(),
|
343
|
+
},
|
344
|
+
},
|
345
|
+
{
|
346
|
+
GroupCode: 'EZCAT',
|
347
|
+
RoleId: 'clcogtmyx00014dn4798pel3n',
|
348
|
+
PrivilegeId: 'clcogtnuf00033wp27vwb1vwl',
|
349
|
+
CreatedById: 74,
|
350
|
+
CreatedAt: new Date(),
|
351
|
+
SystemId: 175,
|
352
|
+
SystemPrivilege: {
|
353
|
+
PrivilegeId: 'clcogtnuf00033wp27vwb1vwl',
|
354
|
+
SystemId: 175,
|
355
|
+
Code: 'Signing Session - Schedule',
|
356
|
+
Module: null,
|
357
|
+
Description:
|
358
|
+
'Allows the user to schedule or reschedule the signing session.',
|
359
|
+
CreatedAt: new Date(),
|
360
|
+
UpdatedAt: new Date(),
|
361
|
+
},
|
362
|
+
},
|
363
|
+
{
|
364
|
+
GroupCode: 'EZCAT',
|
365
|
+
RoleId: 'clcogtmyx00014dn4798pel3n',
|
366
|
+
PrivilegeId: 'clcogto8t00043unyd60c8j6r',
|
367
|
+
CreatedById: 74,
|
368
|
+
CreatedAt: new Date(),
|
369
|
+
SystemId: 175,
|
370
|
+
SystemPrivilege: {
|
371
|
+
PrivilegeId: 'clcogto8t00043unyd60c8j6r',
|
372
|
+
SystemId: 175,
|
373
|
+
Code: 'Signing Session - No Show',
|
374
|
+
Module: null,
|
375
|
+
Description:
|
376
|
+
'Allows the user to mark the signing session as "no show".',
|
377
|
+
CreatedAt: new Date(),
|
378
|
+
UpdatedAt: new Date(),
|
379
|
+
},
|
380
|
+
},
|
381
|
+
{
|
382
|
+
GroupCode: 'EZCAT',
|
383
|
+
RoleId: 'clcogtmyx00014dn4798pel3n',
|
384
|
+
PrivilegeId: 'clcogtobc00073wp21lanh2qw',
|
385
|
+
CreatedById: 74,
|
386
|
+
CreatedAt: new Date(),
|
387
|
+
SystemId: 175,
|
388
|
+
SystemPrivilege: {
|
389
|
+
PrivilegeId: 'clcogtobc00073wp21lanh2qw',
|
390
|
+
SystemId: 175,
|
391
|
+
Code: 'Setup Session',
|
392
|
+
Module: null,
|
393
|
+
Description:
|
394
|
+
'Allows the users to set up the predefined slots for the live attestation sessions.',
|
395
|
+
CreatedAt: new Date(),
|
396
|
+
UpdatedAt: new Date(),
|
397
|
+
},
|
398
|
+
},
|
399
|
+
],
|
400
|
+
};
|
401
|
+
|
402
|
+
let userUserGroups = [
|
403
|
+
{
|
404
|
+
UserId: 755,
|
405
|
+
GroupCode: 'EZCFT',
|
406
|
+
SystemId: 175,
|
407
|
+
CreatedAt: new Date(),
|
408
|
+
UpdatedAt: new Date(),
|
409
|
+
UserGroup: ezcft,
|
410
|
+
},
|
411
|
+
];
|
412
|
+
|
413
|
+
jest.mock('crypto', () => {
|
414
|
+
return {
|
415
|
+
randomUUID: jest.fn().mockReturnValue('ckymxuh8t000137t011w89zgk'),
|
416
|
+
};
|
417
|
+
});
|
418
|
+
|
419
|
+
jest
|
420
|
+
.spyOn(PasswordHashService.prototype, 'verify')
|
421
|
+
.mockImplementation(async (password) => {
|
422
|
+
if (password === 'Abcd@1234') {
|
423
|
+
return true;
|
424
|
+
} else {
|
425
|
+
return false;
|
426
|
+
}
|
427
|
+
});
|
428
|
+
|
429
|
+
jest
|
430
|
+
.spyOn(SystemRepository.prototype, 'findOne')
|
431
|
+
.mockResolvedValue(system as any);
|
432
|
+
|
433
|
+
jest.spyOn(SMTPMailer.prototype, 'send').mockImplementation(async () => { });
|
434
|
+
|
435
|
+
const getUserGroupFromDBMock = jest.spyOn(
|
436
|
+
LoginUser.prototype as any,
|
437
|
+
'getUserGroupFromDB',
|
438
|
+
);
|
439
|
+
|
440
|
+
const getUserUserGroupFromDBMock = jest.spyOn(
|
441
|
+
LoginUser.prototype as any,
|
442
|
+
'getUserUserGroupFromDB',
|
443
|
+
);
|
444
|
+
|
445
|
+
const userMock = jest.spyOn(UserRepository.prototype, 'findOne');
|
446
|
+
|
447
|
+
jest
|
448
|
+
.spyOn(SessionService.prototype, 'retrieveUserSession')
|
449
|
+
.mockImplementation(async (userId: string) => {
|
450
|
+
if (userId && userId == '755' && isSessionExist === true) {
|
451
|
+
return session;
|
452
|
+
} else {
|
453
|
+
return {
|
454
|
+
systemLogins: [],
|
455
|
+
};
|
456
|
+
}
|
457
|
+
});
|
458
|
+
|
459
|
+
userMock.mockResolvedValue(user as any);
|
460
|
+
|
461
|
+
getUserGroupFromDBMock.mockImplementation(async (groupCode) => {
|
462
|
+
if (groupCode === 'EZCFT') {
|
463
|
+
return ezcft;
|
464
|
+
} else if (groupCode === 'EZCCS') {
|
465
|
+
return ezccs;
|
466
|
+
} else if (groupCode === 'EZCAT') {
|
467
|
+
return ezcat;
|
468
|
+
}
|
469
|
+
});
|
470
|
+
|
471
|
+
getUserUserGroupFromDBMock.mockImplementation(async () => {
|
472
|
+
return userUserGroups;
|
473
|
+
});
|
474
|
+
|
475
|
+
describe('login', () => {
|
476
|
+
jest.spyOn(SystemAccessRepository.prototype, 'findOne').mockResolvedValue({
|
477
|
+
...systemAccess,
|
478
|
+
get: () => {
|
479
|
+
return systemAccess;
|
480
|
+
},
|
481
|
+
} as any);
|
482
|
+
|
483
|
+
jest
|
484
|
+
.spyOn(LoginHistoryRepository.prototype, 'findAll')
|
485
|
+
.mockImplementation(async () => {
|
486
|
+
const data = [];
|
487
|
+
return data;
|
488
|
+
});
|
489
|
+
|
490
|
+
jest
|
491
|
+
.spyOn(LoginHistoryRepository.prototype, 'create')
|
492
|
+
.mockResolvedValue({} as any);
|
493
|
+
|
494
|
+
afterAll(() => {
|
495
|
+
jest.clearAllMocks();
|
496
|
+
});
|
497
|
+
|
498
|
+
it('should return login-user service when instansiated', async () => {
|
499
|
+
const sessionService = await SessionService.init();
|
500
|
+
const loginUser = await LoginUser.init(sessionService);
|
501
|
+
expect(loginUser).toBeDefined();
|
502
|
+
});
|
503
|
+
|
504
|
+
it('should able to do login process when no session is already available', async () => {
|
505
|
+
const sessionService = await SessionService.init();
|
506
|
+
const loginUser = await LoginUser.init(sessionService, 755);
|
507
|
+
const result = await loginUser.login(
|
508
|
+
'EZC',
|
509
|
+
'ezcash+florence@tomei.com.my',
|
510
|
+
'Abcd@1234',
|
511
|
+
'1.1.1.1',
|
512
|
+
);
|
513
|
+
expect(result).toEqual('755:ckymxuh8t000137t011w89zgk');
|
514
|
+
});
|
515
|
+
|
516
|
+
it('should able to do login process when session is already available', async () => {
|
517
|
+
const sessionService = await SessionService.init();
|
518
|
+
const loginUser = await LoginUser.init(sessionService, 755);
|
519
|
+
const result = await loginUser.login(
|
520
|
+
'EZC',
|
521
|
+
'ezcash+florence@tomei.com.my',
|
522
|
+
'Abcd@1234',
|
523
|
+
'1.1.1.1',
|
524
|
+
);
|
525
|
+
expect(result).toEqual('755:ckymxuh8t000137t011w89zgk');
|
526
|
+
});
|
527
|
+
});
|
528
|
+
|
529
|
+
describe('getPrivileges', () => {
|
530
|
+
afterAll(() => {
|
531
|
+
jest.clearAllMocks();
|
532
|
+
});
|
533
|
+
|
534
|
+
it('should be able to login when user only have one user group with level 1 or higher', async () => {
|
535
|
+
const sessionService = await SessionService.init();
|
536
|
+
const loginUser = await LoginUser.init(sessionService, 755);
|
537
|
+
const result = await loginUser['getPrivileges']('EZC');
|
538
|
+
expect(getUserGroupFromDBMock).toBeCalledTimes(2);
|
539
|
+
expect(result).toEqual([
|
540
|
+
'View Customer',
|
541
|
+
'Signer - Company',
|
542
|
+
'Download - Agreement',
|
543
|
+
'Loan - Retrieve List',
|
544
|
+
'Signing Session - Schedule',
|
545
|
+
'Signing Session - No Show',
|
546
|
+
'Setup Session',
|
547
|
+
'Terminate',
|
548
|
+
'Disbursement - Confirmation',
|
549
|
+
'Invoice Payment Received',
|
550
|
+
'Terminate Data',
|
551
|
+
]);
|
552
|
+
});
|
553
|
+
|
554
|
+
it('should be able to login when user only have multiple user user group', async () => {
|
555
|
+
const tempUserUserGroups = userUserGroups;
|
556
|
+
userUserGroups.push(userUserGroups[0]);
|
557
|
+
|
558
|
+
const sessionService = await SessionService.init();
|
559
|
+
const loginUser = await LoginUser.init(sessionService, 755);
|
560
|
+
const result = await loginUser['getPrivileges']('EZC');
|
561
|
+
expect(getUserUserGroupFromDBMock).toBeCalledTimes(1);
|
562
|
+
expect(getUserGroupFromDBMock).toBeCalledTimes(4);
|
563
|
+
expect(result).toEqual([
|
564
|
+
'View Customer',
|
565
|
+
'Signer - Company',
|
566
|
+
'Download - Agreement',
|
567
|
+
'Loan - Retrieve List',
|
568
|
+
'Signing Session - Schedule',
|
569
|
+
'Signing Session - No Show',
|
570
|
+
'Setup Session',
|
571
|
+
'Terminate',
|
572
|
+
'Disbursement - Confirmation',
|
573
|
+
'Invoice Payment Received',
|
574
|
+
'Terminate Data',
|
575
|
+
]);
|
576
|
+
|
577
|
+
userUserGroups = tempUserUserGroups;
|
578
|
+
});
|
579
|
+
|
580
|
+
it('should be able to login when user only have user privilege', async () => {
|
581
|
+
const tempUserUserGroup = userUserGroups;
|
582
|
+
userUserGroups = [];
|
583
|
+
|
584
|
+
const sessionService = await SessionService.init();
|
585
|
+
const loginUser = await LoginUser.init(sessionService, 755);
|
586
|
+
const result = await loginUser['getPrivileges']('EZC');
|
587
|
+
expect(getUserGroupFromDBMock).toBeCalledTimes(0);
|
588
|
+
expect(result).toEqual(['Terminate Data']);
|
589
|
+
|
590
|
+
userUserGroups = tempUserUserGroup;
|
591
|
+
});
|
592
|
+
|
593
|
+
it('should be able to login when user only have one user group with no parent', async () => {
|
594
|
+
const tempEzcft = ezcft;
|
595
|
+
ezcft.GroupLevel = 0;
|
596
|
+
const tempUser = user;
|
597
|
+
user.SystemPrivileges = [];
|
598
|
+
|
599
|
+
const sessionService = await SessionService.init();
|
600
|
+
const loginUser = await LoginUser.init(sessionService, 755);
|
601
|
+
const result = await loginUser['getPrivileges']('EZC');
|
602
|
+
expect(getUserGroupFromDBMock).toBeCalledTimes(0);
|
603
|
+
expect(result).toEqual([
|
604
|
+
'Terminate',
|
605
|
+
'Download - Agreement',
|
606
|
+
'Disbursement - Confirmation',
|
607
|
+
'Invoice Payment Received',
|
608
|
+
]);
|
609
|
+
|
610
|
+
ezcft = tempEzcft;
|
611
|
+
user = tempUser;
|
612
|
+
});
|
613
|
+
|
614
|
+
it('should be able to login when user only have one user group that cannot inherit privilege', async () => {
|
615
|
+
const tempEzcft = ezcft;
|
616
|
+
ezcft.GroupLevel = 1;
|
617
|
+
ezcft.AllowInheritFromParentYN = 'N';
|
618
|
+
const tempUser = user;
|
619
|
+
user.SystemPrivileges = [];
|
620
|
+
|
621
|
+
const sessionService = await SessionService.init();
|
622
|
+
const loginUser = await LoginUser.init(sessionService, 755);
|
623
|
+
const result = await loginUser['getPrivileges']('EZC');
|
624
|
+
expect(getUserGroupFromDBMock).toBeCalledTimes(0);
|
625
|
+
expect(result).toEqual([
|
626
|
+
'Terminate',
|
627
|
+
'Download - Agreement',
|
628
|
+
'Disbursement - Confirmation',
|
629
|
+
'Invoice Payment Received',
|
630
|
+
]);
|
631
|
+
|
632
|
+
ezcft = tempEzcft;
|
633
|
+
user = tempUser;
|
634
|
+
});
|
635
|
+
|
636
|
+
it('should be able to login when user dont have user privilage or user usergroup', async () => {
|
637
|
+
const tempUser = user;
|
638
|
+
user.SystemPrivileges = [];
|
639
|
+
const tempUserUserGroup = userUserGroups;
|
640
|
+
userUserGroups = [];
|
641
|
+
|
642
|
+
const sessionService = await SessionService.init();
|
643
|
+
const loginUser = await LoginUser.init(sessionService, 755);
|
644
|
+
const result = await loginUser['getPrivileges']('EZC');
|
645
|
+
expect(getUserGroupFromDBMock).toBeCalledTimes(0);
|
646
|
+
expect(result).toEqual([]);
|
647
|
+
|
648
|
+
userUserGroups = tempUserUserGroup;
|
649
|
+
user = tempUser;
|
650
|
+
});
|
651
|
+
});
|
652
|
+
|
653
|
+
describe('checkPrivileges', () => {
|
654
|
+
afterEach(() => {
|
655
|
+
isSessionExist = true;
|
656
|
+
});
|
657
|
+
|
658
|
+
it('should return false if user session not found', async () => {
|
659
|
+
isSessionExist = false;
|
660
|
+
const sessionService = await SessionService.init();
|
661
|
+
const loginUser = await LoginUser.init(sessionService, 755);
|
662
|
+
const result = await loginUser.checkPrivileges('EZC', 'Terminate');
|
663
|
+
expect(result).toEqual(false);
|
664
|
+
});
|
665
|
+
|
666
|
+
it('should return false if system login not found', async () => {
|
667
|
+
isSessionExist = false;
|
668
|
+
const sessionService = await SessionService.init();
|
669
|
+
const loginUser = await LoginUser.init(sessionService, 755);
|
670
|
+
const result = await loginUser.checkPrivileges('EZC', 'Terminate');
|
671
|
+
expect(result).toEqual(false);
|
672
|
+
});
|
673
|
+
|
674
|
+
it('should return false if privilege not found', async () => {
|
675
|
+
isSessionExist = false;
|
676
|
+
const sessionService = await SessionService.init();
|
677
|
+
const loginUser = await LoginUser.init(sessionService, 755);
|
678
|
+
const result = await loginUser.checkPrivileges('EZC', 'Not Terminate');
|
679
|
+
expect(result).toEqual(false);
|
680
|
+
});
|
681
|
+
|
682
|
+
it('should return true if privilege found', async () => {
|
683
|
+
const sessionService = await SessionService.init();
|
684
|
+
const loginUser = await LoginUser.init(sessionService, 755);
|
685
|
+
const result = await loginUser.checkPrivileges('EZC', 'Terminate');
|
686
|
+
expect(result).toEqual(true);
|
687
|
+
});
|
688
|
+
});
|
689
|
+
|
690
|
+
describe('checkSession', () => {
|
691
|
+
afterEach(() => {
|
692
|
+
isSessionExist = true;
|
693
|
+
});
|
694
|
+
|
695
|
+
it('it should returns session expired if user session not found inside session storage', async () => {
|
696
|
+
try {
|
697
|
+
isSessionExist = false;
|
698
|
+
const sessionService = await SessionService.init();
|
699
|
+
const loginUser = await LoginUser.init(sessionService, 755);
|
700
|
+
await loginUser.checkSession(
|
701
|
+
'EZC',
|
702
|
+
session.systemLogins[0].sessionId,
|
703
|
+
'755',
|
704
|
+
);
|
705
|
+
} catch (error) {
|
706
|
+
expect(error.message).toEqual('Session expired.');
|
707
|
+
}
|
708
|
+
});
|
709
|
+
|
710
|
+
it('it should returns session expired if sessionId not matched', async () => {
|
711
|
+
try {
|
712
|
+
const sessionService = await SessionService.init();
|
713
|
+
const loginUser = await LoginUser.init(sessionService, 755);
|
714
|
+
await loginUser.checkSession(
|
715
|
+
'NOTEZC',
|
716
|
+
session.systemLogins[0].sessionId,
|
717
|
+
'755',
|
718
|
+
);
|
719
|
+
} catch (error) {
|
720
|
+
expect(error.message).toEqual('Session expired.');
|
721
|
+
}
|
722
|
+
});
|
723
|
+
|
724
|
+
it('it should refresh session time-to-live if session valid', async () => {
|
725
|
+
jest
|
726
|
+
.spyOn(SessionService.prototype, 'refreshDuration')
|
727
|
+
.mockImplementationOnce(async (userId) => {
|
728
|
+
if (!userId || userId !== '755') {
|
729
|
+
throw new Error('Refresh session failed.');
|
730
|
+
}
|
731
|
+
});
|
732
|
+
const sessionService = await SessionService.init();
|
733
|
+
const loginUser = await LoginUser.init(sessionService, 755);
|
734
|
+
const result = await loginUser.checkSession(
|
735
|
+
'EZC',
|
736
|
+
session.systemLogins[0].sessionId,
|
737
|
+
'755',
|
738
|
+
);
|
739
|
+
expect(result).toEqual(session.systemLogins[0]);
|
740
|
+
});
|
741
|
+
});
|
742
|
+
});
|