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