@tomei/sso 0.50.8 → 0.51.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (431) hide show
  1. package/.commitlintrc.json +22 -22
  2. package/.eslintrc +16 -16
  3. package/.eslintrc.js +35 -35
  4. package/.gitlab-ci.yml +16 -16
  5. package/.husky/commit-msg +15 -15
  6. package/.husky/pre-commit +7 -7
  7. package/.prettierrc +4 -4
  8. package/Jenkinsfile +57 -57
  9. package/README.md +23 -23
  10. package/__tests__/unit/components/group/group.spec.ts +79 -79
  11. package/__tests__/unit/components/group-object-privilege/group-object-privilege.spec.ts +88 -88
  12. package/__tests__/unit/components/group-privilege/group-privilege.spec.ts +68 -68
  13. package/__tests__/unit/components/group-reporting-user/group-reporting-user.spec.ts +66 -66
  14. package/__tests__/unit/components/group-system-access/group-system-access.spec.ts +83 -83
  15. package/__tests__/unit/components/login-user/l.spec.ts +746 -746
  16. package/__tests__/unit/components/login-user/login.spec.ts +1164 -1164
  17. package/__tests__/unit/components/password-hash/password-hash.service.spec.ts +31 -31
  18. package/__tests__/unit/components/system/system.spec.ts +254 -254
  19. package/__tests__/unit/components/system-privilege/system-privilege.spec.ts +83 -83
  20. package/__tests__/unit/components/user-group/user-group.spec.ts +86 -86
  21. package/__tests__/unit/components/user-object-privilege/user-object-privilege.spec.ts +78 -78
  22. package/__tests__/unit/components/user-privilege/user-privilege.spec.ts +72 -72
  23. package/__tests__/unit/components/user-system-access/user-system-access.spec.ts +89 -89
  24. package/__tests__/unit/redis-client/redis.service.spec.ts +23 -23
  25. package/__tests__/unit/session/session.service.spec.ts +47 -47
  26. package/__tests__/unit/system-privilege/system-privilage.spec.ts +91 -91
  27. package/coverage/clover.xml +1452 -1452
  28. package/coverage/coverage-final.json +47 -47
  29. package/coverage/lcov-report/base.css +224 -224
  30. package/coverage/lcov-report/block-navigation.js +87 -87
  31. package/coverage/lcov-report/components/group/group.repository.ts.html +117 -117
  32. package/coverage/lcov-report/components/group/group.ts.html +327 -327
  33. package/coverage/lcov-report/components/group/index.html +130 -130
  34. package/coverage/lcov-report/components/group-object-privilege/group-object-privilege.repository.ts.html +117 -117
  35. package/coverage/lcov-report/components/group-object-privilege/group-object-privilege.ts.html +321 -321
  36. package/coverage/lcov-report/components/group-object-privilege/index.html +130 -130
  37. package/coverage/lcov-report/components/group-privilege/group-privilege.repository.ts.html +117 -117
  38. package/coverage/lcov-report/components/group-privilege/group-privilege.ts.html +303 -303
  39. package/coverage/lcov-report/components/group-privilege/index.html +130 -130
  40. package/coverage/lcov-report/components/group-reporting-user/group-reporting-user.repository.ts.html +117 -117
  41. package/coverage/lcov-report/components/group-reporting-user/group-reporting-user.ts.html +327 -327
  42. package/coverage/lcov-report/components/group-reporting-user/index.html +130 -130
  43. package/coverage/lcov-report/components/group-system-access/group-system-access.repository.ts.html +117 -117
  44. package/coverage/lcov-report/components/group-system-access/group-system-access.ts.html +309 -309
  45. package/coverage/lcov-report/components/group-system-access/index.html +130 -130
  46. package/coverage/lcov-report/components/login-history/index.html +115 -115
  47. package/coverage/lcov-report/components/login-history/login-history.repository.ts.html +117 -117
  48. package/coverage/lcov-report/components/login-user/index.html +130 -130
  49. package/coverage/lcov-report/components/login-user/login-user.ts.html +5007 -5007
  50. package/coverage/lcov-report/components/login-user/user.repository.ts.html +117 -117
  51. package/coverage/lcov-report/components/password-hash/index.html +115 -115
  52. package/coverage/lcov-report/components/password-hash/password-hash.service.ts.html +126 -126
  53. package/coverage/lcov-report/components/system/index.html +130 -130
  54. package/coverage/lcov-report/components/system/system.repository.ts.html +117 -117
  55. package/coverage/lcov-report/components/system/system.ts.html +909 -909
  56. package/coverage/lcov-report/components/system-privilege/index.html +130 -130
  57. package/coverage/lcov-report/components/system-privilege/system-privilege.repository.ts.html +120 -120
  58. package/coverage/lcov-report/components/system-privilege/system-privilege.ts.html +390 -390
  59. package/coverage/lcov-report/components/user-group/index.html +130 -130
  60. package/coverage/lcov-report/components/user-group/user-group.repository.ts.html +117 -117
  61. package/coverage/lcov-report/components/user-group/user-group.ts.html +354 -354
  62. package/coverage/lcov-report/components/user-object-privilege/index.html +130 -130
  63. package/coverage/lcov-report/components/user-object-privilege/user-object-privilege.repository.ts.html +117 -117
  64. package/coverage/lcov-report/components/user-object-privilege/user-object-privilege.ts.html +312 -312
  65. package/coverage/lcov-report/components/user-privilege/index.html +130 -130
  66. package/coverage/lcov-report/components/user-privilege/user-privilege.repository.ts.html +117 -117
  67. package/coverage/lcov-report/components/user-privilege/user-privilege.ts.html +306 -306
  68. package/coverage/lcov-report/components/user-system-access/index.html +130 -130
  69. package/coverage/lcov-report/components/user-system-access/user-system-access.repository.ts.html +117 -117
  70. package/coverage/lcov-report/components/user-system-access/user-system-access.ts.html +312 -312
  71. package/coverage/lcov-report/enum/group-type.enum.ts.html +108 -108
  72. package/coverage/lcov-report/enum/index.html +160 -160
  73. package/coverage/lcov-report/enum/index.ts.html +93 -93
  74. package/coverage/lcov-report/enum/user-status.enum.ts.html +105 -105
  75. package/coverage/lcov-report/enum/yn.enum.ts.html +96 -96
  76. package/coverage/lcov-report/index.html +370 -370
  77. package/coverage/lcov-report/models/group-object-privilege.entity.ts.html +333 -333
  78. package/coverage/lcov-report/models/group-privilege.entity.ts.html +315 -315
  79. package/coverage/lcov-report/models/group-reporting-user.entity.ts.html +339 -339
  80. package/coverage/lcov-report/models/group-system-access.entity.ts.html +324 -324
  81. package/coverage/lcov-report/models/group.entity.ts.html +435 -435
  82. package/coverage/lcov-report/models/index.html +310 -310
  83. package/coverage/lcov-report/models/login-history.entity.ts.html +252 -252
  84. package/coverage/lcov-report/models/staff.entity.ts.html +411 -411
  85. package/coverage/lcov-report/models/system-privilege.entity.ts.html +354 -354
  86. package/coverage/lcov-report/models/system.entity.ts.html +423 -423
  87. package/coverage/lcov-report/models/user-group.entity.ts.html +354 -354
  88. package/coverage/lcov-report/models/user-object-privilege.entity.ts.html +330 -330
  89. package/coverage/lcov-report/models/user-privilege.entity.ts.html +315 -315
  90. package/coverage/lcov-report/models/user-system-access.entity.ts.html +315 -315
  91. package/coverage/lcov-report/models/user.entity.ts.html +522 -522
  92. package/coverage/lcov-report/prettify.css +1 -1
  93. package/coverage/lcov-report/prettify.js +2 -2
  94. package/coverage/lcov-report/redis-client/index.html +115 -115
  95. package/coverage/lcov-report/redis-client/redis.service.ts.html +240 -240
  96. package/coverage/lcov-report/session/index.html +115 -115
  97. package/coverage/lcov-report/session/session.service.ts.html +246 -246
  98. package/coverage/lcov-report/sorter.js +196 -196
  99. package/coverage/lcov.info +2490 -2490
  100. package/coverage/test-report.xml +128 -128
  101. package/create-sso-user.sql +39 -39
  102. package/dist/__tests__/unit/components/group/group.spec.d.ts +1 -1
  103. package/dist/__tests__/unit/components/group/group.spec.js +71 -71
  104. package/dist/__tests__/unit/components/group-object-privilege/group-object-privilege.spec.d.ts +1 -1
  105. package/dist/__tests__/unit/components/group-object-privilege/group-object-privilege.spec.js +85 -85
  106. package/dist/__tests__/unit/components/group-privilege/group-privilege.spec.d.ts +1 -1
  107. package/dist/__tests__/unit/components/group-privilege/group-privilege.spec.js +70 -70
  108. package/dist/__tests__/unit/components/group-privilege/group-privilege.test.d.ts +1 -0
  109. package/dist/__tests__/unit/components/group-privilege/group-privilege.test.js +71 -0
  110. package/dist/__tests__/unit/components/group-privilege/group-privilege.test.js.map +1 -0
  111. package/dist/__tests__/unit/components/group-reporting-user/group-reporting-user.spec.d.ts +1 -1
  112. package/dist/__tests__/unit/components/group-reporting-user/group-reporting-user.spec.js +57 -57
  113. package/dist/__tests__/unit/components/group-system-access/group-system-access.spec.d.ts +1 -1
  114. package/dist/__tests__/unit/components/group-system-access/group-system-access.spec.js +82 -82
  115. package/dist/__tests__/unit/components/login-user/l.spec.js +5 -5
  116. package/dist/__tests__/unit/components/login-user/login-user.spec.d.ts +0 -0
  117. package/dist/__tests__/unit/components/login-user/login-user.spec.js +6 -0
  118. package/dist/__tests__/unit/components/login-user/login-user.spec.js.map +1 -0
  119. package/dist/__tests__/unit/components/login-user/login.spec.d.ts +1 -1
  120. package/dist/__tests__/unit/components/login-user/login.spec.js +2 -2
  121. package/dist/__tests__/unit/components/password-hash/password-hash.service.spec.d.ts +1 -1
  122. package/dist/__tests__/unit/components/password-hash/password-hash.service.spec.js +37 -37
  123. package/dist/__tests__/unit/components/system/system.spec.d.ts +1 -1
  124. package/dist/__tests__/unit/components/system/system.spec.js +203 -203
  125. package/dist/__tests__/unit/components/system-privilege/system-privilege.spec.d.ts +1 -1
  126. package/dist/__tests__/unit/components/system-privilege/system-privilege.spec.js +84 -84
  127. package/dist/__tests__/unit/components/user-group/user-group.spec.d.ts +1 -1
  128. package/dist/__tests__/unit/components/user-group/user-group.spec.js +81 -81
  129. package/dist/__tests__/unit/components/user-object-privilege/user-object-privilege.spec.d.ts +1 -1
  130. package/dist/__tests__/unit/components/user-object-privilege/user-object-privilege.spec.js +78 -78
  131. package/dist/__tests__/unit/components/user-privilege/user-privilege.spec.d.ts +1 -1
  132. package/dist/__tests__/unit/components/user-privilege/user-privilege.spec.js +75 -75
  133. package/dist/__tests__/unit/components/user-system-access/user-system-access.spec.d.ts +1 -1
  134. package/dist/__tests__/unit/components/user-system-access/user-system-access.spec.js +82 -82
  135. package/dist/__tests__/unit/components/user-system-access/user-system-access.spec.js.map +1 -1
  136. package/dist/__tests__/unit/redis-client/redis.service.spec.d.ts +1 -1
  137. package/dist/__tests__/unit/redis-client/redis.service.spec.js +31 -31
  138. package/dist/__tests__/unit/session/session.service.spec.d.ts +1 -1
  139. package/dist/__tests__/unit/session/session.service.spec.js +54 -54
  140. package/dist/__tests__/unit/system-privilege/system-privilage.spec.js +5 -5
  141. package/dist/index.d.ts +1 -1
  142. package/dist/index.js +17 -17
  143. package/dist/src/components/api-key/api-key.d.ts +84 -84
  144. package/dist/src/components/api-key/api-key.js +255 -255
  145. package/dist/src/components/api-key/api-key.js.map +1 -1
  146. package/dist/src/components/api-key/api-key.repository.d.ts +6 -6
  147. package/dist/src/components/api-key/api-key.repository.js +25 -25
  148. package/dist/src/components/api-key/index.d.ts +3 -3
  149. package/dist/src/components/api-key/index.js +7 -7
  150. package/dist/src/components/building/building.repository.d.ts +6 -6
  151. package/dist/src/components/building/building.repository.js +37 -37
  152. package/dist/src/components/building/building.repository.js.map +1 -1
  153. package/dist/src/components/building/index.d.ts +1 -1
  154. package/dist/src/components/building/index.js +17 -17
  155. package/dist/src/components/group/group.d.ts +112 -112
  156. package/dist/src/components/group/group.js +1240 -1240
  157. package/dist/src/components/group/group.js.map +1 -1
  158. package/dist/src/components/group/group.repository.d.ts +7 -7
  159. package/dist/src/components/group/group.repository.js +36 -36
  160. package/dist/src/components/group/group.repository.js.map +1 -1
  161. package/dist/src/components/group/index.d.ts +2 -2
  162. package/dist/src/components/group/index.js +18 -18
  163. package/dist/src/components/group-object-privilege/group-object-privilege.d.ts +27 -27
  164. package/dist/src/components/group-object-privilege/group-object-privilege.js +177 -177
  165. package/dist/src/components/group-object-privilege/group-object-privilege.js.map +1 -1
  166. package/dist/src/components/group-object-privilege/group-object-privilege.repository.d.ts +6 -6
  167. package/dist/src/components/group-object-privilege/group-object-privilege.repository.js +33 -33
  168. package/dist/src/components/group-object-privilege/group-object-privilege.repository.js.map +1 -1
  169. package/dist/src/components/group-object-privilege/index.d.ts +2 -2
  170. package/dist/src/components/group-object-privilege/index.js +18 -18
  171. package/dist/src/components/group-privilege/group-privilege.d.ts +24 -24
  172. package/dist/src/components/group-privilege/group-privilege.js +77 -77
  173. package/dist/src/components/group-privilege/group-privilege.js.map +1 -1
  174. package/dist/src/components/group-privilege/group-privilege.repository.d.ts +6 -6
  175. package/dist/src/components/group-privilege/group-privilege.repository.js +35 -35
  176. package/dist/src/components/group-privilege/group-privilege.repository.js.map +1 -1
  177. package/dist/src/components/group-privilege/index.d.ts +2 -2
  178. package/dist/src/components/group-privilege/index.js +18 -18
  179. package/dist/src/components/group-reporting-user/group-reporting-user.d.ts +28 -28
  180. package/dist/src/components/group-reporting-user/group-reporting-user.js +208 -208
  181. package/dist/src/components/group-reporting-user/group-reporting-user.js.map +1 -1
  182. package/dist/src/components/group-reporting-user/group-reporting-user.repository.d.ts +6 -6
  183. package/dist/src/components/group-reporting-user/group-reporting-user.repository.js +30 -30
  184. package/dist/src/components/group-reporting-user/index.d.ts +2 -2
  185. package/dist/src/components/group-reporting-user/index.js +18 -18
  186. package/dist/src/components/group-system-access/group-system-access.d.ts +27 -27
  187. package/dist/src/components/group-system-access/group-system-access.js +80 -80
  188. package/dist/src/components/group-system-access/group-system-access.js.map +1 -1
  189. package/dist/src/components/group-system-access/group-system-access.repository.d.ts +7 -7
  190. package/dist/src/components/group-system-access/group-system-access.repository.js +55 -54
  191. package/dist/src/components/group-system-access/group-system-access.repository.js.map +1 -1
  192. package/dist/src/components/group-system-access/index.d.ts +2 -2
  193. package/dist/src/components/group-system-access/index.js +18 -18
  194. package/dist/src/components/index.d.ts +17 -17
  195. package/dist/src/components/index.js +33 -33
  196. package/dist/src/components/login-history/index.d.ts +1 -1
  197. package/dist/src/components/login-history/index.js +17 -17
  198. package/dist/src/components/login-history/login-history.repository.d.ts +5 -5
  199. package/dist/src/components/login-history/login-history.repository.js +11 -11
  200. package/dist/src/components/login-user/index.d.ts +4 -4
  201. package/dist/src/components/login-user/index.js +20 -20
  202. package/dist/src/components/login-user/interfaces/check-user-info-duplicated.interface.d.ts +7 -7
  203. package/dist/src/components/login-user/interfaces/check-user-info-duplicated.interface.js +2 -2
  204. package/dist/src/components/login-user/interfaces/index.d.ts +1 -1
  205. package/dist/src/components/login-user/interfaces/index.js +17 -17
  206. package/dist/src/components/login-user/interfaces/system-access.interface.d.ts +13 -13
  207. package/dist/src/components/login-user/interfaces/system-access.interface.js +2 -2
  208. package/dist/src/components/login-user/interfaces/user-info.interface.d.ts +30 -30
  209. package/dist/src/components/login-user/interfaces/user-info.interface.js +2 -2
  210. package/dist/src/components/login-user/login-user.d.ts +13 -13
  211. package/dist/src/components/login-user/login-user.js +140 -140
  212. package/dist/src/components/login-user/login-user.js.map +1 -1
  213. package/dist/src/components/login-user/user.d.ts +143 -142
  214. package/dist/src/components/login-user/user.js +1791 -1767
  215. package/dist/src/components/login-user/user.js.map +1 -1
  216. package/dist/src/components/login-user/user.repository.d.ts +5 -5
  217. package/dist/src/components/login-user/user.repository.js +11 -11
  218. package/dist/src/components/password-hash/index.d.ts +2 -2
  219. package/dist/src/components/password-hash/index.js +18 -18
  220. package/dist/src/components/password-hash/interfaces/index.d.ts +1 -1
  221. package/dist/src/components/password-hash/interfaces/index.js +17 -17
  222. package/dist/src/components/password-hash/interfaces/password-hash-service.interface.d.ts +4 -4
  223. package/dist/src/components/password-hash/interfaces/password-hash-service.interface.js +2 -2
  224. package/dist/src/components/password-hash/password-hash.service.d.ts +6 -6
  225. package/dist/src/components/password-hash/password-hash.service.js +27 -27
  226. package/dist/src/components/staff/index.d.ts +1 -1
  227. package/dist/src/components/staff/index.js +17 -17
  228. package/dist/src/components/staff/staff.repository.d.ts +6 -6
  229. package/dist/src/components/staff/staff.repository.js +37 -37
  230. package/dist/src/components/staff/staff.repository.js.map +1 -1
  231. package/dist/src/components/system/index.d.ts +2 -2
  232. package/dist/src/components/system/index.js +18 -18
  233. package/dist/src/components/system/system.d.ts +39 -39
  234. package/dist/src/components/system/system.js +300 -300
  235. package/dist/src/components/system/system.js.map +1 -1
  236. package/dist/src/components/system/system.repository.d.ts +5 -5
  237. package/dist/src/components/system/system.repository.js +11 -11
  238. package/dist/src/components/system-privilege/index.d.ts +3 -3
  239. package/dist/src/components/system-privilege/index.js +7 -7
  240. package/dist/src/components/system-privilege/system-privilege.d.ts +52 -52
  241. package/dist/src/components/system-privilege/system-privilege.js +335 -335
  242. package/dist/src/components/system-privilege/system-privilege.js.map +1 -1
  243. package/dist/src/components/system-privilege/system-privilege.repository.d.ts +6 -6
  244. package/dist/src/components/system-privilege/system-privilege.repository.js +28 -28
  245. package/dist/src/components/user-group/index.d.ts +2 -2
  246. package/dist/src/components/user-group/index.js +18 -18
  247. package/dist/src/components/user-group/user-group.d.ts +50 -50
  248. package/dist/src/components/user-group/user-group.js +352 -352
  249. package/dist/src/components/user-group/user-group.js.map +1 -1
  250. package/dist/src/components/user-group/user-group.repository.d.ts +5 -5
  251. package/dist/src/components/user-group/user-group.repository.js +11 -11
  252. package/dist/src/components/user-object-privilege/index.d.ts +2 -2
  253. package/dist/src/components/user-object-privilege/index.js +18 -18
  254. package/dist/src/components/user-object-privilege/user-object-privilege.d.ts +23 -23
  255. package/dist/src/components/user-object-privilege/user-object-privilege.js +69 -69
  256. package/dist/src/components/user-object-privilege/user-object-privilege.js.map +1 -1
  257. package/dist/src/components/user-object-privilege/user-object-privilege.repository.d.ts +5 -5
  258. package/dist/src/components/user-object-privilege/user-object-privilege.repository.js +11 -11
  259. package/dist/src/components/user-privilege/index.d.ts +2 -2
  260. package/dist/src/components/user-privilege/index.js +18 -18
  261. package/dist/src/components/user-privilege/user-privilege.d.ts +64 -64
  262. package/dist/src/components/user-privilege/user-privilege.js +406 -406
  263. package/dist/src/components/user-privilege/user-privilege.js.map +1 -1
  264. package/dist/src/components/user-privilege/user-privilege.repository.d.ts +6 -6
  265. package/dist/src/components/user-privilege/user-privilege.repository.js +36 -36
  266. package/dist/src/components/user-privilege/user-privilege.repository.js.map +1 -1
  267. package/dist/src/components/user-system-access/index.d.ts +2 -2
  268. package/dist/src/components/user-system-access/index.js +18 -18
  269. package/dist/src/components/user-system-access/user-system-access.d.ts +56 -56
  270. package/dist/src/components/user-system-access/user-system-access.js +277 -277
  271. package/dist/src/components/user-system-access/user-system-access.js.map +1 -1
  272. package/dist/src/components/user-system-access/user-system-access.repository.d.ts +6 -6
  273. package/dist/src/components/user-system-access/user-system-access.repository.js +36 -36
  274. package/dist/src/components/user-system-access/user-system-access.repository.js.map +1 -1
  275. package/dist/src/database.d.ts +4 -4
  276. package/dist/src/database.js +13 -14
  277. package/dist/src/database.js.map +1 -1
  278. package/dist/src/enum/api-key.enum.d.ts +5 -5
  279. package/dist/src/enum/api-key.enum.js +9 -9
  280. package/dist/src/enum/api-key.enum.js.map +1 -1
  281. package/dist/src/enum/group-type.enum.d.ts +8 -8
  282. package/dist/src/enum/group-type.enum.js +12 -12
  283. package/dist/src/enum/group-type.enum.js.map +1 -1
  284. package/dist/src/enum/index.d.ts +6 -6
  285. package/dist/src/enum/index.js +22 -22
  286. package/dist/src/enum/login-status.enum.d.ts +4 -4
  287. package/dist/src/enum/login-status.enum.js +8 -8
  288. package/dist/src/enum/login-status.enum.js.map +1 -1
  289. package/dist/src/enum/object-status.enum.d.ts +4 -4
  290. package/dist/src/enum/object-status.enum.js +8 -8
  291. package/dist/src/enum/object-status.enum.js.map +1 -1
  292. package/dist/src/enum/user-status.enum.d.ts +7 -7
  293. package/dist/src/enum/user-status.enum.js +11 -11
  294. package/dist/src/enum/user-status.enum.js.map +1 -1
  295. package/dist/src/enum/yn.enum.d.ts +4 -4
  296. package/dist/src/enum/yn.enum.js +8 -8
  297. package/dist/src/enum/yn.enum.js.map +1 -1
  298. package/dist/src/index.d.ts +6 -6
  299. package/dist/src/index.js +24 -24
  300. package/dist/src/interfaces/api-key-attr.interface.d.ts +15 -15
  301. package/dist/src/interfaces/api-key-attr.interface.js +2 -2
  302. package/dist/src/interfaces/group-object-privilege.interface.d.ts +13 -13
  303. package/dist/src/interfaces/group-object-privilege.interface.js +2 -2
  304. package/dist/src/interfaces/group-privilege.interface.d.ts +10 -10
  305. package/dist/src/interfaces/group-privilege.interface.js +2 -2
  306. package/dist/src/interfaces/group-reporting-user.interface.d.ts +11 -11
  307. package/dist/src/interfaces/group-reporting-user.interface.js +2 -2
  308. package/dist/src/interfaces/group-search-attr.interface.d.ts +8 -8
  309. package/dist/src/interfaces/group-search-attr.interface.js +2 -2
  310. package/dist/src/interfaces/group-system-access.interface.d.ts +10 -10
  311. package/dist/src/interfaces/group-system-access.interface.js +2 -2
  312. package/dist/src/interfaces/group.interface.d.ts +16 -16
  313. package/dist/src/interfaces/group.interface.js +2 -2
  314. package/dist/src/interfaces/index.d.ts +13 -13
  315. package/dist/src/interfaces/index.js +29 -29
  316. package/dist/src/interfaces/system-login.interface.d.ts +6 -6
  317. package/dist/src/interfaces/system-login.interface.js +2 -2
  318. package/dist/src/interfaces/system-privilege-search.interface.d.ts +5 -5
  319. package/dist/src/interfaces/system-privilege-search.interface.js +2 -2
  320. package/dist/src/interfaces/system-privilege.interface.d.ts +11 -11
  321. package/dist/src/interfaces/system-privilege.interface.js +2 -2
  322. package/dist/src/interfaces/system-search-attr.interface.d.ts +5 -5
  323. package/dist/src/interfaces/system-search-attr.interface.js +2 -2
  324. package/dist/src/interfaces/system.interface.d.ts +15 -15
  325. package/dist/src/interfaces/system.interface.js +2 -2
  326. package/dist/src/interfaces/user-group.interface.d.ts +12 -12
  327. package/dist/src/interfaces/user-group.interface.js +2 -2
  328. package/dist/src/interfaces/user-object-privilege.interface.d.ts +13 -13
  329. package/dist/src/interfaces/user-object-privilege.interface.js +2 -2
  330. package/dist/src/interfaces/user-privilege.interface.d.ts +10 -10
  331. package/dist/src/interfaces/user-privilege.interface.js +2 -2
  332. package/dist/src/interfaces/user-session.interface.d.ts +4 -4
  333. package/dist/src/interfaces/user-session.interface.js +2 -2
  334. package/dist/src/interfaces/user-system-access.interface.d.ts +10 -10
  335. package/dist/src/interfaces/user-system-access.interface.js +2 -2
  336. package/dist/src/models/api-key-entity.d.ts +21 -21
  337. package/dist/src/models/api-key-entity.js +121 -121
  338. package/dist/src/models/api-key-entity.js.map +1 -1
  339. package/dist/src/models/building.entity.d.ts +29 -29
  340. package/dist/src/models/building.entity.js +212 -212
  341. package/dist/src/models/building.entity.js.map +1 -1
  342. package/dist/src/models/group-object-privilege.entity.d.ts +21 -21
  343. package/dist/src/models/group-object-privilege.entity.js +110 -110
  344. package/dist/src/models/group-object-privilege.entity.js.map +1 -1
  345. package/dist/src/models/group-privilege.entity.d.ts +18 -18
  346. package/dist/src/models/group-privilege.entity.js +95 -95
  347. package/dist/src/models/group-privilege.entity.js.map +1 -1
  348. package/dist/src/models/group-reporting-user.entity.d.ts +17 -17
  349. package/dist/src/models/group-reporting-user.entity.js +113 -113
  350. package/dist/src/models/group-reporting-user.entity.js.map +1 -1
  351. package/dist/src/models/group-system-access.entity.d.ts +18 -18
  352. package/dist/src/models/group-system-access.entity.js +98 -98
  353. package/dist/src/models/group-system-access.entity.js.map +1 -1
  354. package/dist/src/models/group.entity.d.ts +32 -32
  355. package/dist/src/models/group.entity.js +153 -154
  356. package/dist/src/models/group.entity.js.map +1 -1
  357. package/dist/src/models/login-history.entity.d.ts +14 -14
  358. package/dist/src/models/login-history.entity.js +77 -77
  359. package/dist/src/models/login-history.entity.js.map +1 -1
  360. package/dist/src/models/staff.entity.d.ts +18 -18
  361. package/dist/src/models/staff.entity.js +109 -109
  362. package/dist/src/models/staff.entity.js.map +1 -1
  363. package/dist/src/models/system-privilege.entity.d.ts +18 -18
  364. package/dist/src/models/system-privilege.entity.js +107 -107
  365. package/dist/src/models/system-privilege.entity.js.map +1 -1
  366. package/dist/src/models/system.entity.d.ts +25 -25
  367. package/dist/src/models/system.entity.js +135 -135
  368. package/dist/src/models/system.entity.js.map +1 -1
  369. package/dist/src/models/user-group.entity.d.ts +19 -19
  370. package/dist/src/models/user-group.entity.js +110 -110
  371. package/dist/src/models/user-group.entity.js.map +1 -1
  372. package/dist/src/models/user-object-privilege.entity.d.ts +20 -20
  373. package/dist/src/models/user-object-privilege.entity.js +109 -109
  374. package/dist/src/models/user-object-privilege.entity.js.map +1 -1
  375. package/dist/src/models/user-privilege.entity.d.ts +17 -17
  376. package/dist/src/models/user-privilege.entity.js +95 -95
  377. package/dist/src/models/user-privilege.entity.js.map +1 -1
  378. package/dist/src/models/user-system-access.entity.d.ts +17 -17
  379. package/dist/src/models/user-system-access.entity.js +104 -104
  380. package/dist/src/models/user-system-access.entity.js.map +1 -1
  381. package/dist/src/models/user.entity.d.ts +40 -40
  382. package/dist/src/models/user.entity.js +214 -215
  383. package/dist/src/models/user.entity.js.map +1 -1
  384. package/dist/src/redis-client/__mocks__/jest-initial-setup.d.ts +1 -1
  385. package/dist/src/redis-client/__mocks__/jest-initial-setup.js +4 -4
  386. package/dist/src/redis-client/__mocks__/redis-mock.d.ts +2 -2
  387. package/dist/src/redis-client/__mocks__/redis-mock.js +22 -22
  388. package/dist/src/redis-client/index.d.ts +1 -1
  389. package/dist/src/redis-client/index.js +17 -17
  390. package/dist/src/redis-client/redis.service.d.ts +9 -9
  391. package/dist/src/redis-client/redis.service.js +87 -87
  392. package/dist/src/redis-client/redis.service.js.map +1 -1
  393. package/dist/src/session/index.d.ts +2 -2
  394. package/dist/src/session/index.js +18 -18
  395. package/dist/src/session/interfaces/index.d.ts +1 -1
  396. package/dist/src/session/interfaces/index.js +17 -17
  397. package/dist/src/session/interfaces/session-service.interface.d.ts +9 -9
  398. package/dist/src/session/interfaces/session-service.interface.js +2 -2
  399. package/dist/src/session/session.service.d.ts +13 -13
  400. package/dist/src/session/session.service.js +95 -95
  401. package/dist/src/session/session.service.js.map +1 -1
  402. package/dist/tsconfig.tsbuildinfo +1 -1
  403. package/jest.config.js +14 -14
  404. package/migrations/20240314080602-create-user-table.js +124 -124
  405. package/migrations/20240314080603-create-user-group-table.js +85 -85
  406. package/migrations/20240314080604-create-user-user-group-table.js +55 -55
  407. package/migrations/20240314080605-create-login-history-table.js +53 -53
  408. package/migrations/20240527064925-create-system-table.js +78 -78
  409. package/migrations/20240527064926-create-system-privilege-table.js +71 -71
  410. package/migrations/20240527065342-create-group-table.js +93 -93
  411. package/migrations/20240527065633-create-group-reporting-user-table.js +76 -76
  412. package/migrations/20240528011551-create-group-system-access-table.js +72 -72
  413. package/migrations/20240528023018-user-system-access-table.js +75 -75
  414. package/migrations/20240528032229-user-privilege-table.js +76 -76
  415. package/migrations/20240528063003-create-group-privilege-table.js +76 -76
  416. package/migrations/20240528063051-create-group-object-privilege-table.js +84 -84
  417. package/migrations/20240528063107-create-user-object-privilege-table.js +84 -84
  418. package/migrations/20240528063108-create-api-key-table.js +85 -85
  419. package/migrations/20241104104802-create-building-table.js +95 -95
  420. package/package.json +88 -89
  421. package/sampledotenv +7 -7
  422. package/sonar-project.properties +22 -22
  423. package/src/components/group/group.ts +2 -3
  424. package/src/components/group-system-access/group-system-access.repository.ts +2 -3
  425. package/src/components/login-user/login-user.ts +2 -3
  426. package/src/components/login-user/user.ts +44 -6
  427. package/src/components/system-privilege/system-privilege.ts +2 -3
  428. package/src/components/user-privilege/user-privilege.ts +2 -3
  429. package/src/components/user-system-access/user-system-access.ts +2 -3
  430. package/tsconfig.build.json +5 -5
  431. package/tsconfig.json +22 -22
@@ -1,1164 +1,1164 @@
1
- import { SessionService } from '../../../../src/session/session.service';
2
- import { LoginUser } from '../../../../src/components/login-user/login-user';
3
- import { ApplicationConfig, ComponentConfig } from '@tomei/config';
4
- import { UserRepository } from '../../../../src/components/login-user/user.repository';
5
- import { ClassError } from '@tomei/general';
6
- import { Activity } from '@tomei/activity-history';
7
- import { UserStatus } from '../../../../src/enum/user-status.enum';
8
- import { YN } from '../../../../src/enum/yn.enum';
9
- import SystemPrivilegeModel from '../../../../src/models/system-privilege.entity';
10
- import { GroupSystemAccessRepository } from '../../../../src/components/group-system-access/group-system-access.repository';
11
- import { GroupRepository } from '../../../../src/components/group/group.repository';
12
-
13
- // describe('LoginUser', () => {
14
- // afterAll(() => {
15
- // jest.restoreAllMocks();
16
- // });
17
-
18
- // describe('init', () => {
19
- // let sessionService: any;
20
- // let userId: number;
21
- // let dbTransaction: any;
22
-
23
- // beforeEach(() => {
24
- // sessionService = {};
25
- // userId = 1;
26
- // dbTransaction = null;
27
- // });
28
-
29
- // it('should initialize LoginUser with valid userId', async () => {
30
- // const user = {
31
- // UserId: 1,
32
- // FullName: 'John Doe',
33
- // Email: 'john.doe@example.com',
34
- // Password: 'password',
35
- // Status: 'active',
36
- // DefaultPasswordChangedYN: 'yes',
37
- // FirstLoginAt: new Date(),
38
- // LastLoginAt: new Date(),
39
- // MFAEnabled: 1,
40
- // MFAConfig: 'config',
41
- // RecoveryEmail: 'john.doe@example.com',
42
- // FailedLoginAttemptCount: 0,
43
- // LastFailedLoginAt: null,
44
- // LastPasswordChangedAt: new Date(),
45
- // NeedToChangePasswordYN: 'no',
46
- // CreatedById: 1,
47
- // CreatedAt: new Date(),
48
- // UpdatedById: 1,
49
- // UpdatedAt: new Date(),
50
- // Staff: {
51
- // FullName: 'John Doe',
52
- // IdNo: '1234567890',
53
- // Mobile: '1234567890',
54
- // },
55
- // };
56
-
57
- // const findOneMock = jest
58
- // .spyOn(UserRepository.prototype, 'findOne')
59
- // .mockResolvedValueOnce(user as any);
60
-
61
- // const result = await LoginUser.init(
62
- // sessionService,
63
- // userId,
64
- // dbTransaction,
65
- // );
66
-
67
- // expect(findOneMock).toHaveBeenCalledTimes(1);
68
- // expect(findOneMock).toHaveBeenCalledWith({
69
- // where: {
70
- // UserId: userId,
71
- // },
72
- // include: [
73
- // {
74
- // model: expect.anything(),
75
- // },
76
- // ],
77
- // });
78
- // expect(result).toBeInstanceOf(LoginUser);
79
- // expect(result.UserId).toBe(user.UserId);
80
- // expect(result.FullName).toBe(user.FullName);
81
- // expect(result.Email).toBe(user.Email);
82
- // expect(result.Password).toBe(user.Password);
83
- // expect(result.Status).toBe(user.Status);
84
- // expect(result.DefaultPasswordChangedYN).toBe(
85
- // user.DefaultPasswordChangedYN,
86
- // );
87
- // expect(result.FirstLoginAt).toBe(user.FirstLoginAt);
88
- // expect(result.LastLoginAt).toBe(user.LastLoginAt);
89
- // expect(result.MFAEnabled).toBe(user.MFAEnabled);
90
- // expect(result.MFAConfig).toBe(user.MFAConfig);
91
- // expect(result.RecoveryEmail).toBe(user.RecoveryEmail);
92
- // expect(result.FailedLoginAttemptCount).toBe(user.FailedLoginAttemptCount);
93
- // expect(result.LastFailedLoginAt).toBe(user.LastFailedLoginAt);
94
- // expect(result.LastPasswordChangedAt).toBe(user.LastPasswordChangedAt);
95
- // expect(result.NeedToChangePasswordYN).toBe(user.NeedToChangePasswordYN);
96
- // expect(result.CreatedById).toBe(user.CreatedById);
97
- // expect(result.CreatedAt).toBe(user.CreatedAt);
98
- // expect(result.UpdatedById).toBe(user.UpdatedById);
99
- // expect(result.UpdatedAt).toBe(user.UpdatedAt);
100
- // });
101
-
102
- // it('should throw an error when user is not found', async () => {
103
- // const findOneMock = jest
104
- // .spyOn(UserRepository.prototype, 'findOne')
105
- // .mockResolvedValueOnce(null);
106
-
107
- // await expect(
108
- // LoginUser.init(sessionService, userId, dbTransaction),
109
- // ).rejects.toThrow(Error);
110
-
111
- // expect(findOneMock).toHaveBeenCalledTimes(1);
112
- // expect(findOneMock).toHaveBeenCalledWith({
113
- // where: {
114
- // UserId: userId,
115
- // },
116
- // include: [
117
- // {
118
- // model: expect.anything(),
119
- // },
120
- // ],
121
- // });
122
- // });
123
- // });
124
-
125
- // // describe('checkSession', () => {
126
- // // it('should throw an error if session expired', async () => {
127
- // // // Arrange
128
- // // const systemCode = 'EZC';
129
- // // const sessionId = 'ckymxuh8t000137t011w89zgk';
130
- // // const userId = '755';
131
- // // const sessionService = await SessionService.init();
132
- // // const loginUser = await LoginUser.init(sessionService);
133
-
134
- // // // Act
135
- // // const checkSessionPromise = loginUser.checkSession(
136
- // // systemCode,
137
- // // sessionId,
138
- // // userId,
139
- // // );
140
-
141
- // // // Assert
142
- // // await expect(checkSessionPromise).rejects.toThrow('Session expired.');
143
- // // });
144
-
145
- // // it('should refresh the session duration if session is valid', async () => {
146
- // // // Arrange
147
- // // const systemCode = 'EZC';
148
- // // const sessionId = 'ckymxuh8t000137t011w89zgk';
149
- // // const userId = '755';
150
- // // const sessionService = await SessionService.init();
151
- // // const loginUser = await LoginUser.init(sessionService);
152
-
153
- // // // Mock the _SessionService.retrieveUserSession method
154
- // // loginUser['_SessionService'].retrieveUserSession = jest
155
- // // .fn()
156
- // // .mockResolvedValue({
157
- // // systemLogins: [
158
- // // {
159
- // // code: systemCode,
160
- // // sessionId: sessionId,
161
- // // privileges: [],
162
- // // },
163
- // // ],
164
- // // });
165
-
166
- // // // Mock the _SessionService.refreshDuration method
167
- // // loginUser['_SessionService'].refreshDuration = jest.fn();
168
-
169
- // // // Act
170
- // // const systemLogin = await loginUser.checkSession(
171
- // // systemCode,
172
- // // sessionId,
173
- // // userId,
174
- // // );
175
-
176
- // // // Assert
177
- // // expect(
178
- // // loginUser['_SessionService'].retrieveUserSession,
179
- // // ).toHaveBeenCalledWith(userId);
180
- // // expect(loginUser['_SessionService'].refreshDuration).toHaveBeenCalledWith(
181
- // // userId,
182
- // // );
183
- // // expect(systemLogin).toEqual({
184
- // // code: systemCode,
185
- // // sessionId: sessionId,
186
- // // privileges: [],
187
- // // });
188
- // // });
189
- // // });
190
-
191
- // describe('shouldReleaseLock', () => {
192
- // const minuteToAutoRelease = 5;
193
- // const autoReleaseYN = 'Y';
194
-
195
- // beforeEach(() => {
196
- // jest
197
- // .spyOn(ComponentConfig, 'getComponentConfigValue')
198
- // .mockImplementation((componentName: string, configKey: string) => {
199
- // if (configKey === 'minuteToAutoRelease') {
200
- // return minuteToAutoRelease as any;
201
- // }
202
- // if (configKey === 'autoReleaseYN') {
203
- // return autoReleaseYN as any;
204
- // }
205
- // });
206
- // });
207
-
208
- // it('should return true if autoReleaseYN is "Y" and time difference is greater than minuteToAutoRelease', async () => {
209
- // // Arrange
210
- // const lastFailedLoginAt = new Date();
211
- // lastFailedLoginAt.setMinutes(lastFailedLoginAt.getMinutes() - 10); // Set last failed login time to 10 minutes ago
212
- // // Act
213
- // const result = LoginUser.shouldReleaseLock(lastFailedLoginAt);
214
-
215
- // // Assert
216
- // expect(result).toBe(true);
217
- // });
218
-
219
- // it('should return false if autoReleaseYN is "Y" and time difference is less than or equal to minuteToAutoRelease', async () => {
220
- // // Arrange
221
- // const lastFailedLoginAt = new Date();
222
- // lastFailedLoginAt.setMinutes(lastFailedLoginAt.getMinutes() - 3); // Set last failed login time to 3 minutes ago
223
-
224
- // // Act
225
- // const result = LoginUser.shouldReleaseLock(lastFailedLoginAt);
226
-
227
- // // Assert
228
- // expect(result).toBe(false);
229
- // });
230
-
231
- // it('should return false if autoReleaseYN is "N"', async () => {
232
- // // Arrange
233
- // const lastFailedLoginAt = new Date();
234
-
235
- // // Act
236
- // const result = LoginUser.shouldReleaseLock(lastFailedLoginAt);
237
-
238
- // // Assert
239
- // expect(result).toBe(false);
240
- // });
241
- // });
242
-
243
- // describe('releaseLock', () => {
244
- // it('should release the lock for a user', async () => {
245
- // // Mock the necessary dependencies and setup the test data
246
- // const UserId = 1;
247
- // const dbTransaction = null;
248
-
249
- // const updateMock = jest
250
- // .spyOn(LoginUser['_Repository'], 'update')
251
- // .mockImplementationOnce(() => Promise.resolve({}) as any);
252
-
253
- // // Call the method under test
254
- // LoginUser['releaseLock'](UserId, dbTransaction);
255
-
256
- // // Verify the expected behavior
257
- // expect(updateMock).toHaveBeenCalledTimes(1);
258
- // expect(updateMock).toHaveBeenCalledWith(
259
- // {
260
- // FailedLoginAttemptCount: 0,
261
- // Status: 'Active',
262
- // },
263
- // {
264
- // where: {
265
- // UserId,
266
- // },
267
- // transaction: dbTransaction,
268
- // },
269
- // );
270
- // });
271
- // });
272
-
273
- // describe('checkUserInfoDuplicated', () => {
274
- // it('should throw an error if duplicate user info is found', async () => {
275
- // // Mock the dependencies and setup the test data
276
- // const dbTransaction = null;
277
- // const query = {
278
- // Email: 'test@example.com',
279
- // IdType: 'passport',
280
- // IdNo: '123456789',
281
- // ContactNo: '1234567890',
282
- // };
283
-
284
- // // Mock the LoginUser['_Repository'].findAll method to return a user
285
- // jest
286
- // .spyOn(LoginUser['_Repository'], 'findAll')
287
- // .mockResolvedValueOnce([{ id: 1 }] as any);
288
-
289
- // // Assert that the method throws an error
290
- // await expect(
291
- // LoginUser['checkUserInfoDuplicated'](dbTransaction, query),
292
- // ).rejects.toThrowError();
293
- // });
294
-
295
- // it('should not throw an error if duplicate user info is not found', async () => {
296
- // // Mock the dependencies and setup the test data
297
- // const dbTransaction = null;
298
- // const query = {
299
- // Email: 'test@example.com',
300
- // IdType: 'passport',
301
- // IdNo: '123456789',
302
- // ContactNo: '1234567890',
303
- // };
304
-
305
- // // Mock the LoginUser['_Repository'].findAll method to return an empty array
306
- // jest.spyOn(LoginUser['_Repository'], 'findAll').mockResolvedValueOnce([]);
307
-
308
- // // Assert that the method does not throw an error
309
- // await expect(
310
- // LoginUser['checkUserInfoDuplicated'](dbTransaction, query),
311
- // ).resolves.not.toThrowError();
312
- // });
313
- // });
314
-
315
- // describe('generateDefaultPassword', () => {
316
- // const passwordPolicy = {
317
- // minLen: 6,
318
- // maxLen: 10,
319
- // nonAcceptableChar: 'i,l,o',
320
- // numOfCapitalLetters: 1,
321
- // numOfNumbers: 1,
322
- // numOfSpecialChars: 1,
323
- // };
324
- // beforeEach(() => {
325
- // jest
326
- // .spyOn(ComponentConfig, 'getComponentConfigValue')
327
- // .mockImplementation((componentName: string, configKey: string) => {
328
- // if (configKey === 'passwordPolicy') {
329
- // return passwordPolicy as any;
330
- // }
331
- // });
332
- // });
333
-
334
- // it('should generate a default password with the specified length', () => {
335
- // const password = LoginUser['generateDefaultPassword']();
336
- // expect(password.length).toBeGreaterThanOrEqual(6);
337
- // expect(password.length).toBeLessThanOrEqual(10);
338
- // });
339
-
340
- // it('should generate a default password with at least one capital letter', () => {
341
- // const password = LoginUser['generateDefaultPassword']();
342
- // expect(/[A-Z]/.test(password)).toBe(true);
343
- // });
344
-
345
- // it('should generate a default password with at least one number', () => {
346
- // const password = LoginUser['generateDefaultPassword']();
347
- // expect(/[0-9]/.test(password)).toBe(true);
348
- // });
349
-
350
- // it('should generate a default password with at least one special character', () => {
351
- // const password = LoginUser['generateDefaultPassword']();
352
- // expect(/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?~`]/.test(password)).toBe(true);
353
- // });
354
-
355
- // it('should generate a default password without any non-acceptable characters', () => {
356
- // const password = LoginUser['generateDefaultPassword']();
357
- // const nonAcceptableChars = ['i', 'l', 'o'];
358
- // expect(nonAcceptableChars.some((char) => password.includes(char))).toBe(
359
- // false,
360
- // );
361
- // });
362
- // });
363
-
364
- // describe('setPassword', () => {
365
- // const passwordPolicy = {
366
- // minLen: 6,
367
- // maxLen: 10,
368
- // nonAcceptableChar: 'i,l,o',
369
- // numOfCapitalLetters: 1,
370
- // numOfNumbers: 1,
371
- // numOfSpecialChars: 1,
372
- // };
373
- // beforeEach(() => {
374
- // jest
375
- // .spyOn(ComponentConfig, 'getComponentConfigValue')
376
- // .mockImplementation((componentName: string, configKey: string) => {
377
- // if (configKey === 'passwordPolicy') {
378
- // return passwordPolicy as any;
379
- // }
380
- // });
381
- // });
382
-
383
- // it('should set the password for the user', async () => {
384
- // // Arrange
385
- // const dbTransaction = null;
386
- // const sessionService = await SessionService.init();
387
- // const user = await LoginUser.init(sessionService);
388
- // const password = 'N3wP@ssw0';
389
-
390
- // // Act
391
- // const result = await LoginUser['setPassword'](
392
- // dbTransaction,
393
- // user,
394
- // password,
395
- // );
396
-
397
- // // Assert
398
- // expect(result).toBeInstanceOf(LoginUser);
399
- // await expect(
400
- // LoginUser['setPassword'](dbTransaction, user, password),
401
- // ).resolves.not.toThrowError();
402
- // expect(result.Password).toBeDefined();
403
- // });
404
-
405
- // it('should throw an error if the password does not meet the security requirements', async () => {
406
- // // Arrange
407
- // const dbTransaction = null;
408
- // const sessionService = await SessionService.init();
409
- // const user = await LoginUser.init(sessionService);
410
- // const password = 'weakpassword';
411
-
412
- // // Act & Assert
413
- // await expect(
414
- // LoginUser['setPassword'](dbTransaction, user, password),
415
- // ).rejects.toThrow();
416
- // });
417
- // });
418
-
419
- // // describe('create', () => {
420
- // // let loginUser: LoginUser;
421
- // // let dbTransaction: any;
422
- // // let user: LoginUser;
423
- // // let newUser: any;
424
-
425
- // // beforeEach(async () => {
426
- // // const sessionService = await SessionService.init();
427
- // // loginUser = await LoginUser.init(sessionService);
428
- // // dbTransaction = null;
429
- // // newUser = {
430
- // // UserId: 1,
431
- // // FullName: 'John Doe',
432
- // // Email: 'john.doe@example.com',
433
- // // Password: 'password',
434
- // // Status: 'Active',
435
- // // DefaultPasswordChangedYN: 'N',
436
- // // FirstLoginAt: null,
437
- // // LastLoginAt: null,
438
- // // MFAEnabled: null,
439
- // // MFAConfig: null,
440
- // // RecoveryEmail: null,
441
- // // FailedLoginAttemptCount: 0,
442
- // // LastFailedLoginAt: null,
443
- // // LastPasswordChangedAt: new Date(),
444
- // // NeedToChangePasswordYN: 'N',
445
- // // CreatedById: 1,
446
- // // CreatedAt: new Date(),
447
- // // UpdatedById: 1,
448
- // // UpdatedAt: new Date(),
449
- // // Staff: {
450
- // // FullName: 'John Doe',
451
- // // IdNo: '1234567890',
452
- // // Mobile: '1234567890',
453
- // // },
454
- // // };
455
- // // user = new (LoginUser as any)(sessionService, null, newUser);
456
- // // });
457
-
458
- // // afterEach(() => {
459
- // // jest.clearAllMocks();
460
- // // });
461
-
462
- // // it('should create a new user record', async () => {
463
- // // const checkPrivilegesMock = jest
464
- // // .spyOn(loginUser, 'checkPrivileges')
465
- // // .mockResolvedValueOnce(true);
466
-
467
- // // const checkUserInfoDuplicatedMock = jest
468
- // // .spyOn(LoginUser as any, 'checkUserInfoDuplicated')
469
- // // .mockResolvedValueOnce(undefined);
470
-
471
- // // const generateDefaultPasswordMock = jest
472
- // // .spyOn(LoginUser as any, 'generateDefaultPassword')
473
- // // .mockReturnValueOnce('defaultPassword');
474
-
475
- // // const setPasswordMock = jest
476
- // // .spyOn(LoginUser as any, 'setPassword')
477
- // // .mockResolvedValueOnce(user);
478
-
479
- // // const createMock = jest
480
- // // .spyOn((LoginUser as any)['_Repository'], 'create')
481
- // // .mockResolvedValueOnce({
482
- // // ...newUser,
483
- // // get: () => newUser,
484
- // // });
485
-
486
- // // const activityCreateMock = jest
487
- // // .spyOn((Activity as any).prototype, 'create')
488
- // // .mockResolvedValueOnce(undefined);
489
-
490
- // // jest
491
- // // .spyOn(ApplicationConfig, 'getComponentConfigValue')
492
- // // .mockImplementation((configKey: string) => {
493
- // // if (configKey === 'system-code') {
494
- // // return 'SC';
495
- // // }
496
- // // });
497
-
498
- // // const result = await LoginUser.create(loginUser, dbTransaction, user);
499
-
500
- // // expect(checkPrivilegesMock).toHaveBeenCalledTimes(1);
501
- // // expect(checkPrivilegesMock).toHaveBeenCalledWith(
502
- // // ApplicationConfig.getComponentConfigValue('system-code'),
503
- // // 'User - Create',
504
- // // );
505
-
506
- // // expect(checkUserInfoDuplicatedMock).toHaveBeenCalledTimes(1);
507
- // // expect(checkUserInfoDuplicatedMock).toHaveBeenCalledWith(dbTransaction, {
508
- // // Email: user.Email,
509
- // // IdType: user.IDType,
510
- // // IdNo: user.IDNo,
511
- // // ContactNo: user.ContactNo,
512
- // // });
513
-
514
- // // expect(generateDefaultPasswordMock).toHaveBeenCalledTimes(1);
515
-
516
- // // expect(setPasswordMock).toHaveBeenCalledTimes(1);
517
- // // expect(setPasswordMock).toHaveBeenCalledWith(
518
- // // dbTransaction,
519
- // // user,
520
- // // 'defaultPassword',
521
- // // );
522
-
523
- // // expect(createMock).toHaveBeenCalledTimes(1);
524
-
525
- // // const userInfo = {
526
- // // FullName: user.FullName,
527
- // // IDNo: user.IDNo,
528
- // // Email: user.Email,
529
- // // ContactNo: user.ContactNo,
530
- // // Password: user.Password,
531
- // // Status: UserStatus.ACTIVE,
532
- // // FirstLoginAt: null,
533
- // // LastLoginAt: null,
534
- // // MFAEnabled: null,
535
- // // MFAConfig: null,
536
- // // RecoveryEmail: null,
537
- // // FailedLoginAttemptCount: 0,
538
- // // LastFailedLoginAt: null,
539
- // // LastPasswordChangedAt: null,
540
- // // DefaultPasswordChangedYN: YN.No,
541
- // // NeedToChangePasswordYN: YN.Yes,
542
- // // CreatedById: loginUser.UserId,
543
- // // CreatedAt: new Date(),
544
- // // UpdatedById: loginUser.UserId,
545
- // // UpdatedAt: new Date(),
546
- // // UserId: null,
547
- // // };
548
-
549
- // // expect(createMock).toHaveBeenCalledWith(
550
- // // {
551
- // // Email: userInfo.Email,
552
- // // Password: userInfo.Password,
553
- // // Status: userInfo.Status,
554
- // // DefaultPasswordChangedYN: userInfo.DefaultPasswordChangedYN,
555
- // // FirstLoginAt: userInfo.FirstLoginAt,
556
- // // LastLoginAt: userInfo.LastLoginAt,
557
- // // MFAEnabled: userInfo.MFAEnabled,
558
- // // MFAConfig: userInfo.MFAConfig,
559
- // // RecoveryEmail: userInfo.RecoveryEmail,
560
- // // FailedLoginAttemptCount: userInfo.FailedLoginAttemptCount,
561
- // // LastFailedLoginAt: userInfo.LastFailedLoginAt,
562
- // // LastPasswordChangedAt: userInfo.LastPasswordChangedAt,
563
- // // NeedToChangePasswordYN: userInfo.NeedToChangePasswordYN,
564
- // // CreatedById: userInfo.CreatedById,
565
- // // CreatedAt: expect.any(Date),
566
- // // UpdatedById: userInfo.UpdatedById,
567
- // // UpdatedAt: expect.any(Date),
568
- // // },
569
- // // {
570
- // // transaction: dbTransaction,
571
- // // },
572
- // // );
573
-
574
- // // expect(activityCreateMock).toHaveBeenCalledTimes(1);
575
-
576
- // // expect(result).toBeInstanceOf(LoginUser);
577
- // // expect(result.Email).toBe(userInfo.Email);
578
- // // expect(result.Password).toBe(userInfo.Password);
579
- // // expect(result.Status).toBe(userInfo.Status);
580
- // // expect(result.DefaultPasswordChangedYN).toBe(
581
- // // userInfo.DefaultPasswordChangedYN,
582
- // // );
583
- // // expect(result.FirstLoginAt).toBe(null);
584
- // // expect(result.LastLoginAt).toBe(null);
585
- // // expect(result.MFAEnabled).toBe(userInfo.MFAEnabled);
586
- // // expect(result.MFAConfig).toBe(userInfo.MFAConfig);
587
- // // expect(result.RecoveryEmail).toBe(userInfo.RecoveryEmail);
588
- // // expect(result.FailedLoginAttemptCount).toBe(
589
- // // userInfo.FailedLoginAttemptCount,
590
- // // );
591
- // // expect(result.LastFailedLoginAt).toBe(userInfo.LastFailedLoginAt);
592
- // // expect(result.LastPasswordChangedAt).toBe(userInfo.LastPasswordChangedAt);
593
- // // expect(result.NeedToChangePasswordYN).toBe(
594
- // // userInfo.NeedToChangePasswordYN,
595
- // // );
596
- // // expect(result.CreatedById).toBe(userInfo.CreatedById);
597
- // // expect(result.UpdatedById).toBe(userInfo.UpdatedById);
598
- // // });
599
-
600
- // // it('should throw an error if user dont have the privilege to create new user', async () => {
601
- // // jest.spyOn(loginUser, 'checkPrivileges').mockResolvedValueOnce(false);
602
-
603
- // // await expect(
604
- // // LoginUser.create(loginUser, dbTransaction, user),
605
- // // ).rejects.toThrow(ClassError);
606
- // // });
607
-
608
- // // it('should throw an error if user email is missing', async () => {
609
- // // user.Email = undefined;
610
-
611
- // // jest.spyOn(loginUser, 'checkPrivileges').mockResolvedValueOnce(true);
612
-
613
- // // await expect(
614
- // // LoginUser.create(loginUser, dbTransaction, user),
615
- // // ).rejects.toThrow(ClassError);
616
- // // });
617
- // // });
618
-
619
- // describe('incrementFailedLoginAttemptCount', () => {
620
- // afterAll(() => {
621
- // jest.restoreAllMocks();
622
- // });
623
-
624
- // it('should increment FailedLoginAttemptCount and update user status', async () => {
625
- // // Arrange
626
- // const sessionService = await SessionService.init();
627
- // const loginUser = await LoginUser.init(sessionService);
628
- // loginUser['FailedLoginAttemptCount'] = 2;
629
- // loginUser['LastFailedLoginAt'] = new Date();
630
- // loginUser['Status'] = UserStatus.ACTIVE;
631
-
632
- // const dbTransaction = null;
633
-
634
- // // Mock the static methods and properties
635
- // jest
636
- // .spyOn((LoginUser as any)['_Repository'], 'update')
637
- // .mockReturnValueOnce(null);
638
-
639
- // jest
640
- // .spyOn(ComponentConfig, 'getComponentConfigValue')
641
- // .mockImplementation((componentName: string, configKey: string) => {
642
- // if (configKey === 'maxFailedLoginAttempts') {
643
- // return 3;
644
- // }
645
- // if (configKey === 'autoReleaseYN') {
646
- // return 'Y';
647
- // }
648
- // });
649
-
650
- // // Act
651
- // await loginUser['incrementFailedLoginAttemptCount'](dbTransaction);
652
-
653
- // // Assert
654
- // expect(LoginUser['_Repository'].update).toHaveBeenCalledWith(
655
- // {
656
- // FailedLoginAttemptCount: 3,
657
- // LastFailedLoginAt: expect.any(Date),
658
- // Status: UserStatus.ACTIVE,
659
- // },
660
- // {
661
- // where: {
662
- // UserId: loginUser.UserId,
663
- // },
664
- // transaction: dbTransaction,
665
- // },
666
- // );
667
- // });
668
-
669
- // it('should throw an error if maxFailedLoginAttempts or autoReleaseYN is missing', async () => {
670
- // // Arrange
671
- // const sessionService = await SessionService.init();
672
- // const loginUser = await LoginUser.init(sessionService);
673
- // loginUser['FailedLoginAttemptCount'] = 2;
674
- // loginUser['LastFailedLoginAt'] = new Date();
675
- // loginUser['Status'] = UserStatus.ACTIVE;
676
-
677
- // const dbTransaction = null;
678
-
679
- // // Mock the static methods and properties
680
- // jest
681
- // .spyOn((LoginUser as any)['_Repository'], 'update')
682
- // .mockReturnValueOnce(null);
683
-
684
- // jest
685
- // .spyOn(ComponentConfig, 'getComponentConfigValue')
686
- // .mockImplementationOnce((componentName: string, configKey: string) => {
687
- // if (configKey === 'maxFailedLoginAttempts') {
688
- // return undefined;
689
- // }
690
- // if (configKey === 'autoReleaseYN') {
691
- // return undefined;
692
- // }
693
- // });
694
-
695
- // // Act and Assert
696
- // await expect(
697
- // loginUser['incrementFailedLoginAttemptCount'](dbTransaction),
698
- // ).rejects.toThrow(
699
- // new ClassError(
700
- // 'LoginUser',
701
- // 'LoginUserErrMsg0X',
702
- // 'Missing maxFailedLoginAttempts and or autoReleaseYN. Please set in config file.',
703
- // ),
704
- // );
705
- // });
706
-
707
- // it('should lock the user account if the failed login attempts exceed the maximum allowed', async () => {
708
- // // Arrange
709
- // const sessionService = await SessionService.init();
710
- // const loginUser = await LoginUser.init(sessionService);
711
- // loginUser['FailedLoginAttemptCount'] = 3;
712
- // loginUser['LastFailedLoginAt'] = new Date();
713
- // loginUser['Status'] = UserStatus.ACTIVE;
714
-
715
- // const dbTransaction = null;
716
-
717
- // // Mock the static methods and properties
718
- // jest
719
- // .spyOn((LoginUser as any)['_Repository'], 'update')
720
- // .mockReturnValueOnce(null);
721
-
722
- // jest
723
- // .spyOn(ComponentConfig, 'getComponentConfigValue')
724
- // .mockImplementation((componentName: string, configKey: string) => {
725
- // if (configKey === 'maxFailedLoginAttempts') {
726
- // return 3;
727
- // }
728
- // if (configKey === 'autoReleaseYN') {
729
- // return 'Y';
730
- // }
731
- // });
732
-
733
- // // Act
734
- // try {
735
- // await loginUser['incrementFailedLoginAttemptCount'](dbTransaction);
736
- // expect(false).toBe(true);
737
- // } catch (error) {
738
- // // Assert
739
- // expect(LoginUser['_Repository'].update).toHaveBeenCalledWith(
740
- // {
741
- // FailedLoginAttemptCount: 4,
742
- // LastFailedLoginAt: expect.any(Date),
743
- // Status: UserStatus.LOCKED,
744
- // },
745
- // {
746
- // where: {
747
- // UserId: loginUser.UserId,
748
- // },
749
- // transaction: dbTransaction,
750
- // },
751
- // );
752
- // expect(error).toBeInstanceOf(ClassError);
753
- // expect(error.message).toBe(
754
- // 'Your account has been temporarily locked due to too many failed login attempts, please try again later.',
755
- // );
756
- // }
757
- // });
758
-
759
- // it('should permanently lock the user account if the failed login attempts exceed the maximum allowed and autoReleaseYN is N', async () => {
760
- // // Arrange
761
- // const sessionService = await SessionService.init();
762
- // const loginUser = await LoginUser.init(sessionService);
763
- // loginUser['FailedLoginAttemptCount'] = 3;
764
- // loginUser['LastFailedLoginAt'] = new Date();
765
- // loginUser['Status'] = UserStatus.ACTIVE;
766
-
767
- // const dbTransaction = null;
768
-
769
- // // Mock the static methods and properties
770
- // jest
771
- // .spyOn((LoginUser as any)['_Repository'], 'update')
772
- // .mockReturnValueOnce(null);
773
-
774
- // jest
775
- // .spyOn(ComponentConfig, 'getComponentConfigValue')
776
- // .mockImplementation((componentName: string, configKey: string) => {
777
- // if (configKey === 'maxFailedLoginAttempts') {
778
- // return 3;
779
- // }
780
- // if (configKey === 'autoReleaseYN') {
781
- // return 'N';
782
- // }
783
- // });
784
-
785
- // // Act
786
- // try {
787
- // await loginUser['incrementFailedLoginAttemptCount'](dbTransaction);
788
- // expect(false).toBe(true);
789
- // } catch (error) {
790
- // // Assert
791
- // expect(LoginUser['_Repository'].update).toHaveBeenCalledWith(
792
- // {
793
- // FailedLoginAttemptCount: 4,
794
- // LastFailedLoginAt: expect.any(Date),
795
- // Status: UserStatus.LOCKED,
796
- // },
797
- // {
798
- // where: {
799
- // UserId: loginUser.UserId,
800
- // },
801
- // transaction: dbTransaction,
802
- // },
803
- // );
804
- // expect(error).toBeInstanceOf(ClassError);
805
- // expect(error.message).toBe(
806
- // 'Your account has been locked due to too many failed login attempts, please contact IT Support for instructions on how to unlock your account',
807
- // );
808
- // }
809
- // });
810
- // });
811
-
812
- // describe('combineSystemAccess', () => {
813
- // it('should combine user and group system access and remove duplicates', async () => {
814
- // // Mock the necessary dependencies
815
- // const sessionService = await SessionService.init();
816
- // const loginUser = await LoginUser.init(sessionService);
817
- // const dbTransaction = null;
818
- // const groups = [
819
- // { InheritParentSystemAccessYN: true },
820
- // { InheritParentSystemAccessYN: false },
821
- // ];
822
-
823
- // // Mock the necessary repository methods
824
- // jest
825
- // .spyOn(LoginUser as any, 'getInheritedSystemAccess')
826
- // .mockResolvedValueOnce([
827
- // { SystemCode: 'system1' },
828
- // { SystemCode: 'system2' },
829
- // ]);
830
- // jest
831
- // .spyOn((LoginUser as any)['_UserSystemAccessRepo'], 'findAll')
832
- // .mockResolvedValueOnce([{ SystemCode: 'system3' }]);
833
-
834
- // // Call the method
835
- // const result = await LoginUser['combineSystemAccess'](
836
- // loginUser,
837
- // dbTransaction,
838
- // groups,
839
- // );
840
-
841
- // // Assert the result
842
- // expect(result).toEqual([
843
- // { SystemCode: 'system3' },
844
- // { SystemCode: 'system1' },
845
- // { SystemCode: 'system2' },
846
- // ]);
847
- // });
848
- // });
849
-
850
- // describe('checkPrivileges', () => {
851
- // it('should return true if user has the specified privilege', async () => {
852
- // // Arrange
853
- // const systemCode = 'SS';
854
- // const privilegeName = 'Privilege 1';
855
- // const sessionService = await SessionService.init();
856
- // const loginUser = await LoginUser.init(sessionService);
857
- // loginUser.ObjectId = '1';
858
-
859
- // // Mock the necessary methods
860
- // const rus = jest
861
- // .spyOn(SessionService.prototype, 'retrieveUserSession')
862
- // .mockResolvedValueOnce({
863
- // systemLogins: [
864
- // {
865
- // id: '1',
866
- // sessionId: 'sessionId',
867
- // code: systemCode,
868
- // privileges: [privilegeName],
869
- // },
870
- // ],
871
- // });
872
- // // Act
873
- // const hasPrivilege = await loginUser.checkPrivileges(
874
- // systemCode,
875
- // privilegeName,
876
- // );
877
-
878
- // // Assert
879
- // expect(hasPrivilege).toBe(true);
880
- // expect(rus).toHaveBeenCalledWith(loginUser.ObjectId);
881
- // });
882
-
883
- // it('should return false if user does not have the specified privilege', async () => {
884
- // // Arrange
885
- // const systemCode = 'SS';
886
- // const privilegeName = 'Privilege 1';
887
- // const sessionService = await SessionService.init();
888
- // const loginUser = await LoginUser.init(sessionService);
889
- // loginUser.ObjectId = '1';
890
-
891
- // // Mock the necessary methods
892
- // const rus = jest
893
- // .spyOn(SessionService.prototype, 'retrieveUserSession')
894
- // .mockResolvedValueOnce({
895
- // systemLogins: [
896
- // {
897
- // id: '1',
898
- // sessionId: 'sessionId',
899
- // code: systemCode,
900
- // privileges: [],
901
- // },
902
- // ],
903
- // });
904
- // // Act
905
- // const hasPrivilege = await loginUser.checkPrivileges(
906
- // systemCode,
907
- // privilegeName,
908
- // );
909
-
910
- // // Assert
911
- // expect(hasPrivilege).toBe(false);
912
- // expect(rus).toHaveBeenCalledWith(loginUser.ObjectId);
913
- // });
914
-
915
- // it('should throw an error if ObjectId is not set', async () => {
916
- // // Arrange
917
- // const systemCode = 'SS';
918
- // const privilegeName = 'Privilege 1';
919
- // const sessionService = await SessionService.init();
920
- // const loginUser = await LoginUser.init(sessionService);
921
- // loginUser.ObjectId = null;
922
-
923
- // // Act & Assert
924
- // await expect(
925
- // loginUser.checkPrivileges(systemCode, privilegeName),
926
- // ).rejects.toThrowError();
927
- // });
928
- // });
929
-
930
- // describe('getObjectPrivileges', () => {
931
- // it('should return an array of privileges', async () => {
932
- // // Mock the dependencies and setup the test data
933
- // const systemCode = 'system1';
934
- // const dbTransaction = null;
935
- // const sessionService = await SessionService.init();
936
- // const loginUser = await LoginUser.init(sessionService);
937
-
938
- // // Mock the UserObjectPrivilegeRepo findAll method
939
- // const findAllMock = jest
940
- // .spyOn(LoginUser['_UserObjectPrivilegeRepo'], 'findAll')
941
- // .mockResolvedValue([
942
- // {
943
- // PrivilegeCode: 'privilege1',
944
- // Privilege: {
945
- // PrivilegeCode: 'privilege1',
946
- // SystemCode: systemCode,
947
- // Name: 'privilege1',
948
- // },
949
- // },
950
- // {
951
- // PrivilegeCode: 'privilege2',
952
- // Privilege: {
953
- // PrivilegeCode: 'privilege2',
954
- // Name: 'privilege2',
955
- // },
956
- // },
957
- // ] as any);
958
-
959
- // // Call the getObjectPrivileges method
960
- // const result = await loginUser['getObjectPrivileges'](
961
- // systemCode,
962
- // dbTransaction,
963
- // );
964
-
965
- // // Assertions
966
- // expect(findAllMock).toHaveBeenCalledTimes(1);
967
- // expect(findAllMock).toHaveBeenCalledWith({
968
- // where: {
969
- // UserId: loginUser.UserId,
970
- // },
971
- // include: {
972
- // model: SystemPrivilegeModel,
973
- // where: {
974
- // SystemCode: systemCode,
975
- // Status: 'Active',
976
- // },
977
- // },
978
- // transaction: dbTransaction,
979
- // });
980
- // expect(result).toEqual(['privilege1', 'privilege2']);
981
- // });
982
-
983
- // it('should throw an error if an exception occurs', async () => {
984
- // // Mock the dependencies and setup the test data
985
- // const systemCode = 'system1';
986
- // const dbTransaction = null;
987
- // const sessionService = await SessionService.init();
988
- // const loginUser = await LoginUser.init(sessionService);
989
-
990
- // // Mock the UserObjectPrivilegeRepo findAll method to throw an error
991
- // jest
992
- // .spyOn(LoginUser['_UserObjectPrivilegeRepo'], 'findAll')
993
- // .mockRejectedValue(new Error('Database error'));
994
-
995
- // // Call the getObjectPrivileges method and expect it to throw an error
996
- // await expect(
997
- // loginUser['getObjectPrivileges'](systemCode, dbTransaction),
998
- // ).rejects.toThrow(Error);
999
- // });
1000
- // });
1001
-
1002
- // describe('getUserPersonalPrivileges', () => {
1003
- // it('should return an array of privileges', async () => {
1004
- // // Arrange
1005
- // const sessionService = await SessionService.init();
1006
- // const loginUser = await LoginUser.init(sessionService);
1007
- // const systemCode = 'system1';
1008
- // const dbTransaction = null;
1009
-
1010
- // // Mock the findAll method of UserPrivilegeRepo
1011
- // const findAllMock = jest.spyOn(
1012
- // LoginUser['_UserPrivilegeRepo'],
1013
- // 'findAll',
1014
- // );
1015
- // findAllMock.mockResolvedValue([
1016
- // { Privilege: { Name: 'privilege1' } },
1017
- // { Privilege: { Name: 'privilege2' } },
1018
- // ] as any);
1019
-
1020
- // // Act
1021
- // const privileges = await loginUser['getUserPersonalPrivileges'](
1022
- // systemCode,
1023
- // dbTransaction,
1024
- // );
1025
-
1026
- // // Assert
1027
- // expect(privileges).toEqual(['privilege1', 'privilege2']);
1028
- // expect(findAllMock).toHaveBeenCalledTimes(1);
1029
- // expect(findAllMock).toHaveBeenCalledWith({
1030
- // where: {
1031
- // UserId: loginUser.UserId,
1032
- // Status: 'Active',
1033
- // },
1034
- // include: {
1035
- // model: SystemPrivilegeModel,
1036
- // where: {
1037
- // SystemCode: systemCode,
1038
- // Status: 'Active',
1039
- // },
1040
- // },
1041
- // transaction: dbTransaction,
1042
- // });
1043
- // });
1044
-
1045
- // it('should throw an error if an error occurs', async () => {
1046
- // // Arrange
1047
- // const sessionService = await SessionService.init();
1048
- // const loginUser = await LoginUser.init(sessionService);
1049
- // const systemCode = 'system1';
1050
- // const dbTransaction = null;
1051
-
1052
- // // Mock the findAll method of UserPrivilegeRepo to throw an error
1053
- // const findAllMock = jest.spyOn(
1054
- // LoginUser['_UserPrivilegeRepo'],
1055
- // 'findAll',
1056
- // );
1057
- // findAllMock.mockRejectedValue(new Error('Database error'));
1058
-
1059
- // // Act and Assert
1060
- // await expect(
1061
- // loginUser['getUserPersonalPrivileges'](systemCode, dbTransaction),
1062
- // ).rejects.toThrow(Error);
1063
-
1064
- // expect(findAllMock).toHaveBeenCalledTimes(1);
1065
- // expect(findAllMock).toHaveBeenCalledWith({
1066
- // where: {
1067
- // UserId: loginUser.UserId,
1068
- // Status: 'Active',
1069
- // },
1070
- // include: {
1071
- // model: SystemPrivilegeModel,
1072
- // where: {
1073
- // SystemCode: systemCode,
1074
- // Status: 'Active',
1075
- // },
1076
- // },
1077
- // transaction: dbTransaction,
1078
- // });
1079
- // });
1080
- // });
1081
-
1082
- // describe('getInheritedSystemAccess', () => {
1083
- // it('should return group system access with its parent group system access if applicable', async () => {
1084
- // // Mock the necessary dependencies
1085
- // const dbTransaction = null;
1086
- // const group = {
1087
- // GroupCode: 'group1',
1088
- // InheritParentPrivilegeYN: 'Y',
1089
- // ParentGroupCode: 'parentGroup',
1090
- // } as any;
1091
- // const parentGroup = {
1092
- // GroupCode: 'parentGroup',
1093
- // InheritParentPrivilegeYN: 'N',
1094
- // ParentGroupCode: null,
1095
- // } as any;
1096
-
1097
- // const systemAccess = [
1098
- // {
1099
- // SystemCode: 'system1',
1100
- // GroupCode: 'group1',
1101
- // System: { SystemCode: 'system1' },
1102
- // },
1103
- // {
1104
- // SystemCode: 'system2',
1105
- // GroupCode: 'group1',
1106
- // System: { SystemCode: 'system1' },
1107
- // },
1108
- // ] as any;
1109
-
1110
- // const parentSystemAccess = [
1111
- // {
1112
- // SystemCode: 'system3',
1113
- // GroupCode: 'parentGroup',
1114
- // System: { SystemCode: 'system3' },
1115
- // },
1116
- // ] as any;
1117
-
1118
- // // Mock the necessary repository methods
1119
- // const groupFindByPkMock = jest
1120
- // .spyOn(GroupRepository.prototype, 'findByPk')
1121
- // .mockResolvedValueOnce(parentGroup as any);
1122
- // const systemAccessFindAllMock = jest
1123
- // .spyOn(GroupSystemAccessRepository.prototype, 'findAll')
1124
- // .mockImplementation((options: any) => {
1125
- // if (options.where.GroupCode === group.GroupCode) {
1126
- // return Promise.resolve(systemAccess);
1127
- // } else if (options.where.GroupCode === parentGroup.GroupCode) {
1128
- // return Promise.resolve(parentSystemAccess);
1129
- // }
1130
- // });
1131
-
1132
- // // Call the method
1133
- // const result = await LoginUser['getInheritedSystemAccess'](
1134
- // dbTransaction,
1135
- // group,
1136
- // );
1137
-
1138
- // console.log(result);
1139
- // // Assert the result
1140
- // expect(result).toEqual([
1141
- // {
1142
- // SystemCode: 'system1',
1143
- // GroupCode: 'group1',
1144
- // System: { SystemCode: 'system1' },
1145
- // },
1146
- // {
1147
- // SystemCode: 'system2',
1148
- // GroupCode: 'group1',
1149
- // System: { SystemCode: 'system1' },
1150
- // },
1151
- // {
1152
- // SystemCode: 'system3',
1153
- // GroupCode: 'parentGroup',
1154
- // System: { SystemCode: 'system3' },
1155
- // },
1156
- // ]);
1157
- // expect(groupFindByPkMock).toHaveBeenCalledWith(
1158
- // group.ParentGroupCode,
1159
- // dbTransaction,
1160
- // );
1161
- // expect(systemAccessFindAllMock).toHaveBeenCalledTimes(2);
1162
- // });
1163
- // });
1164
- // });
1
+ import { SessionService } from '../../../../src/session/session.service';
2
+ import { LoginUser } from '../../../../src/components/login-user/login-user';
3
+ import { ApplicationConfig, ComponentConfig } from '@tomei/config';
4
+ import { UserRepository } from '../../../../src/components/login-user/user.repository';
5
+ import { ClassError } from '@tomei/general';
6
+ import { Activity } from '@tomei/activity-history';
7
+ import { UserStatus } from '../../../../src/enum/user-status.enum';
8
+ import { YN } from '../../../../src/enum/yn.enum';
9
+ import SystemPrivilegeModel from '../../../../src/models/system-privilege.entity';
10
+ import { GroupSystemAccessRepository } from '../../../../src/components/group-system-access/group-system-access.repository';
11
+ import { GroupRepository } from '../../../../src/components/group/group.repository';
12
+
13
+ // describe('LoginUser', () => {
14
+ // afterAll(() => {
15
+ // jest.restoreAllMocks();
16
+ // });
17
+
18
+ // describe('init', () => {
19
+ // let sessionService: any;
20
+ // let userId: number;
21
+ // let dbTransaction: any;
22
+
23
+ // beforeEach(() => {
24
+ // sessionService = {};
25
+ // userId = 1;
26
+ // dbTransaction = null;
27
+ // });
28
+
29
+ // it('should initialize LoginUser with valid userId', async () => {
30
+ // const user = {
31
+ // UserId: 1,
32
+ // FullName: 'John Doe',
33
+ // Email: 'john.doe@example.com',
34
+ // Password: 'password',
35
+ // Status: 'active',
36
+ // DefaultPasswordChangedYN: 'yes',
37
+ // FirstLoginAt: new Date(),
38
+ // LastLoginAt: new Date(),
39
+ // MFAEnabled: 1,
40
+ // MFAConfig: 'config',
41
+ // RecoveryEmail: 'john.doe@example.com',
42
+ // FailedLoginAttemptCount: 0,
43
+ // LastFailedLoginAt: null,
44
+ // LastPasswordChangedAt: new Date(),
45
+ // NeedToChangePasswordYN: 'no',
46
+ // CreatedById: 1,
47
+ // CreatedAt: new Date(),
48
+ // UpdatedById: 1,
49
+ // UpdatedAt: new Date(),
50
+ // Staff: {
51
+ // FullName: 'John Doe',
52
+ // IdNo: '1234567890',
53
+ // Mobile: '1234567890',
54
+ // },
55
+ // };
56
+
57
+ // const findOneMock = jest
58
+ // .spyOn(UserRepository.prototype, 'findOne')
59
+ // .mockResolvedValueOnce(user as any);
60
+
61
+ // const result = await LoginUser.init(
62
+ // sessionService,
63
+ // userId,
64
+ // dbTransaction,
65
+ // );
66
+
67
+ // expect(findOneMock).toHaveBeenCalledTimes(1);
68
+ // expect(findOneMock).toHaveBeenCalledWith({
69
+ // where: {
70
+ // UserId: userId,
71
+ // },
72
+ // include: [
73
+ // {
74
+ // model: expect.anything(),
75
+ // },
76
+ // ],
77
+ // });
78
+ // expect(result).toBeInstanceOf(LoginUser);
79
+ // expect(result.UserId).toBe(user.UserId);
80
+ // expect(result.FullName).toBe(user.FullName);
81
+ // expect(result.Email).toBe(user.Email);
82
+ // expect(result.Password).toBe(user.Password);
83
+ // expect(result.Status).toBe(user.Status);
84
+ // expect(result.DefaultPasswordChangedYN).toBe(
85
+ // user.DefaultPasswordChangedYN,
86
+ // );
87
+ // expect(result.FirstLoginAt).toBe(user.FirstLoginAt);
88
+ // expect(result.LastLoginAt).toBe(user.LastLoginAt);
89
+ // expect(result.MFAEnabled).toBe(user.MFAEnabled);
90
+ // expect(result.MFAConfig).toBe(user.MFAConfig);
91
+ // expect(result.RecoveryEmail).toBe(user.RecoveryEmail);
92
+ // expect(result.FailedLoginAttemptCount).toBe(user.FailedLoginAttemptCount);
93
+ // expect(result.LastFailedLoginAt).toBe(user.LastFailedLoginAt);
94
+ // expect(result.LastPasswordChangedAt).toBe(user.LastPasswordChangedAt);
95
+ // expect(result.NeedToChangePasswordYN).toBe(user.NeedToChangePasswordYN);
96
+ // expect(result.CreatedById).toBe(user.CreatedById);
97
+ // expect(result.CreatedAt).toBe(user.CreatedAt);
98
+ // expect(result.UpdatedById).toBe(user.UpdatedById);
99
+ // expect(result.UpdatedAt).toBe(user.UpdatedAt);
100
+ // });
101
+
102
+ // it('should throw an error when user is not found', async () => {
103
+ // const findOneMock = jest
104
+ // .spyOn(UserRepository.prototype, 'findOne')
105
+ // .mockResolvedValueOnce(null);
106
+
107
+ // await expect(
108
+ // LoginUser.init(sessionService, userId, dbTransaction),
109
+ // ).rejects.toThrow(Error);
110
+
111
+ // expect(findOneMock).toHaveBeenCalledTimes(1);
112
+ // expect(findOneMock).toHaveBeenCalledWith({
113
+ // where: {
114
+ // UserId: userId,
115
+ // },
116
+ // include: [
117
+ // {
118
+ // model: expect.anything(),
119
+ // },
120
+ // ],
121
+ // });
122
+ // });
123
+ // });
124
+
125
+ // // describe('checkSession', () => {
126
+ // // it('should throw an error if session expired', async () => {
127
+ // // // Arrange
128
+ // // const systemCode = 'EZC';
129
+ // // const sessionId = 'ckymxuh8t000137t011w89zgk';
130
+ // // const userId = '755';
131
+ // // const sessionService = await SessionService.init();
132
+ // // const loginUser = await LoginUser.init(sessionService);
133
+
134
+ // // // Act
135
+ // // const checkSessionPromise = loginUser.checkSession(
136
+ // // systemCode,
137
+ // // sessionId,
138
+ // // userId,
139
+ // // );
140
+
141
+ // // // Assert
142
+ // // await expect(checkSessionPromise).rejects.toThrow('Session expired.');
143
+ // // });
144
+
145
+ // // it('should refresh the session duration if session is valid', async () => {
146
+ // // // Arrange
147
+ // // const systemCode = 'EZC';
148
+ // // const sessionId = 'ckymxuh8t000137t011w89zgk';
149
+ // // const userId = '755';
150
+ // // const sessionService = await SessionService.init();
151
+ // // const loginUser = await LoginUser.init(sessionService);
152
+
153
+ // // // Mock the _SessionService.retrieveUserSession method
154
+ // // loginUser['_SessionService'].retrieveUserSession = jest
155
+ // // .fn()
156
+ // // .mockResolvedValue({
157
+ // // systemLogins: [
158
+ // // {
159
+ // // code: systemCode,
160
+ // // sessionId: sessionId,
161
+ // // privileges: [],
162
+ // // },
163
+ // // ],
164
+ // // });
165
+
166
+ // // // Mock the _SessionService.refreshDuration method
167
+ // // loginUser['_SessionService'].refreshDuration = jest.fn();
168
+
169
+ // // // Act
170
+ // // const systemLogin = await loginUser.checkSession(
171
+ // // systemCode,
172
+ // // sessionId,
173
+ // // userId,
174
+ // // );
175
+
176
+ // // // Assert
177
+ // // expect(
178
+ // // loginUser['_SessionService'].retrieveUserSession,
179
+ // // ).toHaveBeenCalledWith(userId);
180
+ // // expect(loginUser['_SessionService'].refreshDuration).toHaveBeenCalledWith(
181
+ // // userId,
182
+ // // );
183
+ // // expect(systemLogin).toEqual({
184
+ // // code: systemCode,
185
+ // // sessionId: sessionId,
186
+ // // privileges: [],
187
+ // // });
188
+ // // });
189
+ // // });
190
+
191
+ // describe('shouldReleaseLock', () => {
192
+ // const minuteToAutoRelease = 5;
193
+ // const autoReleaseYN = 'Y';
194
+
195
+ // beforeEach(() => {
196
+ // jest
197
+ // .spyOn(ComponentConfig, 'getComponentConfigValue')
198
+ // .mockImplementation((componentName: string, configKey: string) => {
199
+ // if (configKey === 'minuteToAutoRelease') {
200
+ // return minuteToAutoRelease as any;
201
+ // }
202
+ // if (configKey === 'autoReleaseYN') {
203
+ // return autoReleaseYN as any;
204
+ // }
205
+ // });
206
+ // });
207
+
208
+ // it('should return true if autoReleaseYN is "Y" and time difference is greater than minuteToAutoRelease', async () => {
209
+ // // Arrange
210
+ // const lastFailedLoginAt = new Date();
211
+ // lastFailedLoginAt.setMinutes(lastFailedLoginAt.getMinutes() - 10); // Set last failed login time to 10 minutes ago
212
+ // // Act
213
+ // const result = LoginUser.shouldReleaseLock(lastFailedLoginAt);
214
+
215
+ // // Assert
216
+ // expect(result).toBe(true);
217
+ // });
218
+
219
+ // it('should return false if autoReleaseYN is "Y" and time difference is less than or equal to minuteToAutoRelease', async () => {
220
+ // // Arrange
221
+ // const lastFailedLoginAt = new Date();
222
+ // lastFailedLoginAt.setMinutes(lastFailedLoginAt.getMinutes() - 3); // Set last failed login time to 3 minutes ago
223
+
224
+ // // Act
225
+ // const result = LoginUser.shouldReleaseLock(lastFailedLoginAt);
226
+
227
+ // // Assert
228
+ // expect(result).toBe(false);
229
+ // });
230
+
231
+ // it('should return false if autoReleaseYN is "N"', async () => {
232
+ // // Arrange
233
+ // const lastFailedLoginAt = new Date();
234
+
235
+ // // Act
236
+ // const result = LoginUser.shouldReleaseLock(lastFailedLoginAt);
237
+
238
+ // // Assert
239
+ // expect(result).toBe(false);
240
+ // });
241
+ // });
242
+
243
+ // describe('releaseLock', () => {
244
+ // it('should release the lock for a user', async () => {
245
+ // // Mock the necessary dependencies and setup the test data
246
+ // const UserId = 1;
247
+ // const dbTransaction = null;
248
+
249
+ // const updateMock = jest
250
+ // .spyOn(LoginUser['_Repository'], 'update')
251
+ // .mockImplementationOnce(() => Promise.resolve({}) as any);
252
+
253
+ // // Call the method under test
254
+ // LoginUser['releaseLock'](UserId, dbTransaction);
255
+
256
+ // // Verify the expected behavior
257
+ // expect(updateMock).toHaveBeenCalledTimes(1);
258
+ // expect(updateMock).toHaveBeenCalledWith(
259
+ // {
260
+ // FailedLoginAttemptCount: 0,
261
+ // Status: 'Active',
262
+ // },
263
+ // {
264
+ // where: {
265
+ // UserId,
266
+ // },
267
+ // transaction: dbTransaction,
268
+ // },
269
+ // );
270
+ // });
271
+ // });
272
+
273
+ // describe('checkUserInfoDuplicated', () => {
274
+ // it('should throw an error if duplicate user info is found', async () => {
275
+ // // Mock the dependencies and setup the test data
276
+ // const dbTransaction = null;
277
+ // const query = {
278
+ // Email: 'test@example.com',
279
+ // IdType: 'passport',
280
+ // IdNo: '123456789',
281
+ // ContactNo: '1234567890',
282
+ // };
283
+
284
+ // // Mock the LoginUser['_Repository'].findAll method to return a user
285
+ // jest
286
+ // .spyOn(LoginUser['_Repository'], 'findAll')
287
+ // .mockResolvedValueOnce([{ id: 1 }] as any);
288
+
289
+ // // Assert that the method throws an error
290
+ // await expect(
291
+ // LoginUser['checkUserInfoDuplicated'](dbTransaction, query),
292
+ // ).rejects.toThrowError();
293
+ // });
294
+
295
+ // it('should not throw an error if duplicate user info is not found', async () => {
296
+ // // Mock the dependencies and setup the test data
297
+ // const dbTransaction = null;
298
+ // const query = {
299
+ // Email: 'test@example.com',
300
+ // IdType: 'passport',
301
+ // IdNo: '123456789',
302
+ // ContactNo: '1234567890',
303
+ // };
304
+
305
+ // // Mock the LoginUser['_Repository'].findAll method to return an empty array
306
+ // jest.spyOn(LoginUser['_Repository'], 'findAll').mockResolvedValueOnce([]);
307
+
308
+ // // Assert that the method does not throw an error
309
+ // await expect(
310
+ // LoginUser['checkUserInfoDuplicated'](dbTransaction, query),
311
+ // ).resolves.not.toThrowError();
312
+ // });
313
+ // });
314
+
315
+ // describe('generateDefaultPassword', () => {
316
+ // const passwordPolicy = {
317
+ // minLen: 6,
318
+ // maxLen: 10,
319
+ // nonAcceptableChar: 'i,l,o',
320
+ // numOfCapitalLetters: 1,
321
+ // numOfNumbers: 1,
322
+ // numOfSpecialChars: 1,
323
+ // };
324
+ // beforeEach(() => {
325
+ // jest
326
+ // .spyOn(ComponentConfig, 'getComponentConfigValue')
327
+ // .mockImplementation((componentName: string, configKey: string) => {
328
+ // if (configKey === 'passwordPolicy') {
329
+ // return passwordPolicy as any;
330
+ // }
331
+ // });
332
+ // });
333
+
334
+ // it('should generate a default password with the specified length', () => {
335
+ // const password = LoginUser['generateDefaultPassword']();
336
+ // expect(password.length).toBeGreaterThanOrEqual(6);
337
+ // expect(password.length).toBeLessThanOrEqual(10);
338
+ // });
339
+
340
+ // it('should generate a default password with at least one capital letter', () => {
341
+ // const password = LoginUser['generateDefaultPassword']();
342
+ // expect(/[A-Z]/.test(password)).toBe(true);
343
+ // });
344
+
345
+ // it('should generate a default password with at least one number', () => {
346
+ // const password = LoginUser['generateDefaultPassword']();
347
+ // expect(/[0-9]/.test(password)).toBe(true);
348
+ // });
349
+
350
+ // it('should generate a default password with at least one special character', () => {
351
+ // const password = LoginUser['generateDefaultPassword']();
352
+ // expect(/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?~`]/.test(password)).toBe(true);
353
+ // });
354
+
355
+ // it('should generate a default password without any non-acceptable characters', () => {
356
+ // const password = LoginUser['generateDefaultPassword']();
357
+ // const nonAcceptableChars = ['i', 'l', 'o'];
358
+ // expect(nonAcceptableChars.some((char) => password.includes(char))).toBe(
359
+ // false,
360
+ // );
361
+ // });
362
+ // });
363
+
364
+ // describe('setPassword', () => {
365
+ // const passwordPolicy = {
366
+ // minLen: 6,
367
+ // maxLen: 10,
368
+ // nonAcceptableChar: 'i,l,o',
369
+ // numOfCapitalLetters: 1,
370
+ // numOfNumbers: 1,
371
+ // numOfSpecialChars: 1,
372
+ // };
373
+ // beforeEach(() => {
374
+ // jest
375
+ // .spyOn(ComponentConfig, 'getComponentConfigValue')
376
+ // .mockImplementation((componentName: string, configKey: string) => {
377
+ // if (configKey === 'passwordPolicy') {
378
+ // return passwordPolicy as any;
379
+ // }
380
+ // });
381
+ // });
382
+
383
+ // it('should set the password for the user', async () => {
384
+ // // Arrange
385
+ // const dbTransaction = null;
386
+ // const sessionService = await SessionService.init();
387
+ // const user = await LoginUser.init(sessionService);
388
+ // const password = 'N3wP@ssw0';
389
+
390
+ // // Act
391
+ // const result = await LoginUser['setPassword'](
392
+ // dbTransaction,
393
+ // user,
394
+ // password,
395
+ // );
396
+
397
+ // // Assert
398
+ // expect(result).toBeInstanceOf(LoginUser);
399
+ // await expect(
400
+ // LoginUser['setPassword'](dbTransaction, user, password),
401
+ // ).resolves.not.toThrowError();
402
+ // expect(result.Password).toBeDefined();
403
+ // });
404
+
405
+ // it('should throw an error if the password does not meet the security requirements', async () => {
406
+ // // Arrange
407
+ // const dbTransaction = null;
408
+ // const sessionService = await SessionService.init();
409
+ // const user = await LoginUser.init(sessionService);
410
+ // const password = 'weakpassword';
411
+
412
+ // // Act & Assert
413
+ // await expect(
414
+ // LoginUser['setPassword'](dbTransaction, user, password),
415
+ // ).rejects.toThrow();
416
+ // });
417
+ // });
418
+
419
+ // // describe('create', () => {
420
+ // // let loginUser: LoginUser;
421
+ // // let dbTransaction: any;
422
+ // // let user: LoginUser;
423
+ // // let newUser: any;
424
+
425
+ // // beforeEach(async () => {
426
+ // // const sessionService = await SessionService.init();
427
+ // // loginUser = await LoginUser.init(sessionService);
428
+ // // dbTransaction = null;
429
+ // // newUser = {
430
+ // // UserId: 1,
431
+ // // FullName: 'John Doe',
432
+ // // Email: 'john.doe@example.com',
433
+ // // Password: 'password',
434
+ // // Status: 'Active',
435
+ // // DefaultPasswordChangedYN: 'N',
436
+ // // FirstLoginAt: null,
437
+ // // LastLoginAt: null,
438
+ // // MFAEnabled: null,
439
+ // // MFAConfig: null,
440
+ // // RecoveryEmail: null,
441
+ // // FailedLoginAttemptCount: 0,
442
+ // // LastFailedLoginAt: null,
443
+ // // LastPasswordChangedAt: new Date(),
444
+ // // NeedToChangePasswordYN: 'N',
445
+ // // CreatedById: 1,
446
+ // // CreatedAt: new Date(),
447
+ // // UpdatedById: 1,
448
+ // // UpdatedAt: new Date(),
449
+ // // Staff: {
450
+ // // FullName: 'John Doe',
451
+ // // IdNo: '1234567890',
452
+ // // Mobile: '1234567890',
453
+ // // },
454
+ // // };
455
+ // // user = new (LoginUser as any)(sessionService, null, newUser);
456
+ // // });
457
+
458
+ // // afterEach(() => {
459
+ // // jest.clearAllMocks();
460
+ // // });
461
+
462
+ // // it('should create a new user record', async () => {
463
+ // // const checkPrivilegesMock = jest
464
+ // // .spyOn(loginUser, 'checkPrivileges')
465
+ // // .mockResolvedValueOnce(true);
466
+
467
+ // // const checkUserInfoDuplicatedMock = jest
468
+ // // .spyOn(LoginUser as any, 'checkUserInfoDuplicated')
469
+ // // .mockResolvedValueOnce(undefined);
470
+
471
+ // // const generateDefaultPasswordMock = jest
472
+ // // .spyOn(LoginUser as any, 'generateDefaultPassword')
473
+ // // .mockReturnValueOnce('defaultPassword');
474
+
475
+ // // const setPasswordMock = jest
476
+ // // .spyOn(LoginUser as any, 'setPassword')
477
+ // // .mockResolvedValueOnce(user);
478
+
479
+ // // const createMock = jest
480
+ // // .spyOn((LoginUser as any)['_Repository'], 'create')
481
+ // // .mockResolvedValueOnce({
482
+ // // ...newUser,
483
+ // // get: () => newUser,
484
+ // // });
485
+
486
+ // // const activityCreateMock = jest
487
+ // // .spyOn((Activity as any).prototype, 'create')
488
+ // // .mockResolvedValueOnce(undefined);
489
+
490
+ // // jest
491
+ // // .spyOn(ApplicationConfig, 'getComponentConfigValue')
492
+ // // .mockImplementation((configKey: string) => {
493
+ // // if (configKey === 'system-code') {
494
+ // // return 'SC';
495
+ // // }
496
+ // // });
497
+
498
+ // // const result = await LoginUser.create(loginUser, dbTransaction, user);
499
+
500
+ // // expect(checkPrivilegesMock).toHaveBeenCalledTimes(1);
501
+ // // expect(checkPrivilegesMock).toHaveBeenCalledWith(
502
+ // // ApplicationConfig.getComponentConfigValue('system-code'),
503
+ // // 'User - Create',
504
+ // // );
505
+
506
+ // // expect(checkUserInfoDuplicatedMock).toHaveBeenCalledTimes(1);
507
+ // // expect(checkUserInfoDuplicatedMock).toHaveBeenCalledWith(dbTransaction, {
508
+ // // Email: user.Email,
509
+ // // IdType: user.IDType,
510
+ // // IdNo: user.IDNo,
511
+ // // ContactNo: user.ContactNo,
512
+ // // });
513
+
514
+ // // expect(generateDefaultPasswordMock).toHaveBeenCalledTimes(1);
515
+
516
+ // // expect(setPasswordMock).toHaveBeenCalledTimes(1);
517
+ // // expect(setPasswordMock).toHaveBeenCalledWith(
518
+ // // dbTransaction,
519
+ // // user,
520
+ // // 'defaultPassword',
521
+ // // );
522
+
523
+ // // expect(createMock).toHaveBeenCalledTimes(1);
524
+
525
+ // // const userInfo = {
526
+ // // FullName: user.FullName,
527
+ // // IDNo: user.IDNo,
528
+ // // Email: user.Email,
529
+ // // ContactNo: user.ContactNo,
530
+ // // Password: user.Password,
531
+ // // Status: UserStatus.ACTIVE,
532
+ // // FirstLoginAt: null,
533
+ // // LastLoginAt: null,
534
+ // // MFAEnabled: null,
535
+ // // MFAConfig: null,
536
+ // // RecoveryEmail: null,
537
+ // // FailedLoginAttemptCount: 0,
538
+ // // LastFailedLoginAt: null,
539
+ // // LastPasswordChangedAt: null,
540
+ // // DefaultPasswordChangedYN: YN.No,
541
+ // // NeedToChangePasswordYN: YN.Yes,
542
+ // // CreatedById: loginUser.UserId,
543
+ // // CreatedAt: new Date(),
544
+ // // UpdatedById: loginUser.UserId,
545
+ // // UpdatedAt: new Date(),
546
+ // // UserId: null,
547
+ // // };
548
+
549
+ // // expect(createMock).toHaveBeenCalledWith(
550
+ // // {
551
+ // // Email: userInfo.Email,
552
+ // // Password: userInfo.Password,
553
+ // // Status: userInfo.Status,
554
+ // // DefaultPasswordChangedYN: userInfo.DefaultPasswordChangedYN,
555
+ // // FirstLoginAt: userInfo.FirstLoginAt,
556
+ // // LastLoginAt: userInfo.LastLoginAt,
557
+ // // MFAEnabled: userInfo.MFAEnabled,
558
+ // // MFAConfig: userInfo.MFAConfig,
559
+ // // RecoveryEmail: userInfo.RecoveryEmail,
560
+ // // FailedLoginAttemptCount: userInfo.FailedLoginAttemptCount,
561
+ // // LastFailedLoginAt: userInfo.LastFailedLoginAt,
562
+ // // LastPasswordChangedAt: userInfo.LastPasswordChangedAt,
563
+ // // NeedToChangePasswordYN: userInfo.NeedToChangePasswordYN,
564
+ // // CreatedById: userInfo.CreatedById,
565
+ // // CreatedAt: expect.any(Date),
566
+ // // UpdatedById: userInfo.UpdatedById,
567
+ // // UpdatedAt: expect.any(Date),
568
+ // // },
569
+ // // {
570
+ // // transaction: dbTransaction,
571
+ // // },
572
+ // // );
573
+
574
+ // // expect(activityCreateMock).toHaveBeenCalledTimes(1);
575
+
576
+ // // expect(result).toBeInstanceOf(LoginUser);
577
+ // // expect(result.Email).toBe(userInfo.Email);
578
+ // // expect(result.Password).toBe(userInfo.Password);
579
+ // // expect(result.Status).toBe(userInfo.Status);
580
+ // // expect(result.DefaultPasswordChangedYN).toBe(
581
+ // // userInfo.DefaultPasswordChangedYN,
582
+ // // );
583
+ // // expect(result.FirstLoginAt).toBe(null);
584
+ // // expect(result.LastLoginAt).toBe(null);
585
+ // // expect(result.MFAEnabled).toBe(userInfo.MFAEnabled);
586
+ // // expect(result.MFAConfig).toBe(userInfo.MFAConfig);
587
+ // // expect(result.RecoveryEmail).toBe(userInfo.RecoveryEmail);
588
+ // // expect(result.FailedLoginAttemptCount).toBe(
589
+ // // userInfo.FailedLoginAttemptCount,
590
+ // // );
591
+ // // expect(result.LastFailedLoginAt).toBe(userInfo.LastFailedLoginAt);
592
+ // // expect(result.LastPasswordChangedAt).toBe(userInfo.LastPasswordChangedAt);
593
+ // // expect(result.NeedToChangePasswordYN).toBe(
594
+ // // userInfo.NeedToChangePasswordYN,
595
+ // // );
596
+ // // expect(result.CreatedById).toBe(userInfo.CreatedById);
597
+ // // expect(result.UpdatedById).toBe(userInfo.UpdatedById);
598
+ // // });
599
+
600
+ // // it('should throw an error if user dont have the privilege to create new user', async () => {
601
+ // // jest.spyOn(loginUser, 'checkPrivileges').mockResolvedValueOnce(false);
602
+
603
+ // // await expect(
604
+ // // LoginUser.create(loginUser, dbTransaction, user),
605
+ // // ).rejects.toThrow(ClassError);
606
+ // // });
607
+
608
+ // // it('should throw an error if user email is missing', async () => {
609
+ // // user.Email = undefined;
610
+
611
+ // // jest.spyOn(loginUser, 'checkPrivileges').mockResolvedValueOnce(true);
612
+
613
+ // // await expect(
614
+ // // LoginUser.create(loginUser, dbTransaction, user),
615
+ // // ).rejects.toThrow(ClassError);
616
+ // // });
617
+ // // });
618
+
619
+ // describe('incrementFailedLoginAttemptCount', () => {
620
+ // afterAll(() => {
621
+ // jest.restoreAllMocks();
622
+ // });
623
+
624
+ // it('should increment FailedLoginAttemptCount and update user status', async () => {
625
+ // // Arrange
626
+ // const sessionService = await SessionService.init();
627
+ // const loginUser = await LoginUser.init(sessionService);
628
+ // loginUser['FailedLoginAttemptCount'] = 2;
629
+ // loginUser['LastFailedLoginAt'] = new Date();
630
+ // loginUser['Status'] = UserStatus.ACTIVE;
631
+
632
+ // const dbTransaction = null;
633
+
634
+ // // Mock the static methods and properties
635
+ // jest
636
+ // .spyOn((LoginUser as any)['_Repository'], 'update')
637
+ // .mockReturnValueOnce(null);
638
+
639
+ // jest
640
+ // .spyOn(ComponentConfig, 'getComponentConfigValue')
641
+ // .mockImplementation((componentName: string, configKey: string) => {
642
+ // if (configKey === 'maxFailedLoginAttempts') {
643
+ // return 3;
644
+ // }
645
+ // if (configKey === 'autoReleaseYN') {
646
+ // return 'Y';
647
+ // }
648
+ // });
649
+
650
+ // // Act
651
+ // await loginUser['incrementFailedLoginAttemptCount'](dbTransaction);
652
+
653
+ // // Assert
654
+ // expect(LoginUser['_Repository'].update).toHaveBeenCalledWith(
655
+ // {
656
+ // FailedLoginAttemptCount: 3,
657
+ // LastFailedLoginAt: expect.any(Date),
658
+ // Status: UserStatus.ACTIVE,
659
+ // },
660
+ // {
661
+ // where: {
662
+ // UserId: loginUser.UserId,
663
+ // },
664
+ // transaction: dbTransaction,
665
+ // },
666
+ // );
667
+ // });
668
+
669
+ // it('should throw an error if maxFailedLoginAttempts or autoReleaseYN is missing', async () => {
670
+ // // Arrange
671
+ // const sessionService = await SessionService.init();
672
+ // const loginUser = await LoginUser.init(sessionService);
673
+ // loginUser['FailedLoginAttemptCount'] = 2;
674
+ // loginUser['LastFailedLoginAt'] = new Date();
675
+ // loginUser['Status'] = UserStatus.ACTIVE;
676
+
677
+ // const dbTransaction = null;
678
+
679
+ // // Mock the static methods and properties
680
+ // jest
681
+ // .spyOn((LoginUser as any)['_Repository'], 'update')
682
+ // .mockReturnValueOnce(null);
683
+
684
+ // jest
685
+ // .spyOn(ComponentConfig, 'getComponentConfigValue')
686
+ // .mockImplementationOnce((componentName: string, configKey: string) => {
687
+ // if (configKey === 'maxFailedLoginAttempts') {
688
+ // return undefined;
689
+ // }
690
+ // if (configKey === 'autoReleaseYN') {
691
+ // return undefined;
692
+ // }
693
+ // });
694
+
695
+ // // Act and Assert
696
+ // await expect(
697
+ // loginUser['incrementFailedLoginAttemptCount'](dbTransaction),
698
+ // ).rejects.toThrow(
699
+ // new ClassError(
700
+ // 'LoginUser',
701
+ // 'LoginUserErrMsg0X',
702
+ // 'Missing maxFailedLoginAttempts and or autoReleaseYN. Please set in config file.',
703
+ // ),
704
+ // );
705
+ // });
706
+
707
+ // it('should lock the user account if the failed login attempts exceed the maximum allowed', async () => {
708
+ // // Arrange
709
+ // const sessionService = await SessionService.init();
710
+ // const loginUser = await LoginUser.init(sessionService);
711
+ // loginUser['FailedLoginAttemptCount'] = 3;
712
+ // loginUser['LastFailedLoginAt'] = new Date();
713
+ // loginUser['Status'] = UserStatus.ACTIVE;
714
+
715
+ // const dbTransaction = null;
716
+
717
+ // // Mock the static methods and properties
718
+ // jest
719
+ // .spyOn((LoginUser as any)['_Repository'], 'update')
720
+ // .mockReturnValueOnce(null);
721
+
722
+ // jest
723
+ // .spyOn(ComponentConfig, 'getComponentConfigValue')
724
+ // .mockImplementation((componentName: string, configKey: string) => {
725
+ // if (configKey === 'maxFailedLoginAttempts') {
726
+ // return 3;
727
+ // }
728
+ // if (configKey === 'autoReleaseYN') {
729
+ // return 'Y';
730
+ // }
731
+ // });
732
+
733
+ // // Act
734
+ // try {
735
+ // await loginUser['incrementFailedLoginAttemptCount'](dbTransaction);
736
+ // expect(false).toBe(true);
737
+ // } catch (error) {
738
+ // // Assert
739
+ // expect(LoginUser['_Repository'].update).toHaveBeenCalledWith(
740
+ // {
741
+ // FailedLoginAttemptCount: 4,
742
+ // LastFailedLoginAt: expect.any(Date),
743
+ // Status: UserStatus.LOCKED,
744
+ // },
745
+ // {
746
+ // where: {
747
+ // UserId: loginUser.UserId,
748
+ // },
749
+ // transaction: dbTransaction,
750
+ // },
751
+ // );
752
+ // expect(error).toBeInstanceOf(ClassError);
753
+ // expect(error.message).toBe(
754
+ // 'Your account has been temporarily locked due to too many failed login attempts, please try again later.',
755
+ // );
756
+ // }
757
+ // });
758
+
759
+ // it('should permanently lock the user account if the failed login attempts exceed the maximum allowed and autoReleaseYN is N', async () => {
760
+ // // Arrange
761
+ // const sessionService = await SessionService.init();
762
+ // const loginUser = await LoginUser.init(sessionService);
763
+ // loginUser['FailedLoginAttemptCount'] = 3;
764
+ // loginUser['LastFailedLoginAt'] = new Date();
765
+ // loginUser['Status'] = UserStatus.ACTIVE;
766
+
767
+ // const dbTransaction = null;
768
+
769
+ // // Mock the static methods and properties
770
+ // jest
771
+ // .spyOn((LoginUser as any)['_Repository'], 'update')
772
+ // .mockReturnValueOnce(null);
773
+
774
+ // jest
775
+ // .spyOn(ComponentConfig, 'getComponentConfigValue')
776
+ // .mockImplementation((componentName: string, configKey: string) => {
777
+ // if (configKey === 'maxFailedLoginAttempts') {
778
+ // return 3;
779
+ // }
780
+ // if (configKey === 'autoReleaseYN') {
781
+ // return 'N';
782
+ // }
783
+ // });
784
+
785
+ // // Act
786
+ // try {
787
+ // await loginUser['incrementFailedLoginAttemptCount'](dbTransaction);
788
+ // expect(false).toBe(true);
789
+ // } catch (error) {
790
+ // // Assert
791
+ // expect(LoginUser['_Repository'].update).toHaveBeenCalledWith(
792
+ // {
793
+ // FailedLoginAttemptCount: 4,
794
+ // LastFailedLoginAt: expect.any(Date),
795
+ // Status: UserStatus.LOCKED,
796
+ // },
797
+ // {
798
+ // where: {
799
+ // UserId: loginUser.UserId,
800
+ // },
801
+ // transaction: dbTransaction,
802
+ // },
803
+ // );
804
+ // expect(error).toBeInstanceOf(ClassError);
805
+ // expect(error.message).toBe(
806
+ // 'Your account has been locked due to too many failed login attempts, please contact IT Support for instructions on how to unlock your account',
807
+ // );
808
+ // }
809
+ // });
810
+ // });
811
+
812
+ // describe('combineSystemAccess', () => {
813
+ // it('should combine user and group system access and remove duplicates', async () => {
814
+ // // Mock the necessary dependencies
815
+ // const sessionService = await SessionService.init();
816
+ // const loginUser = await LoginUser.init(sessionService);
817
+ // const dbTransaction = null;
818
+ // const groups = [
819
+ // { InheritParentSystemAccessYN: true },
820
+ // { InheritParentSystemAccessYN: false },
821
+ // ];
822
+
823
+ // // Mock the necessary repository methods
824
+ // jest
825
+ // .spyOn(LoginUser as any, 'getInheritedSystemAccess')
826
+ // .mockResolvedValueOnce([
827
+ // { SystemCode: 'system1' },
828
+ // { SystemCode: 'system2' },
829
+ // ]);
830
+ // jest
831
+ // .spyOn((LoginUser as any)['_UserSystemAccessRepo'], 'findAll')
832
+ // .mockResolvedValueOnce([{ SystemCode: 'system3' }]);
833
+
834
+ // // Call the method
835
+ // const result = await LoginUser['combineSystemAccess'](
836
+ // loginUser,
837
+ // dbTransaction,
838
+ // groups,
839
+ // );
840
+
841
+ // // Assert the result
842
+ // expect(result).toEqual([
843
+ // { SystemCode: 'system3' },
844
+ // { SystemCode: 'system1' },
845
+ // { SystemCode: 'system2' },
846
+ // ]);
847
+ // });
848
+ // });
849
+
850
+ // describe('checkPrivileges', () => {
851
+ // it('should return true if user has the specified privilege', async () => {
852
+ // // Arrange
853
+ // const systemCode = 'SS';
854
+ // const privilegeName = 'Privilege 1';
855
+ // const sessionService = await SessionService.init();
856
+ // const loginUser = await LoginUser.init(sessionService);
857
+ // loginUser.ObjectId = '1';
858
+
859
+ // // Mock the necessary methods
860
+ // const rus = jest
861
+ // .spyOn(SessionService.prototype, 'retrieveUserSession')
862
+ // .mockResolvedValueOnce({
863
+ // systemLogins: [
864
+ // {
865
+ // id: '1',
866
+ // sessionId: 'sessionId',
867
+ // code: systemCode,
868
+ // privileges: [privilegeName],
869
+ // },
870
+ // ],
871
+ // });
872
+ // // Act
873
+ // const hasPrivilege = await loginUser.checkPrivileges(
874
+ // systemCode,
875
+ // privilegeName,
876
+ // );
877
+
878
+ // // Assert
879
+ // expect(hasPrivilege).toBe(true);
880
+ // expect(rus).toHaveBeenCalledWith(loginUser.ObjectId);
881
+ // });
882
+
883
+ // it('should return false if user does not have the specified privilege', async () => {
884
+ // // Arrange
885
+ // const systemCode = 'SS';
886
+ // const privilegeName = 'Privilege 1';
887
+ // const sessionService = await SessionService.init();
888
+ // const loginUser = await LoginUser.init(sessionService);
889
+ // loginUser.ObjectId = '1';
890
+
891
+ // // Mock the necessary methods
892
+ // const rus = jest
893
+ // .spyOn(SessionService.prototype, 'retrieveUserSession')
894
+ // .mockResolvedValueOnce({
895
+ // systemLogins: [
896
+ // {
897
+ // id: '1',
898
+ // sessionId: 'sessionId',
899
+ // code: systemCode,
900
+ // privileges: [],
901
+ // },
902
+ // ],
903
+ // });
904
+ // // Act
905
+ // const hasPrivilege = await loginUser.checkPrivileges(
906
+ // systemCode,
907
+ // privilegeName,
908
+ // );
909
+
910
+ // // Assert
911
+ // expect(hasPrivilege).toBe(false);
912
+ // expect(rus).toHaveBeenCalledWith(loginUser.ObjectId);
913
+ // });
914
+
915
+ // it('should throw an error if ObjectId is not set', async () => {
916
+ // // Arrange
917
+ // const systemCode = 'SS';
918
+ // const privilegeName = 'Privilege 1';
919
+ // const sessionService = await SessionService.init();
920
+ // const loginUser = await LoginUser.init(sessionService);
921
+ // loginUser.ObjectId = null;
922
+
923
+ // // Act & Assert
924
+ // await expect(
925
+ // loginUser.checkPrivileges(systemCode, privilegeName),
926
+ // ).rejects.toThrowError();
927
+ // });
928
+ // });
929
+
930
+ // describe('getObjectPrivileges', () => {
931
+ // it('should return an array of privileges', async () => {
932
+ // // Mock the dependencies and setup the test data
933
+ // const systemCode = 'system1';
934
+ // const dbTransaction = null;
935
+ // const sessionService = await SessionService.init();
936
+ // const loginUser = await LoginUser.init(sessionService);
937
+
938
+ // // Mock the UserObjectPrivilegeRepo findAll method
939
+ // const findAllMock = jest
940
+ // .spyOn(LoginUser['_UserObjectPrivilegeRepo'], 'findAll')
941
+ // .mockResolvedValue([
942
+ // {
943
+ // PrivilegeCode: 'privilege1',
944
+ // Privilege: {
945
+ // PrivilegeCode: 'privilege1',
946
+ // SystemCode: systemCode,
947
+ // Name: 'privilege1',
948
+ // },
949
+ // },
950
+ // {
951
+ // PrivilegeCode: 'privilege2',
952
+ // Privilege: {
953
+ // PrivilegeCode: 'privilege2',
954
+ // Name: 'privilege2',
955
+ // },
956
+ // },
957
+ // ] as any);
958
+
959
+ // // Call the getObjectPrivileges method
960
+ // const result = await loginUser['getObjectPrivileges'](
961
+ // systemCode,
962
+ // dbTransaction,
963
+ // );
964
+
965
+ // // Assertions
966
+ // expect(findAllMock).toHaveBeenCalledTimes(1);
967
+ // expect(findAllMock).toHaveBeenCalledWith({
968
+ // where: {
969
+ // UserId: loginUser.UserId,
970
+ // },
971
+ // include: {
972
+ // model: SystemPrivilegeModel,
973
+ // where: {
974
+ // SystemCode: systemCode,
975
+ // Status: 'Active',
976
+ // },
977
+ // },
978
+ // transaction: dbTransaction,
979
+ // });
980
+ // expect(result).toEqual(['privilege1', 'privilege2']);
981
+ // });
982
+
983
+ // it('should throw an error if an exception occurs', async () => {
984
+ // // Mock the dependencies and setup the test data
985
+ // const systemCode = 'system1';
986
+ // const dbTransaction = null;
987
+ // const sessionService = await SessionService.init();
988
+ // const loginUser = await LoginUser.init(sessionService);
989
+
990
+ // // Mock the UserObjectPrivilegeRepo findAll method to throw an error
991
+ // jest
992
+ // .spyOn(LoginUser['_UserObjectPrivilegeRepo'], 'findAll')
993
+ // .mockRejectedValue(new Error('Database error'));
994
+
995
+ // // Call the getObjectPrivileges method and expect it to throw an error
996
+ // await expect(
997
+ // loginUser['getObjectPrivileges'](systemCode, dbTransaction),
998
+ // ).rejects.toThrow(Error);
999
+ // });
1000
+ // });
1001
+
1002
+ // describe('getUserPersonalPrivileges', () => {
1003
+ // it('should return an array of privileges', async () => {
1004
+ // // Arrange
1005
+ // const sessionService = await SessionService.init();
1006
+ // const loginUser = await LoginUser.init(sessionService);
1007
+ // const systemCode = 'system1';
1008
+ // const dbTransaction = null;
1009
+
1010
+ // // Mock the findAll method of UserPrivilegeRepo
1011
+ // const findAllMock = jest.spyOn(
1012
+ // LoginUser['_UserPrivilegeRepo'],
1013
+ // 'findAll',
1014
+ // );
1015
+ // findAllMock.mockResolvedValue([
1016
+ // { Privilege: { Name: 'privilege1' } },
1017
+ // { Privilege: { Name: 'privilege2' } },
1018
+ // ] as any);
1019
+
1020
+ // // Act
1021
+ // const privileges = await loginUser['getUserPersonalPrivileges'](
1022
+ // systemCode,
1023
+ // dbTransaction,
1024
+ // );
1025
+
1026
+ // // Assert
1027
+ // expect(privileges).toEqual(['privilege1', 'privilege2']);
1028
+ // expect(findAllMock).toHaveBeenCalledTimes(1);
1029
+ // expect(findAllMock).toHaveBeenCalledWith({
1030
+ // where: {
1031
+ // UserId: loginUser.UserId,
1032
+ // Status: 'Active',
1033
+ // },
1034
+ // include: {
1035
+ // model: SystemPrivilegeModel,
1036
+ // where: {
1037
+ // SystemCode: systemCode,
1038
+ // Status: 'Active',
1039
+ // },
1040
+ // },
1041
+ // transaction: dbTransaction,
1042
+ // });
1043
+ // });
1044
+
1045
+ // it('should throw an error if an error occurs', async () => {
1046
+ // // Arrange
1047
+ // const sessionService = await SessionService.init();
1048
+ // const loginUser = await LoginUser.init(sessionService);
1049
+ // const systemCode = 'system1';
1050
+ // const dbTransaction = null;
1051
+
1052
+ // // Mock the findAll method of UserPrivilegeRepo to throw an error
1053
+ // const findAllMock = jest.spyOn(
1054
+ // LoginUser['_UserPrivilegeRepo'],
1055
+ // 'findAll',
1056
+ // );
1057
+ // findAllMock.mockRejectedValue(new Error('Database error'));
1058
+
1059
+ // // Act and Assert
1060
+ // await expect(
1061
+ // loginUser['getUserPersonalPrivileges'](systemCode, dbTransaction),
1062
+ // ).rejects.toThrow(Error);
1063
+
1064
+ // expect(findAllMock).toHaveBeenCalledTimes(1);
1065
+ // expect(findAllMock).toHaveBeenCalledWith({
1066
+ // where: {
1067
+ // UserId: loginUser.UserId,
1068
+ // Status: 'Active',
1069
+ // },
1070
+ // include: {
1071
+ // model: SystemPrivilegeModel,
1072
+ // where: {
1073
+ // SystemCode: systemCode,
1074
+ // Status: 'Active',
1075
+ // },
1076
+ // },
1077
+ // transaction: dbTransaction,
1078
+ // });
1079
+ // });
1080
+ // });
1081
+
1082
+ // describe('getInheritedSystemAccess', () => {
1083
+ // it('should return group system access with its parent group system access if applicable', async () => {
1084
+ // // Mock the necessary dependencies
1085
+ // const dbTransaction = null;
1086
+ // const group = {
1087
+ // GroupCode: 'group1',
1088
+ // InheritParentPrivilegeYN: 'Y',
1089
+ // ParentGroupCode: 'parentGroup',
1090
+ // } as any;
1091
+ // const parentGroup = {
1092
+ // GroupCode: 'parentGroup',
1093
+ // InheritParentPrivilegeYN: 'N',
1094
+ // ParentGroupCode: null,
1095
+ // } as any;
1096
+
1097
+ // const systemAccess = [
1098
+ // {
1099
+ // SystemCode: 'system1',
1100
+ // GroupCode: 'group1',
1101
+ // System: { SystemCode: 'system1' },
1102
+ // },
1103
+ // {
1104
+ // SystemCode: 'system2',
1105
+ // GroupCode: 'group1',
1106
+ // System: { SystemCode: 'system1' },
1107
+ // },
1108
+ // ] as any;
1109
+
1110
+ // const parentSystemAccess = [
1111
+ // {
1112
+ // SystemCode: 'system3',
1113
+ // GroupCode: 'parentGroup',
1114
+ // System: { SystemCode: 'system3' },
1115
+ // },
1116
+ // ] as any;
1117
+
1118
+ // // Mock the necessary repository methods
1119
+ // const groupFindByPkMock = jest
1120
+ // .spyOn(GroupRepository.prototype, 'findByPk')
1121
+ // .mockResolvedValueOnce(parentGroup as any);
1122
+ // const systemAccessFindAllMock = jest
1123
+ // .spyOn(GroupSystemAccessRepository.prototype, 'findAll')
1124
+ // .mockImplementation((options: any) => {
1125
+ // if (options.where.GroupCode === group.GroupCode) {
1126
+ // return Promise.resolve(systemAccess);
1127
+ // } else if (options.where.GroupCode === parentGroup.GroupCode) {
1128
+ // return Promise.resolve(parentSystemAccess);
1129
+ // }
1130
+ // });
1131
+
1132
+ // // Call the method
1133
+ // const result = await LoginUser['getInheritedSystemAccess'](
1134
+ // dbTransaction,
1135
+ // group,
1136
+ // );
1137
+
1138
+ // console.log(result);
1139
+ // // Assert the result
1140
+ // expect(result).toEqual([
1141
+ // {
1142
+ // SystemCode: 'system1',
1143
+ // GroupCode: 'group1',
1144
+ // System: { SystemCode: 'system1' },
1145
+ // },
1146
+ // {
1147
+ // SystemCode: 'system2',
1148
+ // GroupCode: 'group1',
1149
+ // System: { SystemCode: 'system1' },
1150
+ // },
1151
+ // {
1152
+ // SystemCode: 'system3',
1153
+ // GroupCode: 'parentGroup',
1154
+ // System: { SystemCode: 'system3' },
1155
+ // },
1156
+ // ]);
1157
+ // expect(groupFindByPkMock).toHaveBeenCalledWith(
1158
+ // group.ParentGroupCode,
1159
+ // dbTransaction,
1160
+ // );
1161
+ // expect(systemAccessFindAllMock).toHaveBeenCalledTimes(2);
1162
+ // });
1163
+ // });
1164
+ // });