@tomei/sso 0.2.1 → 0.2.3

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 (153) hide show
  1. package/.commitlintrc.json +22 -22
  2. package/.prettierrc +4 -4
  3. package/Jenkinsfile +42 -0
  4. package/README.md +23 -23
  5. package/__tests__/unit/components/login-history/login-history.repository.spec.ts +95 -95
  6. package/__tests__/unit/components/login-user/login-user.spec.ts +223 -223
  7. package/__tests__/unit/components/login-user/user.repository.spec.ts +81 -81
  8. package/__tests__/unit/components/password-hash/password-hash.service.spec.ts +31 -32
  9. package/__tests__/unit/components/system-access/system-access.repository.spec.ts +78 -78
  10. package/__tests__/unit/redis-client/redis.service.spec.ts +23 -23
  11. package/__tests__/unit/session/session.service.spec.ts +27 -27
  12. package/create-sso-user.sql +39 -39
  13. package/dist/__tests__/unit/components/login-history/login-history.repository.spec.d.ts +1 -1
  14. package/dist/__tests__/unit/components/login-history/login-history.repository.spec.js +98 -98
  15. package/dist/__tests__/unit/components/login-user/login-user.spec.d.ts +1 -1
  16. package/dist/__tests__/unit/components/login-user/login-user.spec.js +207 -207
  17. package/dist/__tests__/unit/components/login-user/login-user.spec.js.map +1 -1
  18. package/dist/__tests__/unit/components/login-user/user.repository.spec.d.ts +1 -1
  19. package/dist/__tests__/unit/components/login-user/user.repository.spec.js +77 -77
  20. package/dist/__tests__/unit/components/password-hash/password-hash.service.spec.d.ts +1 -1
  21. package/dist/__tests__/unit/components/password-hash/password-hash.service.spec.js +37 -37
  22. package/dist/__tests__/unit/components/password-hash/password-hash.service.spec.js.map +1 -1
  23. package/dist/__tests__/unit/components/system/system.repository.spec.d.ts +1 -1
  24. package/dist/__tests__/unit/components/system/system.repository.spec.js +84 -84
  25. package/dist/__tests__/unit/components/system-access/system-access.repository.spec.d.ts +1 -1
  26. package/dist/__tests__/unit/components/system-access/system-access.repository.spec.js +74 -74
  27. package/dist/__tests__/unit/redis-client/redis.service.spec.d.ts +1 -1
  28. package/dist/__tests__/unit/redis-client/redis.service.spec.js +31 -31
  29. package/dist/__tests__/unit/session/session.service.spec.d.ts +1 -1
  30. package/dist/__tests__/unit/session/session.service.spec.js +35 -35
  31. package/dist/index.d.ts +1 -1
  32. package/dist/index.js +17 -17
  33. package/dist/src/components/index.d.ts +7 -7
  34. package/dist/src/components/index.js +23 -23
  35. package/dist/src/components/login-history/index.d.ts +1 -1
  36. package/dist/src/components/login-history/index.js +17 -17
  37. package/dist/src/components/login-history/login-history.repository.d.ts +9 -9
  38. package/dist/src/components/login-history/login-history.repository.js +49 -49
  39. package/dist/src/components/login-user/index.d.ts +3 -3
  40. package/dist/src/components/login-user/index.js +19 -19
  41. package/dist/src/components/login-user/interfaces/index.d.ts +1 -1
  42. package/dist/src/components/login-user/interfaces/index.js +17 -17
  43. package/dist/src/components/login-user/interfaces/user-info.interface.d.ts +9 -9
  44. package/dist/src/components/login-user/interfaces/user-info.interface.js +2 -2
  45. package/dist/src/components/login-user/login-user.d.ts +41 -41
  46. package/dist/src/components/login-user/login-user.js +332 -331
  47. package/dist/src/components/login-user/login-user.js.map +1 -1
  48. package/dist/src/components/login-user/user.repository.d.ts +9 -9
  49. package/dist/src/components/login-user/user.repository.js +49 -49
  50. package/dist/src/components/password-hash/index.d.ts +2 -2
  51. package/dist/src/components/password-hash/index.js +18 -18
  52. package/dist/src/components/password-hash/interfaces/index.d.ts +1 -1
  53. package/dist/src/components/password-hash/interfaces/index.js +17 -17
  54. package/dist/src/components/password-hash/interfaces/password-hash-service.interface.d.ts +4 -4
  55. package/dist/src/components/password-hash/interfaces/password-hash-service.interface.js +2 -2
  56. package/dist/src/components/password-hash/password-hash.service.d.ts +6 -6
  57. package/dist/src/components/password-hash/password-hash.service.js +27 -27
  58. package/dist/src/components/system/index.d.ts +1 -1
  59. package/dist/src/components/system/index.js +17 -17
  60. package/dist/src/components/system/system.repository.d.ts +9 -9
  61. package/dist/src/components/system/system.repository.js +49 -49
  62. package/dist/src/components/system-access/index.d.ts +1 -1
  63. package/dist/src/components/system-access/index.js +17 -17
  64. package/dist/src/components/system-access/system-access.repository.d.ts +9 -9
  65. package/dist/src/components/system-access/system-access.repository.js +49 -49
  66. package/dist/src/components/user-group/index.d.ts +1 -1
  67. package/dist/src/components/user-group/index.js +17 -17
  68. package/dist/src/components/user-group/user-group.repository.d.ts +9 -9
  69. package/dist/src/components/user-group/user-group.repository.js +49 -49
  70. package/dist/src/components/user-user-group/index.d.ts +1 -1
  71. package/dist/src/components/user-user-group/index.js +17 -17
  72. package/dist/src/components/user-user-group/user-user-group.repository.d.ts +9 -9
  73. package/dist/src/components/user-user-group/user-user-group.repository.js +49 -49
  74. package/dist/src/index.d.ts +6 -6
  75. package/dist/src/index.js +23 -23
  76. package/dist/src/interfaces/index.d.ts +2 -2
  77. package/dist/src/interfaces/index.js +18 -18
  78. package/dist/src/interfaces/system-login.interface.d.ts +6 -6
  79. package/dist/src/interfaces/system-login.interface.js +2 -2
  80. package/dist/src/interfaces/user-session.interface.d.ts +4 -4
  81. package/dist/src/interfaces/user-session.interface.js +2 -2
  82. package/dist/src/mail/index.d.ts +2 -2
  83. package/dist/src/mail/index.js +18 -18
  84. package/dist/src/mail/interfaces/index.d.ts +2 -2
  85. package/dist/src/mail/interfaces/index.js +18 -18
  86. package/dist/src/mail/interfaces/send-mail.interface.d.ts +8 -8
  87. package/dist/src/mail/interfaces/send-mail.interface.js +2 -2
  88. package/dist/src/mail/interfaces/send-new-login-alert.interface.d.ts +6 -6
  89. package/dist/src/mail/interfaces/send-new-login-alert.interface.js +2 -2
  90. package/dist/src/mail/mail.d.ts +7 -7
  91. package/dist/src/mail/mail.js +48 -48
  92. package/dist/src/mail/mail.service.d.ts +7 -7
  93. package/dist/src/mail/mail.service.js +41 -41
  94. package/dist/src/prisma-client/__mocks__/prisma.d.ts +3 -3
  95. package/dist/src/prisma-client/__mocks__/prisma.js +13 -13
  96. package/dist/src/prisma-client/client.d.ts +3 -3
  97. package/dist/src/prisma-client/client.js +5 -5
  98. package/dist/src/prisma-client/index.d.ts +1 -1
  99. package/dist/src/prisma-client/index.js +17 -17
  100. package/dist/src/redis-client/__mocks__/jest-initial-setup.d.ts +1 -1
  101. package/dist/src/redis-client/__mocks__/jest-initial-setup.js +4 -4
  102. package/dist/src/redis-client/__mocks__/redis-mock.d.ts +2 -2
  103. package/dist/src/redis-client/__mocks__/redis-mock.js +22 -22
  104. package/dist/src/redis-client/index.d.ts +1 -1
  105. package/dist/src/redis-client/index.js +17 -17
  106. package/dist/src/redis-client/redis.service.d.ts +7 -7
  107. package/dist/src/redis-client/redis.service.js +55 -55
  108. package/dist/src/session/index.d.ts +2 -2
  109. package/dist/src/session/index.js +18 -18
  110. package/dist/src/session/interfaces/index.d.ts +1 -1
  111. package/dist/src/session/interfaces/index.js +17 -17
  112. package/dist/src/session/interfaces/session-service.interface.d.ts +5 -5
  113. package/dist/src/session/interfaces/session-service.interface.js +2 -2
  114. package/dist/src/session/session.service.d.ts +9 -9
  115. package/dist/src/session/session.service.js +51 -51
  116. package/dist/tsconfig.tsbuildinfo +1 -1
  117. package/package.json +69 -69
  118. package/sampledotenv +7 -7
  119. package/src/components/index.ts +7 -7
  120. package/src/components/login-history/index.ts +1 -1
  121. package/src/components/login-history/login-history.repository.ts +33 -33
  122. package/src/components/login-user/index.ts +4 -4
  123. package/src/components/login-user/interfaces/user-info.interface.ts +9 -9
  124. package/src/components/login-user/login-user.ts +5 -2
  125. package/src/components/login-user/user.repository.ts +33 -33
  126. package/src/components/password-hash/index.ts +2 -2
  127. package/src/components/password-hash/interfaces/password-hash-service.interface.ts +4 -4
  128. package/src/components/password-hash/password-hash.service.ts +14 -14
  129. package/src/components/system/index.ts +1 -1
  130. package/src/components/system/system.repository.ts +33 -33
  131. package/src/components/system-access/index.ts +1 -1
  132. package/src/components/system-access/system-access.repository.ts +33 -33
  133. package/src/components/user-group/user-group.repository.ts +33 -33
  134. package/src/components/user-user-group/user-user-group.repository.ts +33 -33
  135. package/src/index.ts +7 -7
  136. package/src/interfaces/index.ts +2 -2
  137. package/src/interfaces/system-login.interface.ts +6 -6
  138. package/src/interfaces/user-session.interface.ts +5 -5
  139. package/src/mail/index.ts +2 -2
  140. package/src/mail/interfaces/index.ts +2 -2
  141. package/src/mail/interfaces/send-mail.interface.ts +8 -8
  142. package/src/mail/interfaces/send-new-login-alert.interface.ts +6 -6
  143. package/src/mail/mail.service.ts +33 -33
  144. package/src/mail/mail.ts +40 -40
  145. package/src/prisma-client/__mocks__/prisma.ts +15 -15
  146. package/src/prisma-client/client.ts +3 -3
  147. package/src/redis-client/__mocks__/jest-initial-setup.ts +2 -2
  148. package/src/redis-client/__mocks__/redis-mock.ts +28 -28
  149. package/src/session/index.ts +2 -2
  150. package/src/session/interfaces/index.ts +1 -1
  151. package/src/session/interfaces/session-service.interface.ts +6 -6
  152. package/src/session/session.service.ts +45 -45
  153. package/tsconfig.build.json +5 -5
@@ -1,223 +1,223 @@
1
- import { IUserSession } from '../../../../src/interfaces/user-session.interface';
2
- import { LoginHistoryRepository, SessionService, SystemAccessRepository, SystemRepository } from '../../../../src';
3
- import { LoginUser } from '../../../../src/components/login-user/login-user';
4
- import { UserRepository } from '../../../../src/components/login-user/user.repository';
5
- import { PasswordHashService } from '../../../../src/components/password-hash/password-hash.service';
6
- import { MailService } from '../../../../src/mail/mail.service';
7
- describe('login-user', () => {
8
- const user = {
9
- id: 755,
10
- email: 'ezcash+florence@tomei.com.my',
11
- password:
12
- '$argon2id$v=19$m=4096,t=3,p=1$571ilUAi9n5g393m/NqKbQ$2bMnLtMCIVTjHWHGEDxI2wo+A3mrL3N5rTxDJ6ydPi8',
13
- status: null,
14
- defaultPasswordChanged: false,
15
- firstLoginAt: new Date('2023-01-10T07:57:10.000Z'),
16
- createdAt: new Date('2023-01-10T07:57:10.000Z'),
17
- updatedAt: new Date('2023-01-10T08:58:15.000Z'),
18
- groupCode: 'EZCFT',
19
- staffs: [
20
- {
21
- id: 740,
22
- staffId: 'EZC003',
23
- fullName: 'EZC Florence',
24
- preferredName: 'EZC Florence',
25
- email: 'ezcash+florence@tomei.com.my',
26
- staffTypeId: 1,
27
- jobTitle: 'EZC Finance',
28
- carPlate: '',
29
- mobile: '60123456',
30
- floor: null,
31
- extension: null,
32
- isCharge: false,
33
- status: 'active',
34
- userId: 755,
35
- buildingId: 20,
36
- departmentId: 110,
37
- companyId: 70,
38
- createdById: 74,
39
- updatedById: 74,
40
- createdAt: new Date('2023-01-10T07:57:10.000Z'),
41
- updatedAt: new Date('2023-01-10T07:57:10.000Z'),
42
- image: null,
43
- idNo: '123123123',
44
- fullAddress: 'Lorem Address',
45
- },
46
- ],
47
- userSystemPrivileges: [
48
- {
49
- userId: 22,
50
- privilegeId: 'ckymxuh8t000137t011w89zgk',
51
- isInheritedYN: 'N',
52
- isRevokedYN: 'N',
53
- createdAt: new Date('2022-04-18T04:07:40.000Z'),
54
- updatedAt: new Date('2022-04-18T04:07:40.000Z'),
55
- systemPrivilege: {
56
- privilegeId: 'ckymxuh8t000137t011w89zgk',
57
- systemId: 11,
58
- code: 'Own',
59
- module: null,
60
- description:
61
- 'Allows the user to only view consignments belonging to themselves',
62
- createdAt: new Date('2022-01-20T12:16:26.000Z'),
63
- updatedAt: new Date('2022-01-20T12:16:26.000Z'),
64
- },
65
- },
66
- ],
67
- };
68
-
69
- const system = {
70
- id: 175,
71
- code: 'EZC',
72
- name: 'EzCash',
73
- description: 'Tomei Money Lending System',
74
- accessUrl: 'https://app.ezcash.com.my:22443/staff/login',
75
- googlePlayUrl: '',
76
- appleStoreUrl: '',
77
- apiKey: 'VqS9ks2Lwvqd7HrVUMMIP2q7zaEH689HCPaEaFUQLmiRoZnt',
78
- logo: 'https://sso-api.tomei.com.my/upload/2023/01/10/FJ3DoHdRZKjf2bGkgA4E-BrowserIcon.png',
79
- status: 'active',
80
- visible: true,
81
- createdAt: new Date('2023-01-09T00:45:57.000Z'),
82
- updatedAt: new Date('2023-01-10T06:28:56.000Z'),
83
- apiSecret:
84
- '$argon2id$v=19$m=4096,t=3,p=1$lqxfk/ujftswf2jSEu156g$j2IShE/BZUUoH/1jrvt3GGRSy0rA8HilJvK17e6vdFY',
85
- updatedById: 61,
86
- createdById: 100,
87
- };
88
-
89
- const systemAccess = {
90
- userId: 755,
91
- systemId: 175,
92
- updatedAt: new Date('2023-01-09T00:45:57.000'),
93
- };
94
-
95
- const session: IUserSession = {
96
- systemLogins: [
97
- {
98
- id: '175',
99
- code: 'EZC',
100
- sessionId: 'ckymxuh8t000137t011w89zgk',
101
- privileges: [
102
- 'Terminate',
103
- 'Download - Agreement',
104
- 'Disbursement - Confirmation',
105
- 'Invoice Payment Received',
106
- 'Download - Disbursement Receipt',
107
- 'Download - Stamping Receipt',
108
- 'Installment Payment Received',
109
- 'View Transaction History',
110
- 'Menu - Loans',
111
- 'Loan - Full Settlement',
112
- 'View Billing',
113
- 'Loan - Retrieve List',
114
- 'Loan - View Details',
115
- 'Loan - Retrieve Outstanding',
116
- 'Loan - View Mandate Details',
117
- 'Loan Document - Retrieve List',
118
- 'Loan Document - View',
119
- 'Loan Document - Download',
120
- 'Application - View Details',
121
- 'Simple Loan Schedule - Get Overdue Schedules',
122
- 'Simple Loan Schedule - Get Schedule Payment Details',
123
- 'Retrieve Media List',
124
- 'Retrieve Customer List',
125
- 'View Loan Activity',
126
- 'Activate Installment',
127
- 'Manual Payment Receipt',
128
- 'Customer Documents - View',
129
- ],
130
- },
131
- ],
132
- };
133
-
134
- jest.mock('crypto', () => {
135
- return {
136
- randomUUID: jest.fn().mockReturnValue('ckymxuh8t000137t011w89zgk'),
137
- };
138
- });
139
-
140
- jest
141
- .spyOn(UserRepository.prototype, 'findOne')
142
- .mockImplementation(async () => {
143
- return user;
144
- });
145
-
146
- jest
147
- .spyOn(PasswordHashService.prototype, 'verify')
148
- .mockImplementation(async (password, hash) => {
149
- if (password === 'Abcd@1234') {
150
- return true;
151
- } else {
152
- return false;
153
- }
154
- });
155
-
156
- jest
157
- .spyOn(SystemRepository .prototype, 'findOne')
158
- .mockImplementation(async () => {
159
- return system;
160
- });
161
-
162
- jest
163
- .spyOn(MailService.prototype, 'sendNewLoginAlertEmail')
164
- .mockImplementation(async () => {});
165
-
166
- jest
167
- .spyOn(LoginUser.prototype, 'getPrivileges')
168
- .mockImplementation(async () => {
169
- return session.systemLogins[0].privileges;
170
- });
171
-
172
- jest
173
- .spyOn(SystemAccessRepository.prototype, 'findOne')
174
- .mockImplementation(async () => {
175
- return systemAccess;
176
- });
177
-
178
- jest
179
- .spyOn(LoginHistoryRepository.prototype, 'findAll')
180
- .mockImplementation(async () => {
181
- const data = [];
182
- return data;
183
- })
184
-
185
- it('should return login-user service when instansiated', async () => {
186
- const loginUser = await LoginUser.init();
187
- expect(loginUser).toBeDefined();
188
- });
189
-
190
- it('should able to do login process when no session is already available', async () => {
191
- const loginUser = await LoginUser.init('755');
192
- const result = await loginUser.login(
193
- 'EZC',
194
- 'ezcash+florence@tomei.com.my',
195
- 'Abcd@1234',
196
- '1.1.1.1',
197
- );
198
- expect(result).toEqual('ckymxuh8t000137t011w89zgk');
199
- });
200
-
201
- it('should able to do login process when session is already available', async () => {
202
- jest
203
- .spyOn(SessionService.prototype, 'retrieveUserSession')
204
- .mockImplementationOnce(async (userId: string) => {
205
- if (userId === '755') {
206
- return session;
207
- } else {
208
- return {
209
- systemLogins: [],
210
- };
211
- }
212
- });
213
-
214
- const loginUser = await LoginUser.init('755');
215
- const result = await loginUser.login(
216
- 'EZC',
217
- 'ezcash+florence@tomei.com.my',
218
- 'Abcd@1234',
219
- '1.1.1.1',
220
- );
221
- expect(result).toEqual('ckymxuh8t000137t011w89zgk');
222
- });
223
- });
1
+ import { IUserSession } from '../../../../src/interfaces/user-session.interface';
2
+ import { LoginHistoryRepository, SessionService, SystemAccessRepository, SystemRepository } from '../../../../src';
3
+ import { LoginUser } from '../../../../src/components/login-user/login-user';
4
+ import { UserRepository } from '../../../../src/components/login-user/user.repository';
5
+ import { PasswordHashService } from '../../../../src/components/password-hash/password-hash.service';
6
+ import { MailService } from '../../../../src/mail/mail.service';
7
+ describe('login-user', () => {
8
+ const user = {
9
+ id: 755,
10
+ email: 'ezcash+florence@tomei.com.my',
11
+ password:
12
+ '$argon2id$v=19$m=4096,t=3,p=1$571ilUAi9n5g393m/NqKbQ$2bMnLtMCIVTjHWHGEDxI2wo+A3mrL3N5rTxDJ6ydPi8',
13
+ status: null,
14
+ defaultPasswordChanged: false,
15
+ firstLoginAt: new Date('2023-01-10T07:57:10.000Z'),
16
+ createdAt: new Date('2023-01-10T07:57:10.000Z'),
17
+ updatedAt: new Date('2023-01-10T08:58:15.000Z'),
18
+ groupCode: 'EZCFT',
19
+ staffs: [
20
+ {
21
+ id: 740,
22
+ staffId: 'EZC003',
23
+ fullName: 'EZC Florence',
24
+ preferredName: 'EZC Florence',
25
+ email: 'ezcash+florence@tomei.com.my',
26
+ staffTypeId: 1,
27
+ jobTitle: 'EZC Finance',
28
+ carPlate: '',
29
+ mobile: '60123456',
30
+ floor: null,
31
+ extension: null,
32
+ isCharge: false,
33
+ status: 'active',
34
+ userId: 755,
35
+ buildingId: 20,
36
+ departmentId: 110,
37
+ companyId: 70,
38
+ createdById: 74,
39
+ updatedById: 74,
40
+ createdAt: new Date('2023-01-10T07:57:10.000Z'),
41
+ updatedAt: new Date('2023-01-10T07:57:10.000Z'),
42
+ image: null,
43
+ idNo: '123123123',
44
+ fullAddress: 'Lorem Address',
45
+ },
46
+ ],
47
+ userSystemPrivileges: [
48
+ {
49
+ userId: 22,
50
+ privilegeId: 'ckymxuh8t000137t011w89zgk',
51
+ isInheritedYN: 'N',
52
+ isRevokedYN: 'N',
53
+ createdAt: new Date('2022-04-18T04:07:40.000Z'),
54
+ updatedAt: new Date('2022-04-18T04:07:40.000Z'),
55
+ systemPrivilege: {
56
+ privilegeId: 'ckymxuh8t000137t011w89zgk',
57
+ systemId: 11,
58
+ code: 'Own',
59
+ module: null,
60
+ description:
61
+ 'Allows the user to only view consignments belonging to themselves',
62
+ createdAt: new Date('2022-01-20T12:16:26.000Z'),
63
+ updatedAt: new Date('2022-01-20T12:16:26.000Z'),
64
+ },
65
+ },
66
+ ],
67
+ };
68
+
69
+ const system = {
70
+ id: 175,
71
+ code: 'EZC',
72
+ name: 'EzCash',
73
+ description: 'Tomei Money Lending System',
74
+ accessUrl: 'https://app.ezcash.com.my:22443/staff/login',
75
+ googlePlayUrl: '',
76
+ appleStoreUrl: '',
77
+ apiKey: 'VqS9ks2Lwvqd7HrVUMMIP2q7zaEH689HCPaEaFUQLmiRoZnt',
78
+ logo: 'https://sso-api.tomei.com.my/upload/2023/01/10/FJ3DoHdRZKjf2bGkgA4E-BrowserIcon.png',
79
+ status: 'active',
80
+ visible: true,
81
+ createdAt: new Date('2023-01-09T00:45:57.000Z'),
82
+ updatedAt: new Date('2023-01-10T06:28:56.000Z'),
83
+ apiSecret:
84
+ '$argon2id$v=19$m=4096,t=3,p=1$lqxfk/ujftswf2jSEu156g$j2IShE/BZUUoH/1jrvt3GGRSy0rA8HilJvK17e6vdFY',
85
+ updatedById: 61,
86
+ createdById: 100,
87
+ };
88
+
89
+ const systemAccess = {
90
+ userId: 755,
91
+ systemId: 175,
92
+ updatedAt: new Date('2023-01-09T00:45:57.000'),
93
+ };
94
+
95
+ const session: IUserSession = {
96
+ systemLogins: [
97
+ {
98
+ id: '175',
99
+ code: 'EZC',
100
+ sessionId: 'ckymxuh8t000137t011w89zgk',
101
+ privileges: [
102
+ 'Terminate',
103
+ 'Download - Agreement',
104
+ 'Disbursement - Confirmation',
105
+ 'Invoice Payment Received',
106
+ 'Download - Disbursement Receipt',
107
+ 'Download - Stamping Receipt',
108
+ 'Installment Payment Received',
109
+ 'View Transaction History',
110
+ 'Menu - Loans',
111
+ 'Loan - Full Settlement',
112
+ 'View Billing',
113
+ 'Loan - Retrieve List',
114
+ 'Loan - View Details',
115
+ 'Loan - Retrieve Outstanding',
116
+ 'Loan - View Mandate Details',
117
+ 'Loan Document - Retrieve List',
118
+ 'Loan Document - View',
119
+ 'Loan Document - Download',
120
+ 'Application - View Details',
121
+ 'Simple Loan Schedule - Get Overdue Schedules',
122
+ 'Simple Loan Schedule - Get Schedule Payment Details',
123
+ 'Retrieve Media List',
124
+ 'Retrieve Customer List',
125
+ 'View Loan Activity',
126
+ 'Activate Installment',
127
+ 'Manual Payment Receipt',
128
+ 'Customer Documents - View',
129
+ ],
130
+ },
131
+ ],
132
+ };
133
+
134
+ jest.mock('crypto', () => {
135
+ return {
136
+ randomUUID: jest.fn().mockReturnValue('ckymxuh8t000137t011w89zgk'),
137
+ };
138
+ });
139
+
140
+ jest
141
+ .spyOn(UserRepository.prototype, 'findOne')
142
+ .mockImplementation(async () => {
143
+ return user;
144
+ });
145
+
146
+ jest
147
+ .spyOn(PasswordHashService.prototype, 'verify')
148
+ .mockImplementation(async (password) => {
149
+ if (password === 'Abcd@1234') {
150
+ return true;
151
+ } else {
152
+ return false;
153
+ }
154
+ });
155
+
156
+ jest
157
+ .spyOn(SystemRepository .prototype, 'findOne')
158
+ .mockImplementation(async () => {
159
+ return system;
160
+ });
161
+
162
+ jest
163
+ .spyOn(MailService.prototype, 'sendNewLoginAlertEmail')
164
+ .mockImplementation(async () => {});
165
+
166
+ jest
167
+ .spyOn(LoginUser.prototype, 'getPrivileges')
168
+ .mockImplementation(async () => {
169
+ return session.systemLogins[0].privileges;
170
+ });
171
+
172
+ jest
173
+ .spyOn(SystemAccessRepository.prototype, 'findOne')
174
+ .mockImplementation(async () => {
175
+ return systemAccess;
176
+ });
177
+
178
+ jest
179
+ .spyOn(LoginHistoryRepository.prototype, 'findAll')
180
+ .mockImplementation(async () => {
181
+ const data = [];
182
+ return data;
183
+ })
184
+
185
+ it('should return login-user service when instansiated', async () => {
186
+ const loginUser = await LoginUser.init();
187
+ expect(loginUser).toBeDefined();
188
+ });
189
+
190
+ it('should able to do login process when no session is already available', async () => {
191
+ const loginUser = await LoginUser.init('755');
192
+ const result = await loginUser.login(
193
+ 'EZC',
194
+ 'ezcash+florence@tomei.com.my',
195
+ 'Abcd@1234',
196
+ '1.1.1.1',
197
+ );
198
+ expect(result).toEqual('ckymxuh8t000137t011w89zgk');
199
+ });
200
+
201
+ it('should able to do login process when session is already available', async () => {
202
+ jest
203
+ .spyOn(SessionService.prototype, 'retrieveUserSession')
204
+ .mockImplementationOnce(async (userId: string) => {
205
+ if (userId === '755') {
206
+ return session;
207
+ } else {
208
+ return {
209
+ systemLogins: [],
210
+ };
211
+ }
212
+ });
213
+
214
+ const loginUser = await LoginUser.init('755');
215
+ const result = await loginUser.login(
216
+ 'EZC',
217
+ 'ezcash+florence@tomei.com.my',
218
+ 'Abcd@1234',
219
+ '1.1.1.1',
220
+ );
221
+ expect(result).toEqual('ckymxuh8t000137t011w89zgk');
222
+ });
223
+ });
@@ -1,81 +1,81 @@
1
- import { UserRepository } from '../../../../src/components/login-user/user.repository';
2
- import { prismaMock } from '../../../../src/prisma-client/__mocks__/prisma';
3
-
4
- describe('system-access.repository', () => {
5
- const data = {
6
- id: 1,
7
- email: 'test@test.email.com',
8
- password: '@H34f5yRE',
9
- status: 'Active',
10
- defaultPasswordChanged: false,
11
- firstLoginAt: new Date(),
12
- createdAt: new Date(),
13
- updatedAt: new Date(),
14
- groupCode: 'RDAS',
15
- };
16
-
17
- afterEach(() => {
18
- jest.restoreAllMocks();
19
- });
20
- describe('findAll', () => {
21
- it('should return list of user', async () => {
22
- prismaMock.user.findMany.mockResolvedValueOnce([data]);
23
- const userRepository = new UserRepository();
24
- expect(await userRepository.findAll({})).toEqual([data]);
25
- });
26
- });
27
-
28
- describe('findOne', () => {
29
- it('should return user', async () => {
30
- prismaMock.user.findFirst.mockResolvedValueOnce(data);
31
- const userRepository = new UserRepository();
32
- expect(
33
- await userRepository.findOne({
34
- where: {
35
- id: data.id,
36
- },
37
- }),
38
- ).toEqual(data);
39
- });
40
- });
41
-
42
- describe('create', () => {
43
- it('should create user', async () => {
44
- prismaMock.user.create.mockResolvedValueOnce(data);
45
- const userRepository = new UserRepository();
46
- expect(await userRepository.create(data)).toEqual(data);
47
- });
48
- });
49
-
50
- describe('update', () => {
51
- it('should update user', async () => {
52
- prismaMock.user.update.mockResolvedValueOnce(data);
53
- const userRepository = new UserRepository();
54
- expect(
55
- await userRepository.update(
56
- {
57
- where: {
58
- id: data.id,
59
- },
60
- data: data,
61
- },
62
- data,
63
- ),
64
- ).toEqual(data);
65
- });
66
- });
67
-
68
- describe('delete', () => {
69
- it('should delete user', async () => {
70
- prismaMock.user.delete.mockResolvedValueOnce(data);
71
- const userRepository = new UserRepository();
72
- expect(
73
- await userRepository.delete({
74
- where: {
75
- id: data.id,
76
- },
77
- }),
78
- ).toEqual(data);
79
- });
80
- });
81
- });
1
+ import { UserRepository } from '../../../../src/components/login-user/user.repository';
2
+ import { prismaMock } from '../../../../src/prisma-client/__mocks__/prisma';
3
+
4
+ describe('system-access.repository', () => {
5
+ const data = {
6
+ id: 1,
7
+ email: 'test@test.email.com',
8
+ password: '@H34f5yRE',
9
+ status: 'Active',
10
+ defaultPasswordChanged: false,
11
+ firstLoginAt: new Date(),
12
+ createdAt: new Date(),
13
+ updatedAt: new Date(),
14
+ groupCode: 'RDAS',
15
+ };
16
+
17
+ afterEach(() => {
18
+ jest.restoreAllMocks();
19
+ });
20
+ describe('findAll', () => {
21
+ it('should return list of user', async () => {
22
+ prismaMock.user.findMany.mockResolvedValueOnce([data]);
23
+ const userRepository = new UserRepository();
24
+ expect(await userRepository.findAll({})).toEqual([data]);
25
+ });
26
+ });
27
+
28
+ describe('findOne', () => {
29
+ it('should return user', async () => {
30
+ prismaMock.user.findFirst.mockResolvedValueOnce(data);
31
+ const userRepository = new UserRepository();
32
+ expect(
33
+ await userRepository.findOne({
34
+ where: {
35
+ id: data.id,
36
+ },
37
+ }),
38
+ ).toEqual(data);
39
+ });
40
+ });
41
+
42
+ describe('create', () => {
43
+ it('should create user', async () => {
44
+ prismaMock.user.create.mockResolvedValueOnce(data);
45
+ const userRepository = new UserRepository();
46
+ expect(await userRepository.create(data)).toEqual(data);
47
+ });
48
+ });
49
+
50
+ describe('update', () => {
51
+ it('should update user', async () => {
52
+ prismaMock.user.update.mockResolvedValueOnce(data);
53
+ const userRepository = new UserRepository();
54
+ expect(
55
+ await userRepository.update(
56
+ {
57
+ where: {
58
+ id: data.id,
59
+ },
60
+ data: data,
61
+ },
62
+ data,
63
+ ),
64
+ ).toEqual(data);
65
+ });
66
+ });
67
+
68
+ describe('delete', () => {
69
+ it('should delete user', async () => {
70
+ prismaMock.user.delete.mockResolvedValueOnce(data);
71
+ const userRepository = new UserRepository();
72
+ expect(
73
+ await userRepository.delete({
74
+ where: {
75
+ id: data.id,
76
+ },
77
+ }),
78
+ ).toEqual(data);
79
+ });
80
+ });
81
+ });