@flusys/nestjs-shared 7.1.0 → 8.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (338) hide show
  1. package/classes/api-controller.class.d.ts +4 -4
  2. package/classes/api-service.class.d.ts +7 -7
  3. package/classes/disabled-event-bus.class.d.ts +1 -1
  4. package/classes/domain-event.publisher.d.ts +1 -1
  5. package/classes/event-bus.registry.d.ts +1 -1
  6. package/classes/event-transports/event-transport.registry.d.ts +1 -1
  7. package/classes/event-transports/index.d.ts +2 -2
  8. package/classes/event-transports/kafka-transport.optional.d.ts +1 -1
  9. package/classes/event-transports/memory-transport.d.ts +1 -1
  10. package/classes/event-transports/rabbitmq-transport.optional.d.ts +1 -1
  11. package/classes/hybrid-event-bus.class.d.ts +1 -1
  12. package/classes/index.d.ts +11 -11
  13. package/constants/index.d.ts +2 -2
  14. package/decorators/api-response.decorator.d.ts +1 -1
  15. package/decorators/current-user.decorator.d.ts +1 -1
  16. package/decorators/index.d.ts +6 -6
  17. package/decorators/require-permission.decorator.d.ts +1 -1
  18. package/dtos/filter-and-pagination.dto.d.ts +1 -1
  19. package/dtos/index.d.ts +6 -6
  20. package/entities/index.d.ts +3 -3
  21. package/enums/index.d.ts +3 -3
  22. package/exceptions/index.d.ts +2 -2
  23. package/fesm/470.js +2713 -0
  24. package/fesm/509.js +793 -0
  25. package/fesm/667.js +606 -0
  26. package/fesm/67.js +808 -0
  27. package/fesm/720.js +914 -0
  28. package/{cjs/classes/event-transports/rabbitmq-transport.optional.js → fesm/chunks/123.js} +78 -55
  29. package/fesm/{classes/event-transports/kafka-transport.optional.js → chunks/37.js} +74 -41
  30. package/fesm/classes/index.js +62 -12
  31. package/fesm/constants/index.js +445 -17
  32. package/fesm/decorators/index.js +341 -6
  33. package/fesm/dtos/index.js +23 -6
  34. package/fesm/entities/index.js +336 -3
  35. package/fesm/enums/index.js +57 -3
  36. package/fesm/exceptions/index.js +280 -2
  37. package/fesm/guards/index.js +1003 -3
  38. package/fesm/index.js +1524 -14
  39. package/fesm/interceptors/index.js +924 -5
  40. package/fesm/interfaces/index.js +57 -11
  41. package/fesm/middlewares/index.js +33 -1
  42. package/fesm/modules/index.js +432 -9
  43. package/fesm/runtime.js +134 -0
  44. package/fesm/utils/index.js +1045 -8
  45. package/filters/global-exception.filter.d.ts +1 -1
  46. package/filters/index.d.ts +1 -1
  47. package/guards/index.d.ts +3 -3
  48. package/guards/jwt-auth.guard.d.ts +1 -1
  49. package/guards/optional-jwt-auth.guard.d.ts +1 -1
  50. package/guards/permission.guard.d.ts +2 -2
  51. package/index.d.ts +14 -14
  52. package/interceptors/delete-empty-id-from-body.interceptor.d.ts +1 -1
  53. package/interceptors/idempotency.interceptor.d.ts +2 -2
  54. package/interceptors/index.d.ts +5 -5
  55. package/interceptors/response-meta.interceptor.d.ts +1 -1
  56. package/interceptors/set-user-field-on-body.interceptor.d.ts +1 -1
  57. package/interceptors/slug.interceptor.d.ts +2 -2
  58. package/interfaces/ai-assistant-adapter.interface.d.ts +1 -1
  59. package/interfaces/api.interface.d.ts +2 -2
  60. package/interfaces/datasource.interface.d.ts +1 -1
  61. package/interfaces/event-manager-adapter.interface.d.ts +2 -2
  62. package/interfaces/index.d.ts +11 -11
  63. package/interfaces/module-config.interface.d.ts +1 -1
  64. package/interfaces/notification-adapter.interface.d.ts +1 -1
  65. package/middlewares/index.d.ts +1 -1
  66. package/middlewares/logger.middleware.d.ts +2 -2
  67. package/modules/cache/cache.module.d.ts +1 -1
  68. package/modules/datasource/index.d.ts +1 -1
  69. package/modules/datasource/multi-tenant-datasource.service.d.ts +4 -4
  70. package/modules/event-bus/event-bus.explorer.d.ts +2 -2
  71. package/modules/event-bus/event-bus.module.d.ts +2 -2
  72. package/modules/event-bus/module-events.provider.d.ts +1 -1
  73. package/modules/index.d.ts +9 -9
  74. package/modules/shared-permission-cache/shared-permission-cache.service.d.ts +3 -3
  75. package/modules/utils/utils.service.d.ts +1 -1
  76. package/package.json +30 -44
  77. package/utils/index.d.ts +8 -8
  78. package/utils/permission-cache-key.util.d.ts +1 -1
  79. package/utils/query-helpers.util.d.ts +2 -2
  80. package/utils/request.util.d.ts +1 -1
  81. package/cjs/classes/api-controller.class.js +0 -728
  82. package/cjs/classes/api-controller.class.spec.js +0 -684
  83. package/cjs/classes/api-service.class.js +0 -631
  84. package/cjs/classes/api-service.class.spec.js +0 -1137
  85. package/cjs/classes/disabled-event-bus.class.js +0 -15
  86. package/cjs/classes/disabled-event-bus.class.spec.js +0 -40
  87. package/cjs/classes/domain-event.publisher.js +0 -76
  88. package/cjs/classes/domain-event.publisher.spec.js +0 -234
  89. package/cjs/classes/event-bus.registry.js +0 -68
  90. package/cjs/classes/event-bus.registry.spec.js +0 -141
  91. package/cjs/classes/event-transports/event-transport.registry.js +0 -41
  92. package/cjs/classes/event-transports/event-transport.registry.spec.js +0 -31
  93. package/cjs/classes/event-transports/index.js +0 -23
  94. package/cjs/classes/event-transports/kafka-transport.optional.js +0 -151
  95. package/cjs/classes/event-transports/kafka-transport.optional.spec.js +0 -198
  96. package/cjs/classes/event-transports/memory-transport.js +0 -53
  97. package/cjs/classes/event-transports/memory-transport.spec.js +0 -57
  98. package/cjs/classes/event-transports/rabbitmq-transport.optional.spec.js +0 -255
  99. package/cjs/classes/handle-custome-db.js +0 -37
  100. package/cjs/classes/handle-custome-db.spec.js +0 -82
  101. package/cjs/classes/hybrid-cache.class.js +0 -96
  102. package/cjs/classes/hybrid-cache.class.spec.js +0 -168
  103. package/cjs/classes/hybrid-event-bus.class.js +0 -281
  104. package/cjs/classes/hybrid-event-bus.class.spec.js +0 -218
  105. package/cjs/classes/index.js +0 -28
  106. package/cjs/classes/winston.logger.class.js +0 -274
  107. package/cjs/classes/winston.logger.class.spec.js +0 -330
  108. package/cjs/constants/index.js +0 -88
  109. package/cjs/constants/message-keys.js +0 -68
  110. package/cjs/constants/permissions.js +0 -307
  111. package/cjs/decorators/api-response.decorator.js +0 -52
  112. package/cjs/decorators/api-response.decorator.spec.js +0 -126
  113. package/cjs/decorators/current-user.decorator.js +0 -16
  114. package/cjs/decorators/current-user.decorator.spec.js +0 -74
  115. package/cjs/decorators/index.js +0 -23
  116. package/cjs/decorators/log-action.decorator.js +0 -149
  117. package/cjs/decorators/log-action.decorator.spec.js +0 -353
  118. package/cjs/decorators/on-domain-event.decorator.js +0 -13
  119. package/cjs/decorators/on-domain-event.decorator.spec.js +0 -50
  120. package/cjs/decorators/public.decorator.js +0 -13
  121. package/cjs/decorators/public.decorator.spec.js +0 -50
  122. package/cjs/decorators/require-permission.decorator.js +0 -32
  123. package/cjs/decorators/require-permission.decorator.spec.js +0 -147
  124. package/cjs/dtos/delete.dto.js +0 -92
  125. package/cjs/dtos/filter-and-pagination.dto.js +0 -164
  126. package/cjs/dtos/get-by-ids.dto.js +0 -65
  127. package/cjs/dtos/identity-response.dto.js +0 -108
  128. package/cjs/dtos/index.js +0 -23
  129. package/cjs/dtos/pagination.dto.js +0 -67
  130. package/cjs/dtos/response-payload.dto.js +0 -369
  131. package/cjs/entities/identity.js +0 -100
  132. package/cjs/entities/index.js +0 -20
  133. package/cjs/entities/raw-type.js +0 -4
  134. package/cjs/entities/user-root.js +0 -189
  135. package/cjs/enums/index.js +0 -20
  136. package/cjs/enums/notification-type.enum.js +0 -17
  137. package/cjs/enums/participant-status.enum.js +0 -17
  138. package/cjs/enums/recurrence-type.enum.js +0 -18
  139. package/cjs/exceptions/base-app.exception.js +0 -151
  140. package/cjs/exceptions/base-app.exception.spec.js +0 -157
  141. package/cjs/exceptions/index.js +0 -19
  142. package/cjs/exceptions/permission.exception.js +0 -56
  143. package/cjs/exceptions/permission.exception.spec.js +0 -82
  144. package/cjs/filters/global-exception.filter.js +0 -279
  145. package/cjs/filters/global-exception.filter.spec.js +0 -440
  146. package/cjs/filters/index.js +0 -18
  147. package/cjs/guards/index.js +0 -20
  148. package/cjs/guards/jwt-auth.guard.js +0 -75
  149. package/cjs/guards/jwt-auth.guard.spec.js +0 -75
  150. package/cjs/guards/optional-jwt-auth.guard.js +0 -67
  151. package/cjs/guards/optional-jwt-auth.guard.spec.js +0 -55
  152. package/cjs/guards/permission.guard.js +0 -179
  153. package/cjs/guards/permission.guard.spec.js +0 -373
  154. package/cjs/index.js +0 -31
  155. package/cjs/interceptors/delete-empty-id-from-body.interceptor.js +0 -40
  156. package/cjs/interceptors/delete-empty-id-from-body.interceptor.spec.js +0 -107
  157. package/cjs/interceptors/idempotency.interceptor.js +0 -96
  158. package/cjs/interceptors/idempotency.interceptor.spec.js +0 -116
  159. package/cjs/interceptors/index.js +0 -22
  160. package/cjs/interceptors/response-meta.interceptor.js +0 -47
  161. package/cjs/interceptors/response-meta.interceptor.spec.js +0 -89
  162. package/cjs/interceptors/set-user-field-on-body.interceptor.js +0 -60
  163. package/cjs/interceptors/set-user-field-on-body.interceptor.spec.js +0 -128
  164. package/cjs/interceptors/slug.interceptor.js +0 -75
  165. package/cjs/interceptors/slug.interceptor.spec.js +0 -110
  166. package/cjs/interfaces/ai-assistant-adapter.interface.js +0 -24
  167. package/cjs/interfaces/api.interface.js +0 -4
  168. package/cjs/interfaces/datasource.interface.js +0 -4
  169. package/cjs/interfaces/event-bus.interface.js +0 -4
  170. package/cjs/interfaces/event-manager-adapter.interface.js +0 -11
  171. package/cjs/interfaces/identity.interface.js +0 -4
  172. package/cjs/interfaces/index.js +0 -28
  173. package/cjs/interfaces/logged-user-info.interface.js +0 -6
  174. package/cjs/interfaces/module-config.interface.js +0 -4
  175. package/cjs/interfaces/notification-adapter.interface.js +0 -11
  176. package/cjs/interfaces/permission-sync-adapter.interface.js +0 -11
  177. package/cjs/interfaces/permission.interface.js +0 -4
  178. package/cjs/middlewares/index.js +0 -18
  179. package/cjs/middlewares/logger.middleware.js +0 -264
  180. package/cjs/middlewares/logger.middleware.spec.js +0 -462
  181. package/cjs/modules/cache/cache.module.js +0 -39
  182. package/cjs/modules/cache/cache.module.spec.js +0 -48
  183. package/cjs/modules/datasource/index.js +0 -18
  184. package/cjs/modules/datasource/multi-tenant-datasource.service.js +0 -222
  185. package/cjs/modules/datasource/multi-tenant-datasource.service.spec.js +0 -381
  186. package/cjs/modules/event-bus/event-bus.explorer.js +0 -124
  187. package/cjs/modules/event-bus/event-bus.explorer.spec.js +0 -189
  188. package/cjs/modules/event-bus/event-bus.integration.spec.js +0 -253
  189. package/cjs/modules/event-bus/event-bus.module.js +0 -94
  190. package/cjs/modules/event-bus/event-bus.module.spec.js +0 -149
  191. package/cjs/modules/event-bus/module-events.provider.js +0 -39
  192. package/cjs/modules/event-bus/module-events.provider.spec.js +0 -56
  193. package/cjs/modules/index.js +0 -26
  194. package/cjs/modules/shared-permission-cache/shared-permission-cache.module.js +0 -32
  195. package/cjs/modules/shared-permission-cache/shared-permission-cache.service.js +0 -101
  196. package/cjs/modules/shared-permission-cache/shared-permission-cache.service.spec.js +0 -165
  197. package/cjs/modules/utils/utils.module.js +0 -32
  198. package/cjs/modules/utils/utils.service.js +0 -76
  199. package/cjs/modules/utils/utils.service.spec.js +0 -169
  200. package/cjs/utils/date-time.util.js +0 -94
  201. package/cjs/utils/date-time.util.spec.js +0 -84
  202. package/cjs/utils/event-pattern.util.js +0 -103
  203. package/cjs/utils/event-pattern.util.spec.js +0 -251
  204. package/cjs/utils/html-sanitizer.util.js +0 -64
  205. package/cjs/utils/html-sanitizer.util.spec.js +0 -76
  206. package/cjs/utils/index.js +0 -25
  207. package/cjs/utils/optional-module.util.js +0 -35
  208. package/cjs/utils/optional-module.util.spec.js +0 -14
  209. package/cjs/utils/permission-cache-key.util.js +0 -31
  210. package/cjs/utils/permission-cache-key.util.spec.js +0 -88
  211. package/cjs/utils/query-helpers.util.js +0 -60
  212. package/cjs/utils/query-helpers.util.spec.js +0 -209
  213. package/cjs/utils/request.util.js +0 -96
  214. package/cjs/utils/request.util.spec.js +0 -249
  215. package/cjs/utils/string.util.js +0 -63
  216. package/cjs/utils/string.util.spec.js +0 -63
  217. package/fesm/classes/api-controller.class.js +0 -718
  218. package/fesm/classes/api-controller.class.spec.js +0 -680
  219. package/fesm/classes/api-service.class.js +0 -621
  220. package/fesm/classes/api-service.class.spec.js +0 -1133
  221. package/fesm/classes/disabled-event-bus.class.js +0 -11
  222. package/fesm/classes/disabled-event-bus.class.spec.js +0 -36
  223. package/fesm/classes/domain-event.publisher.js +0 -63
  224. package/fesm/classes/domain-event.publisher.spec.js +0 -230
  225. package/fesm/classes/event-bus.registry.js +0 -64
  226. package/fesm/classes/event-bus.registry.spec.js +0 -137
  227. package/fesm/classes/event-transports/event-transport.registry.js +0 -35
  228. package/fesm/classes/event-transports/event-transport.registry.spec.js +0 -27
  229. package/fesm/classes/event-transports/index.js +0 -6
  230. package/fesm/classes/event-transports/kafka-transport.optional.spec.js +0 -194
  231. package/fesm/classes/event-transports/memory-transport.js +0 -49
  232. package/fesm/classes/event-transports/memory-transport.spec.js +0 -53
  233. package/fesm/classes/event-transports/rabbitmq-transport.optional.js +0 -174
  234. package/fesm/classes/event-transports/rabbitmq-transport.optional.spec.js +0 -251
  235. package/fesm/classes/handle-custome-db.js +0 -19
  236. package/fesm/classes/handle-custome-db.spec.js +0 -78
  237. package/fesm/classes/hybrid-cache.class.js +0 -81
  238. package/fesm/classes/hybrid-cache.class.spec.js +0 -164
  239. package/fesm/classes/hybrid-event-bus.class.js +0 -237
  240. package/fesm/classes/hybrid-event-bus.class.spec.js +0 -214
  241. package/fesm/classes/winston.logger.class.js +0 -228
  242. package/fesm/classes/winston.logger.class.spec.js +0 -327
  243. package/fesm/constants/message-keys.js +0 -49
  244. package/fesm/constants/permissions.js +0 -215
  245. package/fesm/decorators/api-response.decorator.js +0 -42
  246. package/fesm/decorators/api-response.decorator.spec.js +0 -122
  247. package/fesm/decorators/current-user.decorator.js +0 -18
  248. package/fesm/decorators/current-user.decorator.spec.js +0 -73
  249. package/fesm/decorators/log-action.decorator.js +0 -139
  250. package/fesm/decorators/log-action.decorator.spec.js +0 -349
  251. package/fesm/decorators/on-domain-event.decorator.js +0 -10
  252. package/fesm/decorators/on-domain-event.decorator.spec.js +0 -46
  253. package/fesm/decorators/public.decorator.js +0 -20
  254. package/fesm/decorators/public.decorator.spec.js +0 -46
  255. package/fesm/decorators/require-permission.decorator.js +0 -27
  256. package/fesm/decorators/require-permission.decorator.spec.js +0 -143
  257. package/fesm/dtos/delete.dto.js +0 -82
  258. package/fesm/dtos/filter-and-pagination.dto.js +0 -148
  259. package/fesm/dtos/get-by-ids.dto.js +0 -55
  260. package/fesm/dtos/identity-response.dto.js +0 -98
  261. package/fesm/dtos/pagination.dto.js +0 -57
  262. package/fesm/dtos/response-payload.dto.js +0 -336
  263. package/fesm/entities/identity.js +0 -90
  264. package/fesm/entities/raw-type.js +0 -1
  265. package/fesm/entities/user-root.js +0 -179
  266. package/fesm/enums/notification-type.enum.js +0 -7
  267. package/fesm/enums/participant-status.enum.js +0 -7
  268. package/fesm/enums/recurrence-type.enum.js +0 -8
  269. package/fesm/exceptions/base-app.exception.js +0 -115
  270. package/fesm/exceptions/base-app.exception.spec.js +0 -153
  271. package/fesm/exceptions/permission.exception.js +0 -35
  272. package/fesm/exceptions/permission.exception.spec.js +0 -78
  273. package/fesm/filters/global-exception.filter.js +0 -269
  274. package/fesm/filters/global-exception.filter.spec.js +0 -436
  275. package/fesm/filters/index.js +0 -1
  276. package/fesm/guards/jwt-auth.guard.js +0 -65
  277. package/fesm/guards/jwt-auth.guard.spec.js +0 -71
  278. package/fesm/guards/optional-jwt-auth.guard.js +0 -57
  279. package/fesm/guards/optional-jwt-auth.guard.spec.js +0 -51
  280. package/fesm/guards/permission.guard.js +0 -169
  281. package/fesm/guards/permission.guard.spec.js +0 -369
  282. package/fesm/interceptors/delete-empty-id-from-body.interceptor.js +0 -30
  283. package/fesm/interceptors/delete-empty-id-from-body.interceptor.spec.js +0 -103
  284. package/fesm/interceptors/idempotency.interceptor.js +0 -86
  285. package/fesm/interceptors/idempotency.interceptor.spec.js +0 -112
  286. package/fesm/interceptors/response-meta.interceptor.js +0 -37
  287. package/fesm/interceptors/response-meta.interceptor.spec.js +0 -85
  288. package/fesm/interceptors/set-user-field-on-body.interceptor.js +0 -39
  289. package/fesm/interceptors/set-user-field-on-body.interceptor.spec.js +0 -124
  290. package/fesm/interceptors/slug.interceptor.js +0 -65
  291. package/fesm/interceptors/slug.interceptor.spec.js +0 -106
  292. package/fesm/interfaces/ai-assistant-adapter.interface.js +0 -3
  293. package/fesm/interfaces/api.interface.js +0 -1
  294. package/fesm/interfaces/datasource.interface.js +0 -1
  295. package/fesm/interfaces/event-bus.interface.js +0 -1
  296. package/fesm/interfaces/event-manager-adapter.interface.js +0 -1
  297. package/fesm/interfaces/identity.interface.js +0 -1
  298. package/fesm/interfaces/logged-user-info.interface.js +0 -3
  299. package/fesm/interfaces/module-config.interface.js +0 -5
  300. package/fesm/interfaces/notification-adapter.interface.js +0 -1
  301. package/fesm/interfaces/permission-sync-adapter.interface.js +0 -1
  302. package/fesm/interfaces/permission.interface.js +0 -1
  303. package/fesm/middlewares/logger.middleware.js +0 -235
  304. package/fesm/middlewares/logger.middleware.spec.js +0 -459
  305. package/fesm/modules/cache/cache.module.js +0 -29
  306. package/fesm/modules/cache/cache.module.spec.js +0 -44
  307. package/fesm/modules/datasource/index.js +0 -1
  308. package/fesm/modules/datasource/multi-tenant-datasource.service.js +0 -212
  309. package/fesm/modules/datasource/multi-tenant-datasource.service.spec.js +0 -377
  310. package/fesm/modules/event-bus/event-bus.explorer.js +0 -114
  311. package/fesm/modules/event-bus/event-bus.explorer.spec.js +0 -185
  312. package/fesm/modules/event-bus/event-bus.integration.spec.js +0 -249
  313. package/fesm/modules/event-bus/event-bus.module.js +0 -84
  314. package/fesm/modules/event-bus/event-bus.module.spec.js +0 -145
  315. package/fesm/modules/event-bus/module-events.provider.js +0 -26
  316. package/fesm/modules/event-bus/module-events.provider.spec.js +0 -52
  317. package/fesm/modules/shared-permission-cache/shared-permission-cache.module.js +0 -22
  318. package/fesm/modules/shared-permission-cache/shared-permission-cache.service.js +0 -91
  319. package/fesm/modules/shared-permission-cache/shared-permission-cache.service.spec.js +0 -161
  320. package/fesm/modules/utils/utils.module.js +0 -22
  321. package/fesm/modules/utils/utils.service.js +0 -66
  322. package/fesm/modules/utils/utils.service.spec.js +0 -165
  323. package/fesm/utils/date-time.util.js +0 -70
  324. package/fesm/utils/date-time.util.spec.js +0 -80
  325. package/fesm/utils/event-pattern.util.js +0 -91
  326. package/fesm/utils/event-pattern.util.spec.js +0 -247
  327. package/fesm/utils/html-sanitizer.util.js +0 -69
  328. package/fesm/utils/html-sanitizer.util.spec.js +0 -72
  329. package/fesm/utils/optional-module.util.js +0 -25
  330. package/fesm/utils/optional-module.util.spec.js +0 -10
  331. package/fesm/utils/permission-cache-key.util.js +0 -10
  332. package/fesm/utils/permission-cache-key.util.spec.js +0 -84
  333. package/fesm/utils/query-helpers.util.js +0 -85
  334. package/fesm/utils/query-helpers.util.spec.js +0 -205
  335. package/fesm/utils/request.util.js +0 -81
  336. package/fesm/utils/request.util.spec.js +0 -245
  337. package/fesm/utils/string.util.js +0 -71
  338. package/fesm/utils/string.util.spec.js +0 -59
@@ -1,440 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- const _common = require("@nestjs/common");
6
- const _typeorm = require("typeorm");
7
- const _globalexceptionfilter = require("./global-exception.filter");
8
- const _baseappexception = require("../exceptions/base-app.exception");
9
- const _messagekeys = require("../constants/message-keys");
10
- const mockGetRequestId = jest.fn();
11
- const mockGetUserId = jest.fn();
12
- const mockGetTenantId = jest.fn();
13
- const mockGetCompanyId = jest.fn();
14
- jest.mock('../middlewares/logger.middleware', ()=>({
15
- getRequestId: (...args)=>mockGetRequestId(...args),
16
- getUserId: (...args)=>mockGetUserId(...args),
17
- getTenantId: (...args)=>mockGetTenantId(...args),
18
- getCompanyId: (...args)=>mockGetCompanyId(...args)
19
- }));
20
- function makeQueryFailedError(driverError, message = 'db error') {
21
- const err = new _typeorm.QueryFailedError('SELECT 1', [], new Error(message));
22
- Object.assign(err, driverError);
23
- return err;
24
- }
25
- describe('GlobalExceptionFilter', ()=>{
26
- let filter;
27
- let errorSpy;
28
- let warnSpy;
29
- let request;
30
- let response;
31
- let host;
32
- beforeEach(()=>{
33
- jest.clearAllMocks();
34
- filter = new _globalexceptionfilter.GlobalExceptionFilter();
35
- errorSpy = jest.spyOn(_common.Logger.prototype, 'error').mockImplementation(()=>undefined);
36
- warnSpy = jest.spyOn(_common.Logger.prototype, 'warn').mockImplementation(()=>undefined);
37
- jest.spyOn(_common.Logger.prototype, 'log').mockImplementation(()=>undefined);
38
- mockGetRequestId.mockReturnValue(undefined);
39
- mockGetUserId.mockReturnValue(undefined);
40
- mockGetTenantId.mockReturnValue(undefined);
41
- mockGetCompanyId.mockReturnValue(undefined);
42
- request = {
43
- headers: {},
44
- method: 'GET',
45
- originalUrl: '/api/users',
46
- path: '/api/users'
47
- };
48
- response = {
49
- status: jest.fn().mockReturnThis(),
50
- json: jest.fn()
51
- };
52
- host = {
53
- switchToHttp: ()=>({
54
- getRequest: ()=>request,
55
- getResponse: ()=>response
56
- })
57
- };
58
- });
59
- afterEach(()=>{
60
- errorSpy.mockRestore();
61
- warnSpy.mockRestore();
62
- });
63
- describe('request id resolution', ()=>{
64
- it('should prefer the AsyncLocalStorage request id', ()=>{
65
- mockGetRequestId.mockReturnValue('ctx-request-id');
66
- request.headers['x-request-id'] = 'header-request-id';
67
- filter.catch(new Error('boom'), host);
68
- const payload = response.json.mock.calls[0][0];
69
- expect(payload._meta.requestId).toBe('ctx-request-id');
70
- });
71
- it('should fall back to the x-request-id header', ()=>{
72
- request.headers['x-request-id'] = 'header-request-id';
73
- filter.catch(new Error('boom'), host);
74
- expect(response.json.mock.calls[0][0]._meta.requestId).toBe('header-request-id');
75
- });
76
- it('should default to "no-request-id" when nothing is available', ()=>{
77
- filter.catch(new Error('boom'), host);
78
- expect(response.json.mock.calls[0][0]._meta.requestId).toBe('no-request-id');
79
- });
80
- });
81
- describe('BaseAppException handling', ()=>{
82
- it('should use the exception status, message, messageKey, and variables', ()=>{
83
- const exception = new _baseappexception.ConflictException('User', 'email');
84
- filter.catch(exception, host);
85
- expect(response.status).toHaveBeenCalledWith(_common.HttpStatus.CONFLICT);
86
- const payload = response.json.mock.calls[0][0];
87
- expect(payload).toMatchObject({
88
- success: false,
89
- message: 'User with this email already exists',
90
- messageKey: _messagekeys.ERROR_MESSAGES.CONFLICT,
91
- messageVariables: {
92
- entity: 'User',
93
- field: 'email'
94
- }
95
- });
96
- });
97
- it('should include validation errors when present', ()=>{
98
- const exception = new _baseappexception.BaseAppException({
99
- message: 'Validation failed',
100
- messageKey: _messagekeys.ERROR_MESSAGES.VALIDATION,
101
- status: _common.HttpStatus.BAD_REQUEST,
102
- errors: [
103
- {
104
- field: 'email',
105
- message: 'must be an email'
106
- }
107
- ]
108
- });
109
- filter.catch(exception, host);
110
- const payload = response.json.mock.calls[0][0];
111
- expect(payload.errors).toEqual([
112
- {
113
- field: 'email',
114
- message: 'must be an email'
115
- }
116
- ]);
117
- });
118
- });
119
- describe('HttpException handling', ()=>{
120
- it('should use the string response body as the message', ()=>{
121
- const exception = new _common.HttpException('Not allowed', _common.HttpStatus.FORBIDDEN);
122
- filter.catch(exception, host);
123
- expect(response.status).toHaveBeenCalledWith(_common.HttpStatus.FORBIDDEN);
124
- const payload = response.json.mock.calls[0][0];
125
- expect(payload.message).toBe('Not allowed');
126
- expect(payload.messageKey).toBe(_messagekeys.ERROR_MESSAGES.HTTP);
127
- });
128
- it('should convert an array of validation messages into structured errors', ()=>{
129
- const exception = new _common.HttpException({
130
- message: [
131
- 'email must be a valid email',
132
- 'age must not be less than 0'
133
- ]
134
- }, _common.HttpStatus.BAD_REQUEST);
135
- filter.catch(exception, host);
136
- const payload = response.json.mock.calls[0][0];
137
- expect(payload.message).toBe('Validation failed');
138
- expect(payload.messageKey).toBe(_messagekeys.ERROR_MESSAGES.VALIDATION);
139
- expect(payload.errors).toEqual([
140
- {
141
- field: 'email',
142
- message: 'must be a valid email'
143
- },
144
- {
145
- field: 'age',
146
- message: 'must not be less than 0'
147
- }
148
- ]);
149
- });
150
- it('should fall back the message when a validation message has no spaces', ()=>{
151
- const exception = new _common.HttpException({
152
- message: [
153
- 'required'
154
- ]
155
- }, _common.HttpStatus.BAD_REQUEST);
156
- filter.catch(exception, host);
157
- const payload = response.json.mock.calls[0][0];
158
- expect(payload.errors).toEqual([
159
- {
160
- field: 'required',
161
- message: 'required'
162
- }
163
- ]);
164
- });
165
- it('should use the object messageKey/messageVariables/errors when present', ()=>{
166
- const exception = new _common.HttpException({
167
- message: 'Custom message',
168
- messageKey: 'custom.key',
169
- messageVariables: {
170
- foo: 'bar'
171
- },
172
- errors: [
173
- {
174
- field: 'x',
175
- message: 'y'
176
- }
177
- ]
178
- }, _common.HttpStatus.BAD_REQUEST);
179
- filter.catch(exception, host);
180
- const payload = response.json.mock.calls[0][0];
181
- expect(payload).toMatchObject({
182
- message: 'Custom message',
183
- messageKey: 'custom.key',
184
- messageVariables: {
185
- foo: 'bar'
186
- },
187
- errors: [
188
- {
189
- field: 'x',
190
- message: 'y'
191
- }
192
- ]
193
- });
194
- });
195
- it('should default to Unknown error/HTTP messageKey when the object has no message', ()=>{
196
- const exception = new _common.HttpException({}, _common.HttpStatus.BAD_REQUEST);
197
- filter.catch(exception, host);
198
- const payload = response.json.mock.calls[0][0];
199
- expect(payload.message).toBe('Unknown error');
200
- expect(payload.messageKey).toBe(_messagekeys.ERROR_MESSAGES.HTTP);
201
- });
202
- it('should handle a non-string/non-object response body', ()=>{
203
- const exception = new _common.HttpException(42, _common.HttpStatus.BAD_REQUEST);
204
- filter.catch(exception, host);
205
- const payload = response.json.mock.calls[0][0];
206
- expect(payload.message).toBe('Unknown error');
207
- expect(payload.messageKey).toBe(_messagekeys.ERROR_MESSAGES.UNKNOWN);
208
- });
209
- });
210
- describe('QueryFailedError handling', ()=>{
211
- it('should map a postgres unique violation (23505) to a conflict', ()=>{
212
- const exception = makeQueryFailedError({
213
- driverError: {
214
- code: '23505',
215
- detail: 'Key (email)=(a@b.com) already exists.',
216
- table: 'users'
217
- }
218
- });
219
- filter.catch(exception, host);
220
- expect(response.status).toHaveBeenCalledWith(_common.HttpStatus.CONFLICT);
221
- const payload = response.json.mock.calls[0][0];
222
- expect(payload.messageKey).toBe(_messagekeys.ERROR_MESSAGES.CONFLICT);
223
- expect(payload.message).toContain('Email');
224
- });
225
- it('should map a mysql duplicate entry (ER_DUP_ENTRY) to a conflict using the sqlMessage key name', ()=>{
226
- const exception = makeQueryFailedError({
227
- driverError: {
228
- code: 'ER_DUP_ENTRY',
229
- sqlMessage: "Duplicate entry 'a@b.com' for key 'users.email_UNIQUE'",
230
- table: 'users'
231
- }
232
- });
233
- filter.catch(exception, host);
234
- const payload = response.json.mock.calls[0][0];
235
- expect(payload.messageKey).toBe(_messagekeys.ERROR_MESSAGES.CONFLICT);
236
- });
237
- it('should map an mssql duplicate constraint (2627) to a conflict', ()=>{
238
- const exception = makeQueryFailedError({
239
- driverError: {
240
- number: 2627,
241
- table: 'users'
242
- }
243
- });
244
- filter.catch(exception, host);
245
- expect(response.json.mock.calls[0][0].messageKey).toBe(_messagekeys.ERROR_MESSAGES.CONFLICT);
246
- });
247
- it('should fall back to "record" when no table name is available for a duplicate', ()=>{
248
- const exception = makeQueryFailedError({
249
- driverError: {
250
- code: '23505'
251
- }
252
- });
253
- filter.catch(exception, host);
254
- expect(response.json.mock.calls[0][0].message).toContain('Record');
255
- });
256
- it('should map a foreign key violation (23503) to a bad request', ()=>{
257
- const exception = makeQueryFailedError({
258
- driverError: {
259
- code: '23503',
260
- detail: 'Key (company_id)=(x) is not present in table "companies".'
261
- }
262
- });
263
- filter.catch(exception, host);
264
- expect(response.status).toHaveBeenCalledWith(_common.HttpStatus.BAD_REQUEST);
265
- const payload = response.json.mock.calls[0][0];
266
- expect(payload.messageKey).toBe(_messagekeys.ERROR_MESSAGES.DB_FOREIGN_KEY);
267
- expect(payload.message).toContain('Company ID');
268
- });
269
- it('should map a mysql foreign key violation via errno 1452', ()=>{
270
- const exception = makeQueryFailedError({
271
- driverError: {
272
- errno: 1452,
273
- sqlMessage: 'Cannot add or update a child row: a foreign key constraint fails (FOREIGN KEY (`company_id`) ...)'
274
- }
275
- });
276
- filter.catch(exception, host);
277
- expect(response.json.mock.calls[0][0].messageKey).toBe(_messagekeys.ERROR_MESSAGES.DB_FOREIGN_KEY);
278
- });
279
- it('should map a not-null violation (23502) with the human-readable column name', ()=>{
280
- const exception = makeQueryFailedError({
281
- driverError: {
282
- code: '23502',
283
- column: 'user_name'
284
- }
285
- });
286
- filter.catch(exception, host);
287
- const payload = response.json.mock.calls[0][0];
288
- expect(payload.messageKey).toBe(_messagekeys.ERROR_MESSAGES.DB_NOT_NULL);
289
- expect(payload.message).toContain('User Name');
290
- });
291
- it('should map a mysql not-null violation using the sqlMessage column name', ()=>{
292
- const exception = makeQueryFailedError({
293
- driverError: {
294
- code: 'ER_BAD_NULL_ERROR',
295
- sqlMessage: "Column 'user_name' cannot be null"
296
- }
297
- });
298
- filter.catch(exception, host);
299
- expect(response.json.mock.calls[0][0].messageKey).toBe(_messagekeys.ERROR_MESSAGES.DB_NOT_NULL);
300
- });
301
- it('should map a postgres invalid input syntax error (22P02)', ()=>{
302
- const exception = makeQueryFailedError({
303
- driverError: {
304
- code: '22P02',
305
- column: 'age'
306
- }
307
- }, 'invalid input syntax for type integer: "abc"');
308
- filter.catch(exception, host);
309
- const payload = response.json.mock.calls[0][0];
310
- expect(payload.messageKey).toBe(_messagekeys.ERROR_MESSAGES.DB_INVALID_INPUT);
311
- expect(payload.message).toContain('integer');
312
- expect(payload.message).toContain('Age');
313
- });
314
- it('should map a value-too-long error (22001)', ()=>{
315
- const exception = makeQueryFailedError({
316
- driverError: {
317
- code: '22001',
318
- column: 'name'
319
- }
320
- });
321
- filter.catch(exception, host);
322
- expect(response.json.mock.calls[0][0].messageKey).toBe(_messagekeys.ERROR_MESSAGES.DB_VALUE_TOO_LONG);
323
- });
324
- it('should map a mysql data-too-long error using the sqlMessage column name', ()=>{
325
- const exception = makeQueryFailedError({
326
- driverError: {
327
- code: 'ER_DATA_TOO_LONG',
328
- sqlMessage: "Data too long for column 'name' at row 1"
329
- }
330
- });
331
- filter.catch(exception, host);
332
- const payload = response.json.mock.calls[0][0];
333
- expect(payload.messageKey).toBe(_messagekeys.ERROR_MESSAGES.DB_VALUE_TOO_LONG);
334
- expect(payload.message).toContain('Name');
335
- });
336
- it('should map a check constraint violation (23514)', ()=>{
337
- const exception = makeQueryFailedError({
338
- driverError: {
339
- code: '23514',
340
- table: 'orders',
341
- constraint: 'orders_total_check'
342
- }
343
- });
344
- filter.catch(exception, host);
345
- const payload = response.json.mock.calls[0][0];
346
- expect(payload.messageKey).toBe(_messagekeys.ERROR_MESSAGES.DB_CHECK_CONSTRAINT);
347
- expect(payload.messageVariables).toMatchObject({
348
- constraint: 'orders_total_check'
349
- });
350
- });
351
- it('should map a deadlock error (40P01) to service unavailable', ()=>{
352
- const exception = makeQueryFailedError({
353
- driverError: {
354
- code: '40P01'
355
- }
356
- });
357
- filter.catch(exception, host);
358
- expect(response.status).toHaveBeenCalledWith(_common.HttpStatus.SERVICE_UNAVAILABLE);
359
- expect(response.json.mock.calls[0][0].messageKey).toBe(_messagekeys.ERROR_MESSAGES.DB_DEADLOCK);
360
- });
361
- it('should map a mysql deadlock via errno 1213', ()=>{
362
- const exception = makeQueryFailedError({
363
- driverError: {
364
- errno: 1213
365
- }
366
- });
367
- filter.catch(exception, host);
368
- expect(response.json.mock.calls[0][0].messageKey).toBe(_messagekeys.ERROR_MESSAGES.DB_DEADLOCK);
369
- });
370
- it('should fall back to a generic 500 for an unrecognized db error code', ()=>{
371
- const exception = makeQueryFailedError({
372
- driverError: {
373
- code: '99999'
374
- }
375
- });
376
- filter.catch(exception, host);
377
- expect(response.status).toHaveBeenCalledWith(_common.HttpStatus.INTERNAL_SERVER_ERROR);
378
- expect(response.json.mock.calls[0][0].messageKey).toBe(_messagekeys.ERROR_MESSAGES.INTERNAL);
379
- });
380
- it('should read driver fields directly when driverError is absent', ()=>{
381
- const exception = makeQueryFailedError({
382
- code: '23505',
383
- table: 'users'
384
- });
385
- filter.catch(exception, host);
386
- expect(response.json.mock.calls[0][0].messageKey).toBe(_messagekeys.ERROR_MESSAGES.CONFLICT);
387
- });
388
- });
389
- describe('unrecognized exceptions', ()=>{
390
- it('should return a generic 500 for a plain Error', ()=>{
391
- filter.catch(new Error('unexpected'), host);
392
- expect(response.status).toHaveBeenCalledWith(_common.HttpStatus.INTERNAL_SERVER_ERROR);
393
- const payload = response.json.mock.calls[0][0];
394
- expect(payload.message).toBe('Internal server error');
395
- expect(payload.messageKey).toBe(_messagekeys.ERROR_MESSAGES.INTERNAL);
396
- });
397
- it('should return a generic 500 for a thrown non-Error value', ()=>{
398
- filter.catch('just a string', host);
399
- expect(response.status).toHaveBeenCalledWith(_common.HttpStatus.INTERNAL_SERVER_ERROR);
400
- });
401
- it('should return a generic 500 for undefined/null', ()=>{
402
- filter.catch(undefined, host);
403
- expect(response.status).toHaveBeenCalledWith(_common.HttpStatus.INTERNAL_SERVER_ERROR);
404
- });
405
- });
406
- describe('logging behavior', ()=>{
407
- it('should log at error level with the stack trace for 5xx responses', ()=>{
408
- const exception = new Error('unexpected');
409
- filter.catch(exception, host);
410
- expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining('500'), exception.stack, expect.objectContaining({
411
- statusCode: _common.HttpStatus.INTERNAL_SERVER_ERROR
412
- }));
413
- expect(warnSpy).not.toHaveBeenCalled();
414
- });
415
- it('should log at warn level without a stack trace for 4xx responses', ()=>{
416
- const exception = new _common.HttpException('Not allowed', _common.HttpStatus.FORBIDDEN);
417
- filter.catch(exception, host);
418
- expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('403'), expect.objectContaining({
419
- statusCode: _common.HttpStatus.FORBIDDEN
420
- }));
421
- expect(errorSpy).not.toHaveBeenCalled();
422
- });
423
- it('should include correlation context (userId/tenantId/companyId) in the log payload', ()=>{
424
- mockGetUserId.mockReturnValue('user-1');
425
- mockGetTenantId.mockReturnValue('tenant-1');
426
- mockGetCompanyId.mockReturnValue('company-1');
427
- filter.catch(new Error('unexpected'), host);
428
- expect(errorSpy).toHaveBeenCalledWith(expect.any(String), expect.any(String), expect.objectContaining({
429
- userId: 'user-1',
430
- tenantId: 'tenant-1',
431
- companyId: 'company-1'
432
- }));
433
- });
434
- });
435
- it('should always set the response status and JSON body once', ()=>{
436
- filter.catch(new Error('boom'), host);
437
- expect(response.status).toHaveBeenCalledTimes(1);
438
- expect(response.json).toHaveBeenCalledTimes(1);
439
- });
440
- });
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- _export_star(require("./global-exception.filter"), exports);
6
- function _export_star(from, to) {
7
- Object.keys(from).forEach(function(k) {
8
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
9
- Object.defineProperty(to, k, {
10
- enumerable: true,
11
- get: function() {
12
- return from[k];
13
- }
14
- });
15
- }
16
- });
17
- return from;
18
- }
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- _export_star(require("./jwt-auth.guard"), exports);
6
- _export_star(require("./optional-jwt-auth.guard"), exports);
7
- _export_star(require("./permission.guard"), exports);
8
- function _export_star(from, to) {
9
- Object.keys(from).forEach(function(k) {
10
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
11
- Object.defineProperty(to, k, {
12
- enumerable: true,
13
- get: function() {
14
- return from[k];
15
- }
16
- });
17
- }
18
- });
19
- return from;
20
- }
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "JwtAuthGuard", {
6
- enumerable: true,
7
- get: function() {
8
- return JwtAuthGuard;
9
- }
10
- });
11
- const _constants = require("../constants");
12
- const _common = require("@nestjs/common");
13
- const _core = require("@nestjs/core");
14
- const _passport = require("@nestjs/passport");
15
- function _define_property(obj, key, value) {
16
- if (key in obj) {
17
- Object.defineProperty(obj, key, {
18
- value: value,
19
- enumerable: true,
20
- configurable: true,
21
- writable: true
22
- });
23
- } else {
24
- obj[key] = value;
25
- }
26
- return obj;
27
- }
28
- function _ts_decorate(decorators, target, key, desc) {
29
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
30
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
31
- else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
32
- return c > 3 && r && Object.defineProperty(target, key, r), r;
33
- }
34
- function _ts_metadata(k, v) {
35
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
36
- }
37
- function _ts_param(paramIndex, decorator) {
38
- return function(target, key) {
39
- decorator(target, key, paramIndex);
40
- };
41
- }
42
- let JwtAuthGuard = class JwtAuthGuard extends (0, _passport.AuthGuard)('jwt') {
43
- canActivate(context) {
44
- // Check if route is marked as public
45
- const isPublic = this.reflector.getAllAndOverride(_constants.IS_PUBLIC_KEY, [
46
- context.getHandler(),
47
- context.getClass()
48
- ]);
49
- if (isPublic) {
50
- return true;
51
- }
52
- return super.canActivate(context);
53
- }
54
- handleRequest(err, user) {
55
- if (err || !user) {
56
- throw err || new _common.UnauthorizedException({
57
- message: 'Invalid or expired token',
58
- messageKey: _constants.AUTH_MESSAGES.TOKEN_INVALID
59
- });
60
- }
61
- return user;
62
- }
63
- // NOTE: @Inject(Reflector) required for bundled code - external classes need explicit injection
64
- constructor(reflector){
65
- super(), _define_property(this, "reflector", void 0), this.reflector = reflector;
66
- }
67
- };
68
- JwtAuthGuard = _ts_decorate([
69
- (0, _common.Injectable)(),
70
- _ts_param(0, (0, _common.Inject)(_core.Reflector)),
71
- _ts_metadata("design:type", Function),
72
- _ts_metadata("design:paramtypes", [
73
- typeof _core.Reflector === "undefined" ? Object : _core.Reflector
74
- ])
75
- ], JwtAuthGuard);
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- const _common = require("@nestjs/common");
6
- const _core = require("@nestjs/core");
7
- const _passport = require("@nestjs/passport");
8
- const _constants = require("../constants");
9
- const _jwtauthguard = require("./jwt-auth.guard");
10
- function buildContext() {
11
- return {
12
- getHandler: ()=>({}),
13
- getClass: ()=>({})
14
- };
15
- }
16
- describe('JwtAuthGuard', ()=>{
17
- let reflector;
18
- let guard;
19
- let superCanActivateSpy;
20
- beforeEach(()=>{
21
- reflector = new _core.Reflector();
22
- guard = new _jwtauthguard.JwtAuthGuard(reflector);
23
- superCanActivateSpy = jest.spyOn((0, _passport.AuthGuard)('jwt').prototype, 'canActivate').mockReturnValue(true);
24
- });
25
- afterEach(()=>{
26
- jest.restoreAllMocks();
27
- });
28
- describe('canActivate', ()=>{
29
- it('should allow access without invoking the parent guard when the route is public', ()=>{
30
- jest.spyOn(reflector, 'getAllAndOverride').mockReturnValue(true);
31
- const result = guard.canActivate(buildContext());
32
- expect(result).toBe(true);
33
- expect(superCanActivateSpy).not.toHaveBeenCalled();
34
- });
35
- it('should check IS_PUBLIC_KEY metadata on both handler and class', ()=>{
36
- const getAllAndOverrideSpy = jest.spyOn(reflector, 'getAllAndOverride').mockReturnValue(false);
37
- const ctx = buildContext();
38
- guard.canActivate(ctx);
39
- expect(getAllAndOverrideSpy).toHaveBeenCalledWith(_constants.IS_PUBLIC_KEY, [
40
- ctx.getHandler(),
41
- ctx.getClass()
42
- ]);
43
- });
44
- it('should delegate to the parent AuthGuard when the route is not public', ()=>{
45
- jest.spyOn(reflector, 'getAllAndOverride').mockReturnValue(false);
46
- const result = guard.canActivate(buildContext());
47
- expect(result).toBe(true);
48
- expect(superCanActivateSpy).toHaveBeenCalled();
49
- });
50
- });
51
- describe('handleRequest', ()=>{
52
- it('should return the user when authentication succeeds', ()=>{
53
- const user = {
54
- id: 'user-1'
55
- };
56
- expect(guard.handleRequest(null, user)).toBe(user);
57
- });
58
- it('should throw the original error when one is provided', ()=>{
59
- const err = new Error('strategy failure');
60
- expect(()=>guard.handleRequest(err, null)).toThrow(err);
61
- });
62
- it('should throw UnauthorizedException with AUTH_MESSAGES.TOKEN_INVALID when no error but no user', ()=>{
63
- try {
64
- guard.handleRequest(null, null);
65
- fail('expected to throw');
66
- } catch (error) {
67
- expect(error).toBeInstanceOf(_common.UnauthorizedException);
68
- expect(error.getResponse()).toMatchObject({
69
- message: 'Invalid or expired token',
70
- messageKey: _constants.AUTH_MESSAGES.TOKEN_INVALID
71
- });
72
- }
73
- });
74
- });
75
- });