@open-mercato/core 0.4.5-develop-2e9903a57a → 0.4.5-develop-eeccf7adf4

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 (473) hide show
  1. package/package.json +2 -2
  2. package/dist/modules/auth/__integration__/TC-AUTH-001.spec.js +0 -9
  3. package/dist/modules/auth/__integration__/TC-AUTH-001.spec.js.map +0 -7
  4. package/dist/modules/auth/__integration__/TC-AUTH-002.spec.js +0 -22
  5. package/dist/modules/auth/__integration__/TC-AUTH-002.spec.js.map +0 -7
  6. package/dist/modules/auth/__integration__/TC-AUTH-003.spec.js +0 -21
  7. package/dist/modules/auth/__integration__/TC-AUTH-003.spec.js.map +0 -7
  8. package/dist/modules/auth/__integration__/TC-AUTH-004.spec.js +0 -15
  9. package/dist/modules/auth/__integration__/TC-AUTH-004.spec.js.map +0 -7
  10. package/dist/modules/auth/__integration__/TC-AUTH-005.spec.js +0 -11
  11. package/dist/modules/auth/__integration__/TC-AUTH-005.spec.js.map +0 -7
  12. package/dist/modules/auth/__integration__/TC-AUTH-006.spec.js +0 -11
  13. package/dist/modules/auth/__integration__/TC-AUTH-006.spec.js.map +0 -7
  14. package/dist/modules/auth/__integration__/TC-AUTH-007.spec.js +0 -14
  15. package/dist/modules/auth/__integration__/TC-AUTH-007.spec.js.map +0 -7
  16. package/dist/modules/auth/__integration__/TC-AUTH-008.spec.js +0 -26
  17. package/dist/modules/auth/__integration__/TC-AUTH-008.spec.js.map +0 -7
  18. package/dist/modules/auth/__integration__/TC-AUTH-009.spec.js +0 -16
  19. package/dist/modules/auth/__integration__/TC-AUTH-009.spec.js.map +0 -7
  20. package/dist/modules/auth/__integration__/TC-AUTH-010.spec.js +0 -32
  21. package/dist/modules/auth/__integration__/TC-AUTH-010.spec.js.map +0 -7
  22. package/dist/modules/auth/__integration__/TC-AUTH-011.spec.js +0 -26
  23. package/dist/modules/auth/__integration__/TC-AUTH-011.spec.js.map +0 -7
  24. package/dist/modules/auth/__integration__/TC-AUTH-012.spec.js +0 -30
  25. package/dist/modules/auth/__integration__/TC-AUTH-012.spec.js.map +0 -7
  26. package/dist/modules/auth/__integration__/TC-AUTH-013.spec.js +0 -41
  27. package/dist/modules/auth/__integration__/TC-AUTH-013.spec.js.map +0 -7
  28. package/dist/modules/auth/__integration__/TC-AUTH-014.spec.js +0 -25
  29. package/dist/modules/auth/__integration__/TC-AUTH-014.spec.js.map +0 -7
  30. package/dist/modules/auth/__integration__/TC-AUTH-015.spec.js +0 -20
  31. package/dist/modules/auth/__integration__/TC-AUTH-015.spec.js.map +0 -7
  32. package/dist/modules/auth/__integration__/TC-AUTH-016.spec.js +0 -76
  33. package/dist/modules/auth/__integration__/TC-AUTH-016.spec.js.map +0 -7
  34. package/dist/modules/catalog/__integration__/TC-CAT-001.spec.js +0 -20
  35. package/dist/modules/catalog/__integration__/TC-CAT-001.spec.js.map +0 -7
  36. package/dist/modules/catalog/__integration__/TC-CAT-002.spec.js +0 -12
  37. package/dist/modules/catalog/__integration__/TC-CAT-002.spec.js.map +0 -7
  38. package/dist/modules/catalog/__integration__/TC-CAT-003.spec.js +0 -28
  39. package/dist/modules/catalog/__integration__/TC-CAT-003.spec.js.map +0 -7
  40. package/dist/modules/catalog/__integration__/TC-CAT-004.spec.js +0 -33
  41. package/dist/modules/catalog/__integration__/TC-CAT-004.spec.js.map +0 -7
  42. package/dist/modules/catalog/__integration__/TC-CAT-005.spec.js +0 -30
  43. package/dist/modules/catalog/__integration__/TC-CAT-005.spec.js.map +0 -7
  44. package/dist/modules/catalog/__integration__/TC-CAT-006.spec.js +0 -31
  45. package/dist/modules/catalog/__integration__/TC-CAT-006.spec.js.map +0 -7
  46. package/dist/modules/catalog/__integration__/TC-CAT-007.spec.js +0 -31
  47. package/dist/modules/catalog/__integration__/TC-CAT-007.spec.js.map +0 -7
  48. package/dist/modules/catalog/__integration__/TC-CAT-008.spec.js +0 -65
  49. package/dist/modules/catalog/__integration__/TC-CAT-008.spec.js.map +0 -7
  50. package/dist/modules/catalog/__integration__/TC-CAT-009.spec.js +0 -31
  51. package/dist/modules/catalog/__integration__/TC-CAT-009.spec.js.map +0 -7
  52. package/dist/modules/catalog/__integration__/TC-CAT-010.spec.js +0 -28
  53. package/dist/modules/catalog/__integration__/TC-CAT-010.spec.js.map +0 -7
  54. package/dist/modules/catalog/__integration__/TC-CAT-011.spec.js +0 -34
  55. package/dist/modules/catalog/__integration__/TC-CAT-011.spec.js.map +0 -7
  56. package/dist/modules/catalog/__integration__/TC-CAT-012.spec.js +0 -27
  57. package/dist/modules/catalog/__integration__/TC-CAT-012.spec.js.map +0 -7
  58. package/dist/modules/core/__integration__/admin/TC-ADMIN-001.spec.js +0 -44
  59. package/dist/modules/core/__integration__/admin/TC-ADMIN-001.spec.js.map +0 -7
  60. package/dist/modules/core/__integration__/admin/TC-ADMIN-002.spec.js +0 -53
  61. package/dist/modules/core/__integration__/admin/TC-ADMIN-002.spec.js.map +0 -7
  62. package/dist/modules/core/__integration__/admin/TC-ADMIN-003.spec.js +0 -26
  63. package/dist/modules/core/__integration__/admin/TC-ADMIN-003.spec.js.map +0 -7
  64. package/dist/modules/core/__integration__/admin/TC-ADMIN-004.spec.js +0 -47
  65. package/dist/modules/core/__integration__/admin/TC-ADMIN-004.spec.js.map +0 -7
  66. package/dist/modules/core/__integration__/admin/TC-ADMIN-005.spec.js +0 -33
  67. package/dist/modules/core/__integration__/admin/TC-ADMIN-005.spec.js.map +0 -7
  68. package/dist/modules/core/__integration__/admin/TC-ADMIN-006.spec.js +0 -30
  69. package/dist/modules/core/__integration__/admin/TC-ADMIN-006.spec.js.map +0 -7
  70. package/dist/modules/core/__integration__/admin/TC-ADMIN-007.spec.js +0 -36
  71. package/dist/modules/core/__integration__/admin/TC-ADMIN-007.spec.js.map +0 -7
  72. package/dist/modules/core/__integration__/admin/TC-ADMIN-008.spec.js +0 -113
  73. package/dist/modules/core/__integration__/admin/TC-ADMIN-008.spec.js.map +0 -7
  74. package/dist/modules/core/__integration__/admin/TC-ADMIN-009.spec.js +0 -25
  75. package/dist/modules/core/__integration__/admin/TC-ADMIN-009.spec.js.map +0 -7
  76. package/dist/modules/core/__integration__/admin/TC-ADMIN-010.spec.js +0 -35
  77. package/dist/modules/core/__integration__/admin/TC-ADMIN-010.spec.js.map +0 -7
  78. package/dist/modules/core/__integration__/helpers/api.js +0 -64
  79. package/dist/modules/core/__integration__/helpers/api.js.map +0 -7
  80. package/dist/modules/core/__integration__/helpers/auth.js +0 -98
  81. package/dist/modules/core/__integration__/helpers/auth.js.map +0 -7
  82. package/dist/modules/core/__integration__/helpers/authUi.js +0 -31
  83. package/dist/modules/core/__integration__/helpers/authUi.js.map +0 -7
  84. package/dist/modules/core/__integration__/helpers/catalogFixtures.js +0 -49
  85. package/dist/modules/core/__integration__/helpers/catalogFixtures.js.map +0 -7
  86. package/dist/modules/core/__integration__/helpers/crmFixtures.js +0 -73
  87. package/dist/modules/core/__integration__/helpers/crmFixtures.js.map +0 -7
  88. package/dist/modules/core/__integration__/helpers/salesFixtures.js +0 -63
  89. package/dist/modules/core/__integration__/helpers/salesFixtures.js.map +0 -7
  90. package/dist/modules/core/__integration__/helpers/salesUi.js +0 -464
  91. package/dist/modules/core/__integration__/helpers/salesUi.js.map +0 -7
  92. package/dist/modules/core/__integration__/integration/TC-INT-001.spec.js +0 -26
  93. package/dist/modules/core/__integration__/integration/TC-INT-001.spec.js.map +0 -7
  94. package/dist/modules/core/__integration__/integration/TC-INT-002.spec.js +0 -60
  95. package/dist/modules/core/__integration__/integration/TC-INT-002.spec.js.map +0 -7
  96. package/dist/modules/core/__integration__/integration/TC-INT-003.spec.js +0 -36
  97. package/dist/modules/core/__integration__/integration/TC-INT-003.spec.js.map +0 -7
  98. package/dist/modules/core/__integration__/integration/TC-INT-004.spec.js +0 -74
  99. package/dist/modules/core/__integration__/integration/TC-INT-004.spec.js.map +0 -7
  100. package/dist/modules/core/__integration__/integration/TC-INT-005.spec.js +0 -21
  101. package/dist/modules/core/__integration__/integration/TC-INT-005.spec.js.map +0 -7
  102. package/dist/modules/customers/__integration__/TC-CRM-001.spec.js +0 -32
  103. package/dist/modules/customers/__integration__/TC-CRM-001.spec.js.map +0 -7
  104. package/dist/modules/customers/__integration__/TC-CRM-002.spec.js +0 -35
  105. package/dist/modules/customers/__integration__/TC-CRM-002.spec.js.map +0 -7
  106. package/dist/modules/customers/__integration__/TC-CRM-003.spec.js +0 -40
  107. package/dist/modules/customers/__integration__/TC-CRM-003.spec.js.map +0 -7
  108. package/dist/modules/customers/__integration__/TC-CRM-004.spec.js +0 -40
  109. package/dist/modules/customers/__integration__/TC-CRM-004.spec.js.map +0 -7
  110. package/dist/modules/customers/__integration__/TC-CRM-005.spec.js +0 -37
  111. package/dist/modules/customers/__integration__/TC-CRM-005.spec.js.map +0 -7
  112. package/dist/modules/customers/__integration__/TC-CRM-006.spec.js +0 -42
  113. package/dist/modules/customers/__integration__/TC-CRM-006.spec.js.map +0 -7
  114. package/dist/modules/customers/__integration__/TC-CRM-007.spec.js +0 -44
  115. package/dist/modules/customers/__integration__/TC-CRM-007.spec.js.map +0 -7
  116. package/dist/modules/customers/__integration__/TC-CRM-008.spec.js +0 -50
  117. package/dist/modules/customers/__integration__/TC-CRM-008.spec.js.map +0 -7
  118. package/dist/modules/customers/__integration__/TC-CRM-009.spec.js +0 -33
  119. package/dist/modules/customers/__integration__/TC-CRM-009.spec.js.map +0 -7
  120. package/dist/modules/customers/__integration__/TC-CRM-010.spec.js +0 -39
  121. package/dist/modules/customers/__integration__/TC-CRM-010.spec.js.map +0 -7
  122. package/dist/modules/customers/__integration__/TC-CRM-011.spec.js +0 -37
  123. package/dist/modules/customers/__integration__/TC-CRM-011.spec.js.map +0 -7
  124. package/dist/modules/customers/__integration__/TC-CRM-012.spec.js +0 -38
  125. package/dist/modules/customers/__integration__/TC-CRM-012.spec.js.map +0 -7
  126. package/dist/modules/customers/__integration__/TC-CRM-013.spec.js +0 -43
  127. package/dist/modules/customers/__integration__/TC-CRM-013.spec.js.map +0 -7
  128. package/dist/modules/customers/__integration__/TC-CRM-014.spec.js +0 -23
  129. package/dist/modules/customers/__integration__/TC-CRM-014.spec.js.map +0 -7
  130. package/dist/modules/customers/__integration__/TC-CRM-015.spec.js +0 -63
  131. package/dist/modules/customers/__integration__/TC-CRM-015.spec.js.map +0 -7
  132. package/dist/modules/customers/__integration__/TC-CRM-016.spec.js +0 -46
  133. package/dist/modules/customers/__integration__/TC-CRM-016.spec.js.map +0 -7
  134. package/dist/modules/customers/__integration__/TC-CRM-017.spec.js +0 -29
  135. package/dist/modules/customers/__integration__/TC-CRM-017.spec.js.map +0 -7
  136. package/dist/modules/customers/__integration__/TC-CRM-018.spec.js +0 -52
  137. package/dist/modules/customers/__integration__/TC-CRM-018.spec.js.map +0 -7
  138. package/dist/modules/customers/__integration__/TC-CRM-019.spec.js +0 -37
  139. package/dist/modules/customers/__integration__/TC-CRM-019.spec.js.map +0 -7
  140. package/dist/modules/customers/__integration__/TC-CRM-020.spec.js +0 -65
  141. package/dist/modules/customers/__integration__/TC-CRM-020.spec.js.map +0 -7
  142. package/dist/modules/progress/__integration__/TC-PROG-001.spec.js +0 -51
  143. package/dist/modules/progress/__integration__/TC-PROG-001.spec.js.map +0 -7
  144. package/dist/modules/resources/__integration__/TC-INT-007.spec.js +0 -88
  145. package/dist/modules/resources/__integration__/TC-INT-007.spec.js.map +0 -7
  146. package/dist/modules/resources/__integration__/helpers/resourcesFixtures.js +0 -45
  147. package/dist/modules/resources/__integration__/helpers/resourcesFixtures.js.map +0 -7
  148. package/dist/modules/sales/__integration__/TC-SALES-001.spec.js +0 -20
  149. package/dist/modules/sales/__integration__/TC-SALES-001.spec.js.map +0 -7
  150. package/dist/modules/sales/__integration__/TC-SALES-002.spec.js +0 -31
  151. package/dist/modules/sales/__integration__/TC-SALES-002.spec.js.map +0 -7
  152. package/dist/modules/sales/__integration__/TC-SALES-003.spec.js +0 -13
  153. package/dist/modules/sales/__integration__/TC-SALES-003.spec.js.map +0 -7
  154. package/dist/modules/sales/__integration__/TC-SALES-004.spec.js +0 -14
  155. package/dist/modules/sales/__integration__/TC-SALES-004.spec.js.map +0 -7
  156. package/dist/modules/sales/__integration__/TC-SALES-005.spec.js +0 -15
  157. package/dist/modules/sales/__integration__/TC-SALES-005.spec.js.map +0 -7
  158. package/dist/modules/sales/__integration__/TC-SALES-006.spec.js +0 -20
  159. package/dist/modules/sales/__integration__/TC-SALES-006.spec.js.map +0 -7
  160. package/dist/modules/sales/__integration__/TC-SALES-007.spec.js +0 -19
  161. package/dist/modules/sales/__integration__/TC-SALES-007.spec.js.map +0 -7
  162. package/dist/modules/sales/__integration__/TC-SALES-008.spec.js +0 -7
  163. package/dist/modules/sales/__integration__/TC-SALES-008.spec.js.map +0 -7
  164. package/dist/modules/sales/__integration__/TC-SALES-009.spec.js +0 -7
  165. package/dist/modules/sales/__integration__/TC-SALES-009.spec.js.map +0 -7
  166. package/dist/modules/sales/__integration__/TC-SALES-010.spec.js +0 -16
  167. package/dist/modules/sales/__integration__/TC-SALES-010.spec.js.map +0 -7
  168. package/dist/modules/sales/__integration__/TC-SALES-011.spec.js +0 -20
  169. package/dist/modules/sales/__integration__/TC-SALES-011.spec.js.map +0 -7
  170. package/dist/modules/sales/__integration__/TC-SALES-012.spec.js +0 -7
  171. package/dist/modules/sales/__integration__/TC-SALES-012.spec.js.map +0 -7
  172. package/dist/modules/sales/__integration__/TC-SALES-013.spec.js +0 -66
  173. package/dist/modules/sales/__integration__/TC-SALES-013.spec.js.map +0 -7
  174. package/dist/modules/sales/__integration__/TC-SALES-014.spec.js +0 -13
  175. package/dist/modules/sales/__integration__/TC-SALES-014.spec.js.map +0 -7
  176. package/dist/modules/sales/__integration__/TC-SALES-015.spec.js +0 -13
  177. package/dist/modules/sales/__integration__/TC-SALES-015.spec.js.map +0 -7
  178. package/dist/modules/sales/__integration__/TC-SALES-016.spec.js +0 -13
  179. package/dist/modules/sales/__integration__/TC-SALES-016.spec.js.map +0 -7
  180. package/dist/modules/sales/__integration__/TC-SALES-017.spec.js +0 -44
  181. package/dist/modules/sales/__integration__/TC-SALES-017.spec.js.map +0 -7
  182. package/dist/modules/sales/__integration__/TC-SALES-018.spec.js +0 -18
  183. package/dist/modules/sales/__integration__/TC-SALES-018.spec.js.map +0 -7
  184. package/dist/modules/sales/__integration__/TC-SALES-019.spec.js +0 -16
  185. package/dist/modules/sales/__integration__/TC-SALES-019.spec.js.map +0 -7
  186. package/dist/modules/sales/__integration__/TC-SALES-020.spec.js +0 -75
  187. package/dist/modules/sales/__integration__/TC-SALES-020.spec.js.map +0 -7
  188. package/dist/modules/staff/__integration__/TC-INT-006.spec.js +0 -64
  189. package/dist/modules/staff/__integration__/TC-INT-006.spec.js.map +0 -7
  190. package/dist/modules/translations/__integration__/TC-TRANS-001.spec.js +0 -48
  191. package/dist/modules/translations/__integration__/TC-TRANS-001.spec.js.map +0 -7
  192. package/dist/modules/translations/__integration__/TC-TRANS-002.spec.js +0 -94
  193. package/dist/modules/translations/__integration__/TC-TRANS-002.spec.js.map +0 -7
  194. package/dist/modules/translations/__integration__/TC-TRANS-003.spec.js +0 -61
  195. package/dist/modules/translations/__integration__/TC-TRANS-003.spec.js.map +0 -7
  196. package/dist/modules/translations/__integration__/TC-TRANS-004.spec.js +0 -52
  197. package/dist/modules/translations/__integration__/TC-TRANS-004.spec.js.map +0 -7
  198. package/dist/modules/translations/__integration__/TC-TRANS-005.spec.js +0 -106
  199. package/dist/modules/translations/__integration__/TC-TRANS-005.spec.js.map +0 -7
  200. package/dist/modules/translations/__integration__/TC-TRANS-006.spec.js +0 -94
  201. package/dist/modules/translations/__integration__/TC-TRANS-006.spec.js.map +0 -7
  202. package/dist/modules/translations/__integration__/TC-TRANS-007.spec.js +0 -62
  203. package/dist/modules/translations/__integration__/TC-TRANS-007.spec.js.map +0 -7
  204. package/dist/modules/translations/__integration__/TC-TRANS-008.spec.js +0 -168
  205. package/dist/modules/translations/__integration__/TC-TRANS-008.spec.js.map +0 -7
  206. package/dist/modules/translations/__integration__/helpers/translationFixtures.js +0 -63
  207. package/dist/modules/translations/__integration__/helpers/translationFixtures.js.map +0 -7
  208. package/dist/modules/workflows/__integration__/TC-WF-001.spec.js +0 -73
  209. package/dist/modules/workflows/__integration__/TC-WF-001.spec.js.map +0 -7
  210. package/src/__tests__/module-decoupling.test.ts +0 -356
  211. package/src/modules/api_keys/api/__tests__/keys.route.test.ts +0 -244
  212. package/src/modules/attachments/api/__tests__/attachments.api.test.ts +0 -240
  213. package/src/modules/attachments/components/__tests__/AttachmentContentPreview.test.tsx +0 -45
  214. package/src/modules/attachments/data/__tests__/entities-ocr.test.ts +0 -15
  215. package/src/modules/attachments/lib/__tests__/ocr-config.test.ts +0 -27
  216. package/src/modules/attachments/lib/__tests__/textExtraction.test.ts +0 -64
  217. package/src/modules/audit_logs/api/__tests__/access.route.test.ts +0 -118
  218. package/src/modules/audit_logs/api/__tests__/redo.route.test.ts +0 -131
  219. package/src/modules/audit_logs/api/__tests__/undo.route.test.ts +0 -103
  220. package/src/modules/audit_logs/services/__tests__/actionLogService.test.ts +0 -26
  221. package/src/modules/auth/__integration__/TC-AUTH-001.spec.ts +0 -13
  222. package/src/modules/auth/__integration__/TC-AUTH-002.spec.ts +0 -30
  223. package/src/modules/auth/__integration__/TC-AUTH-003.spec.ts +0 -28
  224. package/src/modules/auth/__integration__/TC-AUTH-004.spec.ts +0 -21
  225. package/src/modules/auth/__integration__/TC-AUTH-005.spec.ts +0 -17
  226. package/src/modules/auth/__integration__/TC-AUTH-006.spec.ts +0 -17
  227. package/src/modules/auth/__integration__/TC-AUTH-007.spec.ts +0 -19
  228. package/src/modules/auth/__integration__/TC-AUTH-008.spec.ts +0 -31
  229. package/src/modules/auth/__integration__/TC-AUTH-009.spec.ts +0 -22
  230. package/src/modules/auth/__integration__/TC-AUTH-010.spec.ts +0 -39
  231. package/src/modules/auth/__integration__/TC-AUTH-011.spec.ts +0 -35
  232. package/src/modules/auth/__integration__/TC-AUTH-012.spec.ts +0 -36
  233. package/src/modules/auth/__integration__/TC-AUTH-013.spec.ts +0 -48
  234. package/src/modules/auth/__integration__/TC-AUTH-014.spec.ts +0 -31
  235. package/src/modules/auth/__integration__/TC-AUTH-015.spec.ts +0 -28
  236. package/src/modules/auth/__integration__/TC-AUTH-016.spec.ts +0 -109
  237. package/src/modules/auth/__tests__/cli-rotate-encryption.test.ts +0 -97
  238. package/src/modules/auth/__tests__/cli-setup-acl.test.ts +0 -148
  239. package/src/modules/auth/api/__tests__/feature-check.test.ts +0 -65
  240. package/src/modules/auth/api/__tests__/login.test.ts +0 -47
  241. package/src/modules/auth/commands/__tests__/roles.custom-fields.test.ts +0 -126
  242. package/src/modules/auth/commands/__tests__/users.custom-fields.test.ts +0 -147
  243. package/src/modules/auth/lib/__tests__/rateLimitCheck.test.ts +0 -224
  244. package/src/modules/auth/services/__tests__/authService.test.ts +0 -32
  245. package/src/modules/auth/services/__tests__/rbacService.test.ts +0 -814
  246. package/src/modules/business_rules/api/__tests__/execute.route.test.ts +0 -311
  247. package/src/modules/business_rules/api/__tests__/logs-detail.route.test.ts +0 -181
  248. package/src/modules/business_rules/api/__tests__/logs.route.test.ts +0 -261
  249. package/src/modules/business_rules/api/__tests__/rules-detail.route.test.ts +0 -115
  250. package/src/modules/business_rules/api/__tests__/rules.route.test.ts +0 -746
  251. package/src/modules/business_rules/api/__tests__/sets-detail.route.test.ts +0 -169
  252. package/src/modules/business_rules/api/__tests__/sets-members.route.test.ts +0 -367
  253. package/src/modules/business_rules/api/__tests__/sets.route.test.ts +0 -361
  254. package/src/modules/business_rules/api/__tests__/test-helpers.ts +0 -42
  255. package/src/modules/business_rules/components/utils/__tests__/formHelpers.test.ts +0 -69
  256. package/src/modules/business_rules/data/__tests__/validators.test.ts +0 -637
  257. package/src/modules/business_rules/lib/__tests__/action-executor.test.ts +0 -728
  258. package/src/modules/business_rules/lib/__tests__/expression-evaluator.test.ts +0 -592
  259. package/src/modules/business_rules/lib/__tests__/rule-engine.test.ts +0 -805
  260. package/src/modules/business_rules/lib/__tests__/rule-evaluator.test.ts +0 -436
  261. package/src/modules/catalog/__integration__/TC-CAT-001.spec.ts +0 -32
  262. package/src/modules/catalog/__integration__/TC-CAT-002.spec.ts +0 -19
  263. package/src/modules/catalog/__integration__/TC-CAT-003.spec.ts +0 -39
  264. package/src/modules/catalog/__integration__/TC-CAT-004.spec.ts +0 -41
  265. package/src/modules/catalog/__integration__/TC-CAT-005.spec.ts +0 -37
  266. package/src/modules/catalog/__integration__/TC-CAT-006.spec.ts +0 -40
  267. package/src/modules/catalog/__integration__/TC-CAT-007.spec.ts +0 -37
  268. package/src/modules/catalog/__integration__/TC-CAT-008.spec.ts +0 -76
  269. package/src/modules/catalog/__integration__/TC-CAT-009.spec.ts +0 -39
  270. package/src/modules/catalog/__integration__/TC-CAT-010.spec.ts +0 -36
  271. package/src/modules/catalog/__integration__/TC-CAT-011.spec.ts +0 -44
  272. package/src/modules/catalog/__integration__/TC-CAT-012.spec.ts +0 -35
  273. package/src/modules/catalog/api/__tests__/offers.route.test.ts +0 -161
  274. package/src/modules/catalog/api/__tests__/prices.route.test.ts +0 -39
  275. package/src/modules/catalog/api/__tests__/products.route.test.ts +0 -91
  276. package/src/modules/catalog/api/__tests__/utils.test.ts +0 -36
  277. package/src/modules/catalog/api/__tests__/variants.route.test.ts +0 -44
  278. package/src/modules/catalog/backend/catalog/products/__tests__/ProductsDataTable.test.tsx +0 -172
  279. package/src/modules/catalog/commands/__tests__/products.delete.test.ts +0 -146
  280. package/src/modules/catalog/commands/__tests__/products.update.test.ts +0 -142
  281. package/src/modules/catalog/commands/__tests__/registration.test.ts +0 -54
  282. package/src/modules/catalog/commands/__tests__/shared.test.ts +0 -129
  283. package/src/modules/catalog/components/__tests__/catalogComponentsRender.test.tsx +0 -373
  284. package/src/modules/catalog/components/products/__tests__/ProductImageCell.test.tsx +0 -51
  285. package/src/modules/catalog/components/products/__tests__/productForm.test.ts +0 -32
  286. package/src/modules/catalog/lib/__tests__/pricing.test.ts +0 -150
  287. package/src/modules/catalog/services/__tests__/catalogPricingService.test.ts +0 -21
  288. package/src/modules/configs/components/__tests__/CachePanel.test.tsx +0 -134
  289. package/src/modules/configs/components/__tests__/SystemStatusPanel.test.tsx +0 -93
  290. package/src/modules/configs/lib/__tests__/system-status.test.ts +0 -55
  291. package/src/modules/configs/lib/__tests__/upgrade-actions.test.ts +0 -135
  292. package/src/modules/core/__integration__/admin/TC-ADMIN-001.spec.ts +0 -70
  293. package/src/modules/core/__integration__/admin/TC-ADMIN-002.spec.ts +0 -83
  294. package/src/modules/core/__integration__/admin/TC-ADMIN-003.spec.ts +0 -50
  295. package/src/modules/core/__integration__/admin/TC-ADMIN-004.spec.ts +0 -77
  296. package/src/modules/core/__integration__/admin/TC-ADMIN-005.spec.ts +0 -49
  297. package/src/modules/core/__integration__/admin/TC-ADMIN-006.spec.ts +0 -59
  298. package/src/modules/core/__integration__/admin/TC-ADMIN-007.spec.ts +0 -68
  299. package/src/modules/core/__integration__/admin/TC-ADMIN-008.spec.ts +0 -127
  300. package/src/modules/core/__integration__/admin/TC-ADMIN-009.spec.ts +0 -48
  301. package/src/modules/core/__integration__/admin/TC-ADMIN-010.spec.ts +0 -57
  302. package/src/modules/core/__integration__/helpers/api.ts +0 -84
  303. package/src/modules/core/__integration__/helpers/auth.ts +0 -110
  304. package/src/modules/core/__integration__/helpers/authUi.ts +0 -33
  305. package/src/modules/core/__integration__/helpers/catalogFixtures.ts +0 -73
  306. package/src/modules/core/__integration__/helpers/crmFixtures.ts +0 -101
  307. package/src/modules/core/__integration__/helpers/salesFixtures.ts +0 -89
  308. package/src/modules/core/__integration__/helpers/salesUi.ts +0 -528
  309. package/src/modules/core/__integration__/integration/TC-INT-001.spec.ts +0 -34
  310. package/src/modules/core/__integration__/integration/TC-INT-002.spec.ts +0 -74
  311. package/src/modules/core/__integration__/integration/TC-INT-003.spec.ts +0 -43
  312. package/src/modules/core/__integration__/integration/TC-INT-004.spec.ts +0 -82
  313. package/src/modules/core/__integration__/integration/TC-INT-005.spec.ts +0 -29
  314. package/src/modules/currencies/backend/exchange-rates/__tests__/formatDateTimeLocal.test.ts +0 -78
  315. package/src/modules/currencies/data/__tests__/validators.test.ts +0 -100
  316. package/src/modules/currencies/services/__tests__/exchangeRateService.test.ts +0 -666
  317. package/src/modules/currencies/services/__tests__/rateFetchingService.basic.test.ts +0 -398
  318. package/src/modules/currencies/services/__tests__/rateFetchingService.errors.test.ts +0 -296
  319. package/src/modules/currencies/services/__tests__/rateFetchingService.providers.test.ts +0 -350
  320. package/src/modules/currencies/services/__tests__/rateFetchingService.setup.ts +0 -188
  321. package/src/modules/customers/__integration__/TC-CRM-001.spec.ts +0 -42
  322. package/src/modules/customers/__integration__/TC-CRM-002.spec.ts +0 -47
  323. package/src/modules/customers/__integration__/TC-CRM-003.spec.ts +0 -55
  324. package/src/modules/customers/__integration__/TC-CRM-004.spec.ts +0 -57
  325. package/src/modules/customers/__integration__/TC-CRM-005.spec.ts +0 -50
  326. package/src/modules/customers/__integration__/TC-CRM-006.spec.ts +0 -60
  327. package/src/modules/customers/__integration__/TC-CRM-007.spec.ts +0 -57
  328. package/src/modules/customers/__integration__/TC-CRM-008.spec.ts +0 -62
  329. package/src/modules/customers/__integration__/TC-CRM-009.spec.ts +0 -46
  330. package/src/modules/customers/__integration__/TC-CRM-010.spec.ts +0 -49
  331. package/src/modules/customers/__integration__/TC-CRM-011.spec.ts +0 -47
  332. package/src/modules/customers/__integration__/TC-CRM-012.spec.ts +0 -49
  333. package/src/modules/customers/__integration__/TC-CRM-013.spec.ts +0 -61
  334. package/src/modules/customers/__integration__/TC-CRM-014.spec.ts +0 -31
  335. package/src/modules/customers/__integration__/TC-CRM-015.spec.ts +0 -89
  336. package/src/modules/customers/__integration__/TC-CRM-016.spec.ts +0 -55
  337. package/src/modules/customers/__integration__/TC-CRM-017.spec.ts +0 -37
  338. package/src/modules/customers/__integration__/TC-CRM-018.spec.ts +0 -62
  339. package/src/modules/customers/__integration__/TC-CRM-019.spec.ts +0 -44
  340. package/src/modules/customers/__integration__/TC-CRM-020.spec.ts +0 -73
  341. package/src/modules/customers/api/__tests__/utils.test.ts +0 -61
  342. package/src/modules/customers/api/dashboard/widgets/new-deals/__tests__/route.test.ts +0 -54
  343. package/src/modules/customers/commands/__tests__/shared.test.ts +0 -263
  344. package/src/modules/customers/commands/__tests__/undo.custom-fields.test.ts +0 -1184
  345. package/src/modules/customers/components/detail/__tests__/ActivityForm.validation.test.ts +0 -37
  346. package/src/modules/customers/components/detail/__tests__/DealForm.validation.test.ts +0 -45
  347. package/src/modules/customers/components/detail/__tests__/InlineEditors.test.tsx +0 -166
  348. package/src/modules/customers/components/detail/__tests__/TaskForm.submit.test.ts +0 -21
  349. package/src/modules/customers/components/detail/hooks/__tests__/useCustomerDictionary.test.ts +0 -97
  350. package/src/modules/customers/lib/__tests__/customFieldRouting.test.ts +0 -107
  351. package/src/modules/customers/utils/__tests__/addressFormat.test.ts +0 -105
  352. package/src/modules/customers/utils/__tests__/phoneDuplicates.test.ts +0 -98
  353. package/src/modules/dashboards/__tests__/widgets.test.ts +0 -70
  354. package/src/modules/dashboards/lib/__tests__/aggregations.test.ts +0 -328
  355. package/src/modules/dashboards/lib/__tests__/formatters.test.ts +0 -128
  356. package/src/modules/directory/backend/directory/organizations/__tests__/create-submit.test.ts +0 -46
  357. package/src/modules/directory/backend/directory/organizations/__tests__/edit-submit.test.ts +0 -49
  358. package/src/modules/directory/components/__tests__/OrganizationSelect.test.tsx +0 -71
  359. package/src/modules/directory/components/__tests__/TenantSelect.test.tsx +0 -75
  360. package/src/modules/entities/__tests__/cli-decrypt-database.test.ts +0 -534
  361. package/src/modules/entities/__tests__/cli-rotate-encryption.test.ts +0 -123
  362. package/src/modules/entities/api/__tests__/encryption.api.test.ts +0 -57
  363. package/src/modules/entities/api/__tests__/records.get.custom-entity.test.ts +0 -43
  364. package/src/modules/entities/api/__tests__/records.validation.test.ts +0 -53
  365. package/src/modules/entities/backend/entities/user/__tests__/create-entity-submit.test.ts +0 -47
  366. package/src/modules/entities/backend/entities/user/__tests__/records-submit.test.ts +0 -104
  367. package/src/modules/feature_toggles/commands/__tests__/global.test.ts +0 -325
  368. package/src/modules/feature_toggles/commands/__tests__/overrides.test.ts +0 -186
  369. package/src/modules/feature_toggles/lib/__tests__/feature-flag-check.test.ts +0 -365
  370. package/src/modules/feature_toggles/lib/__tests__/queries.test.ts +0 -130
  371. package/src/modules/inbox_ops/api/emails/[id]/reprocess/__tests__/route.test.ts +0 -194
  372. package/src/modules/inbox_ops/api/proposals/[id]/__tests__/route.test.ts +0 -124
  373. package/src/modules/inbox_ops/api/proposals/[id]/accept-all/__tests__/route.test.ts +0 -154
  374. package/src/modules/inbox_ops/api/proposals/[id]/actions/[actionId]/__tests__/route.test.ts +0 -200
  375. package/src/modules/inbox_ops/api/proposals/[id]/actions/[actionId]/accept/__tests__/route.test.ts +0 -261
  376. package/src/modules/inbox_ops/api/proposals/[id]/actions/[actionId]/reject/__tests__/route.test.ts +0 -201
  377. package/src/modules/inbox_ops/api/proposals/[id]/reject/__tests__/route.test.ts +0 -123
  378. package/src/modules/inbox_ops/api/proposals/[id]/replies/[replyId]/send/__tests__/route.test.ts +0 -232
  379. package/src/modules/inbox_ops/api/proposals/[id]/translate/__tests__/route.test.ts +0 -173
  380. package/src/modules/inbox_ops/api/proposals/__tests__/route.test.ts +0 -185
  381. package/src/modules/inbox_ops/api/webhook/__tests__/inbound.test.ts +0 -317
  382. package/src/modules/inbox_ops/data/__tests__/validators.test.ts +0 -463
  383. package/src/modules/inbox_ops/lib/__tests__/catalogLookup.test.ts +0 -143
  384. package/src/modules/inbox_ops/lib/__tests__/contactMatcher.test.ts +0 -158
  385. package/src/modules/inbox_ops/lib/__tests__/emailParser.test.ts +0 -191
  386. package/src/modules/inbox_ops/lib/__tests__/executionEngine.test.ts +0 -1419
  387. package/src/modules/inbox_ops/lib/__tests__/extractionPrompt.test.ts +0 -151
  388. package/src/modules/inbox_ops/lib/__tests__/priceValidator.test.ts +0 -259
  389. package/src/modules/inbox_ops/lib/__tests__/translationProvider.test.ts +0 -99
  390. package/src/modules/inbox_ops/subscribers/__tests__/extractionWorker.test.ts +0 -803
  391. package/src/modules/notifications/__tests__/deliver-notification.test.ts +0 -285
  392. package/src/modules/notifications/__tests__/deliveryStrategies.test.ts +0 -19
  393. package/src/modules/notifications/__tests__/notificationService.test.ts +0 -248
  394. package/src/modules/planner/__tests__/availabilityMerge.test.ts +0 -99
  395. package/src/modules/planner/__tests__/plannerAvailabilityService.test.ts +0 -89
  396. package/src/modules/planner/data/__tests__/validators.test.ts +0 -78
  397. package/src/modules/progress/__integration__/TC-PROG-001.spec.ts +0 -67
  398. package/src/modules/progress/__tests__/progressService.test.ts +0 -377
  399. package/src/modules/query_index/__tests__/hybrid-engine.test.ts +0 -365
  400. package/src/modules/query_index/__tests__/indexer.test.ts +0 -175
  401. package/src/modules/resources/__integration__/TC-INT-007.spec.ts +0 -110
  402. package/src/modules/resources/__integration__/helpers/resourcesFixtures.ts +0 -50
  403. package/src/modules/resources/data/__tests__/validators.test.ts +0 -65
  404. package/src/modules/sales/__integration__/TC-SALES-001.spec.ts +0 -26
  405. package/src/modules/sales/__integration__/TC-SALES-002.spec.ts +0 -38
  406. package/src/modules/sales/__integration__/TC-SALES-003.spec.ts +0 -18
  407. package/src/modules/sales/__integration__/TC-SALES-004.spec.ts +0 -19
  408. package/src/modules/sales/__integration__/TC-SALES-005.spec.ts +0 -21
  409. package/src/modules/sales/__integration__/TC-SALES-006.spec.ts +0 -26
  410. package/src/modules/sales/__integration__/TC-SALES-007.spec.ts +0 -23
  411. package/src/modules/sales/__integration__/TC-SALES-008.spec.ts +0 -11
  412. package/src/modules/sales/__integration__/TC-SALES-009.spec.ts +0 -12
  413. package/src/modules/sales/__integration__/TC-SALES-010.spec.ts +0 -20
  414. package/src/modules/sales/__integration__/TC-SALES-011.spec.ts +0 -26
  415. package/src/modules/sales/__integration__/TC-SALES-012.spec.ts +0 -12
  416. package/src/modules/sales/__integration__/TC-SALES-013.spec.ts +0 -73
  417. package/src/modules/sales/__integration__/TC-SALES-014.spec.ts +0 -17
  418. package/src/modules/sales/__integration__/TC-SALES-015.spec.ts +0 -17
  419. package/src/modules/sales/__integration__/TC-SALES-016.spec.ts +0 -17
  420. package/src/modules/sales/__integration__/TC-SALES-017.spec.ts +0 -60
  421. package/src/modules/sales/__integration__/TC-SALES-018.spec.ts +0 -25
  422. package/src/modules/sales/__integration__/TC-SALES-019.spec.ts +0 -22
  423. package/src/modules/sales/__integration__/TC-SALES-020.spec.ts +0 -107
  424. package/src/modules/sales/api/__tests__/channels.route.test.ts +0 -50
  425. package/src/modules/sales/api/__tests__/document-history.test.ts +0 -146
  426. package/src/modules/sales/api/__tests__/documents.factory.test.ts +0 -98
  427. package/src/modules/sales/api/__tests__/documents.routes.test.ts +0 -149
  428. package/src/modules/sales/api/__tests__/quotes.acceptance.test.ts +0 -209
  429. package/src/modules/sales/api/__tests__/timeline.test.tsx +0 -165
  430. package/src/modules/sales/api/dashboard/widgets/new-orders/__tests__/route.test.ts +0 -112
  431. package/src/modules/sales/api/dashboard/widgets/new-quotes/__tests__/route.test.ts +0 -116
  432. package/src/modules/sales/commands/__tests__/documents.cache.test.ts +0 -126
  433. package/src/modules/sales/commands/__tests__/documents.undo.test.ts +0 -170
  434. package/src/modules/sales/commands/__tests__/registration.test.ts +0 -141
  435. package/src/modules/sales/components/__tests__/salesComponentsRender.test.tsx +0 -456
  436. package/src/modules/sales/lib/__tests__/calculations.test.ts +0 -210
  437. package/src/modules/sales/services/__tests__/salesCalculationService.test.ts +0 -181
  438. package/src/modules/sales/services/__tests__/taxCalculationService.test.ts +0 -79
  439. package/src/modules/sales/widgets/dashboard/new-orders/__tests__/config.test.ts +0 -47
  440. package/src/modules/sales/widgets/dashboard/new-quotes/__tests__/config.test.ts +0 -47
  441. package/src/modules/staff/__integration__/TC-INT-006.spec.ts +0 -71
  442. package/src/modules/staff/data/__tests__/validators.test.ts +0 -60
  443. package/src/modules/translations/__integration__/TC-TRANS-001.spec.ts +0 -57
  444. package/src/modules/translations/__integration__/TC-TRANS-002.spec.ts +0 -114
  445. package/src/modules/translations/__integration__/TC-TRANS-003.spec.ts +0 -71
  446. package/src/modules/translations/__integration__/TC-TRANS-004.spec.ts +0 -66
  447. package/src/modules/translations/__integration__/TC-TRANS-005.spec.ts +0 -135
  448. package/src/modules/translations/__integration__/TC-TRANS-006.spec.ts +0 -113
  449. package/src/modules/translations/__integration__/TC-TRANS-007.spec.ts +0 -80
  450. package/src/modules/translations/__integration__/TC-TRANS-008.spec.ts +0 -209
  451. package/src/modules/translations/__integration__/helpers/translationFixtures.ts +0 -95
  452. package/src/modules/translations/api/__tests__/locales.test.ts +0 -67
  453. package/src/modules/translations/data/__tests__/validators.test.ts +0 -143
  454. package/src/modules/translations/lib/__tests__/extract-record-id.test.ts +0 -75
  455. package/src/modules/translations/lib/__tests__/helpers.test.ts +0 -215
  456. package/src/modules/translations/lib/__tests__/locale.test.ts +0 -115
  457. package/src/modules/translations/lib/__tests__/resolve-field-list.test.ts +0 -176
  458. package/src/modules/translations/lib/__tests__/translatable-fields.test.ts +0 -79
  459. package/src/modules/translations/widgets/__tests__/injection-table.test.ts +0 -83
  460. package/src/modules/workflows/__integration__/TC-WF-001.spec.ts +0 -114
  461. package/src/modules/workflows/api/__tests__/definitions.route.test.ts +0 -762
  462. package/src/modules/workflows/api/__tests__/instances.route.test.ts +0 -869
  463. package/src/modules/workflows/data/__tests__/validators.test.ts +0 -707
  464. package/src/modules/workflows/lib/__tests__/activity-executor.test.ts +0 -1230
  465. package/src/modules/workflows/lib/__tests__/call-api.test.ts +0 -421
  466. package/src/modules/workflows/lib/__tests__/compensation.test.ts +0 -713
  467. package/src/modules/workflows/lib/__tests__/event-logger.test.ts +0 -615
  468. package/src/modules/workflows/lib/__tests__/integration.test.ts +0 -693
  469. package/src/modules/workflows/lib/__tests__/signals.test.ts +0 -566
  470. package/src/modules/workflows/lib/__tests__/step-handler.test.ts +0 -670
  471. package/src/modules/workflows/lib/__tests__/sub-workflow.test.ts +0 -934
  472. package/src/modules/workflows/lib/__tests__/transition-handler.test.ts +0 -925
  473. package/src/modules/workflows/lib/__tests__/workflow-executor.test.ts +0 -684
@@ -1,869 +0,0 @@
1
- /**
2
- * Workflow Instances API Tests
3
- *
4
- * Tests all operations for workflow instances API
5
- */
6
-
7
- import { NextRequest } from 'next/server'
8
- import { GET as listInstances, POST as startInstance } from '../instances/route'
9
- import { GET as getInstance } from '../instances/[id]/route'
10
- import { POST as cancelInstance } from '../instances/[id]/cancel/route'
11
- import { POST as retryInstance } from '../instances/[id]/retry/route'
12
- import { GET as getInstanceEvents } from '../instances/[id]/events/route'
13
- import { WorkflowInstance, WorkflowDefinition, WorkflowEvent } from '../../data/entities'
14
- import * as workflowExecutor from '../../lib/workflow-executor'
15
-
16
- // Mock dependencies
17
- jest.mock('@open-mercato/shared/lib/di/container', () => ({
18
- createRequestContainer: jest.fn(),
19
- }))
20
-
21
- jest.mock('@open-mercato/shared/lib/auth/server', () => ({
22
- getAuthFromRequest: jest.fn(),
23
- }))
24
-
25
- jest.mock('@open-mercato/core/modules/directory/utils/organizationScope', () => ({
26
- resolveOrganizationScopeForRequest: jest.fn(),
27
- }))
28
-
29
- jest.mock('../../lib/workflow-executor', () => ({
30
- startWorkflow: jest.fn(),
31
- executeWorkflow: jest.fn(),
32
- completeWorkflow: jest.fn(),
33
- WorkflowExecutionError: class WorkflowExecutionError extends Error {
34
- constructor(message: string, public code: string, public details?: any) {
35
- super(message)
36
- this.name = 'WorkflowExecutionError'
37
- }
38
- },
39
- }))
40
-
41
- describe('Workflow Instances API', () => {
42
- let mockContainer: any
43
- let mockEm: any
44
- let mockAuthContext: any
45
- let mockRbacService: any
46
-
47
- const testTenantId = 'test-tenant-id'
48
- const testOrgId = 'test-org-id'
49
- const testUserId = 'test-user-id'
50
- const testInstanceId = 'test-instance-id'
51
- const testDefinitionId = 'test-definition-id'
52
-
53
- beforeEach(() => {
54
- // Setup mocks
55
- mockAuthContext = {
56
- tenantId: testTenantId,
57
- organizationId: testOrgId,
58
- userId: testUserId,
59
- }
60
-
61
- mockRbacService = {
62
- userHasAllFeatures: jest.fn().mockResolvedValue(true),
63
- }
64
-
65
- mockEm = {
66
- findOne: jest.fn(),
67
- find: jest.fn(),
68
- findAndCount: jest.fn(),
69
- count: jest.fn(),
70
- create: jest.fn(),
71
- persistAndFlush: jest.fn(),
72
- flush: jest.fn(),
73
- refresh: jest.fn(),
74
- }
75
-
76
- mockContainer = {
77
- resolve: jest.fn((name: string) => {
78
- if (name === 'em') return mockEm
79
- if (name === 'authContext') return mockAuthContext
80
- if (name === 'rbacService') return mockRbacService
81
- return null
82
- }),
83
- }
84
-
85
- const { createRequestContainer } = require('@open-mercato/shared/lib/di/container')
86
- createRequestContainer.mockResolvedValue(mockContainer)
87
-
88
- const { getAuthFromRequest } = require('@open-mercato/shared/lib/auth/server')
89
- getAuthFromRequest.mockResolvedValue({
90
- sub: testUserId,
91
- tenantId: testTenantId,
92
- orgId: testOrgId,
93
- })
94
-
95
- const { resolveOrganizationScopeForRequest } = require('@open-mercato/core/modules/directory/utils/organizationScope')
96
- resolveOrganizationScopeForRequest.mockResolvedValue({
97
- selectedId: testOrgId,
98
- })
99
-
100
- jest.clearAllMocks()
101
- })
102
-
103
- // ============================================================================
104
- // GET /api/workflows/instances - List Instances
105
- // ============================================================================
106
-
107
- describe('GET /api/workflows/instances', () => {
108
- test('should list workflow instances with default pagination', async () => {
109
- const mockInstances = [
110
- {
111
- id: testInstanceId,
112
- workflowId: 'checkout',
113
- version: 1,
114
- status: 'RUNNING',
115
- currentStepId: 'payment',
116
- context: { cartId: '123' },
117
- tenantId: testTenantId,
118
- organizationId: testOrgId,
119
- },
120
- ]
121
-
122
- mockEm.findAndCount.mockResolvedValue([mockInstances, 1])
123
-
124
- const request = new NextRequest('http://localhost/api/workflows/instances')
125
- const response = await listInstances(request)
126
- const data = await response.json()
127
-
128
- expect(response.status).toBe(200)
129
- expect(data.data).toEqual(mockInstances)
130
- expect(data.pagination).toEqual({
131
- total: 1,
132
- limit: 50,
133
- offset: 0,
134
- hasMore: false,
135
- })
136
- expect(mockEm.findAndCount).toHaveBeenCalledWith(
137
- WorkflowInstance,
138
- expect.objectContaining({
139
- tenantId: testTenantId,
140
- organizationId: testOrgId,
141
- }),
142
- expect.any(Object)
143
- )
144
- })
145
-
146
- test('should filter instances by workflowId', async () => {
147
- mockEm.findAndCount.mockResolvedValue([[], 0])
148
-
149
- const request = new NextRequest('http://localhost/api/workflows/instances?workflowId=checkout')
150
- await listInstances(request)
151
-
152
- expect(mockEm.findAndCount).toHaveBeenCalledWith(
153
- WorkflowInstance,
154
- expect.objectContaining({
155
- workflowId: 'checkout',
156
- }),
157
- expect.any(Object)
158
- )
159
- })
160
-
161
- test('should filter instances by status', async () => {
162
- mockEm.findAndCount.mockResolvedValue([[], 0])
163
-
164
- const request = new NextRequest('http://localhost/api/workflows/instances?status=RUNNING')
165
- await listInstances(request)
166
-
167
- expect(mockEm.findAndCount).toHaveBeenCalledWith(
168
- WorkflowInstance,
169
- expect.objectContaining({
170
- status: 'RUNNING',
171
- }),
172
- expect.any(Object)
173
- )
174
- })
175
-
176
- test('should filter instances by correlationKey', async () => {
177
- mockEm.findAndCount.mockResolvedValue([[], 0])
178
-
179
- const request = new NextRequest('http://localhost/api/workflows/instances?correlationKey=order-123')
180
- await listInstances(request)
181
-
182
- expect(mockEm.findAndCount).toHaveBeenCalledWith(
183
- WorkflowInstance,
184
- expect.objectContaining({
185
- correlationKey: 'order-123',
186
- }),
187
- expect.any(Object)
188
- )
189
- })
190
-
191
- test('should filter instances by entityType and entityId', async () => {
192
- mockEm.findAndCount.mockResolvedValue([[], 0])
193
-
194
- const request = new NextRequest('http://localhost/api/workflows/instances?entityType=order&entityId=order-123')
195
- await listInstances(request)
196
-
197
- // The implementation uses JSONB $contains queries for metadata filtering
198
- expect(mockEm.findAndCount).toHaveBeenCalledWith(
199
- WorkflowInstance,
200
- expect.objectContaining({
201
- $and: expect.arrayContaining([
202
- { metadata: { $contains: { entityType: 'order' } } },
203
- { metadata: { $contains: { entityId: 'order-123' } } },
204
- ]),
205
- }),
206
- expect.any(Object)
207
- )
208
- })
209
-
210
- test('should support custom pagination', async () => {
211
- mockEm.findAndCount.mockResolvedValue([[], 100])
212
-
213
- const request = new NextRequest('http://localhost/api/workflows/instances?limit=10&offset=20')
214
- const response = await listInstances(request)
215
- const data = await response.json()
216
-
217
- expect(data.pagination).toEqual({
218
- total: 100,
219
- limit: 10,
220
- offset: 20,
221
- hasMore: true,
222
- })
223
- })
224
-
225
- test('should return 401 when not authenticated', async () => {
226
- const { getAuthFromRequest } = require('@open-mercato/shared/lib/auth/server')
227
- getAuthFromRequest.mockResolvedValue(null)
228
-
229
- const request = new NextRequest('http://localhost/api/workflows/instances')
230
- const response = await listInstances(request)
231
-
232
- expect(response.status).toBe(401)
233
- })
234
-
235
- test('should handle database errors', async () => {
236
- mockEm.findAndCount.mockRejectedValue(new Error('Database error'))
237
-
238
- const request = new NextRequest('http://localhost/api/workflows/instances')
239
- const response = await listInstances(request)
240
-
241
- expect(response.status).toBe(500)
242
- })
243
- })
244
-
245
- // ============================================================================
246
- // POST /api/workflows/instances - Start Instance
247
- // ============================================================================
248
-
249
- describe('POST /api/workflows/instances', () => {
250
- const mockInstance = {
251
- id: testInstanceId,
252
- workflowId: 'checkout',
253
- version: 1,
254
- status: 'RUNNING',
255
- currentStepId: 'start',
256
- context: { cartId: '123' },
257
- tenantId: testTenantId,
258
- organizationId: testOrgId,
259
- }
260
-
261
- const mockExecutionResult = {
262
- status: 'RUNNING',
263
- currentStep: 'payment',
264
- context: { cartId: '123' },
265
- events: [],
266
- executionTime: 100,
267
- }
268
-
269
- test('should start workflow successfully', async () => {
270
- (workflowExecutor.startWorkflow as jest.Mock).mockResolvedValue(mockInstance);
271
- (workflowExecutor.executeWorkflow as jest.Mock).mockResolvedValue(mockExecutionResult)
272
-
273
- const request = new NextRequest('http://localhost/api/workflows/instances', {
274
- method: 'POST',
275
- body: JSON.stringify({
276
- workflowId: 'checkout',
277
- initialContext: { cartId: '123' },
278
- }),
279
- })
280
-
281
- const response = await startInstance(request)
282
- const data = await response.json()
283
-
284
- expect(response.status).toBe(201)
285
- expect(data.data.instance).toEqual(mockInstance)
286
- expect(data.data.execution).toEqual({
287
- status: mockInstance.status,
288
- currentStep: mockInstance.currentStepId,
289
- message: 'Workflow execution started in background',
290
- })
291
- expect(data.message).toBe('Workflow started successfully')
292
- expect(workflowExecutor.startWorkflow).toHaveBeenCalledWith(
293
- mockEm,
294
- expect.objectContaining({
295
- workflowId: 'checkout',
296
- initialContext: { cartId: '123' },
297
- tenantId: testTenantId,
298
- organizationId: testOrgId,
299
- })
300
- )
301
- })
302
-
303
- test('should inject initiatedBy from auth context', async () => {
304
- (workflowExecutor.startWorkflow as jest.Mock).mockResolvedValue(mockInstance);
305
- (workflowExecutor.executeWorkflow as jest.Mock).mockResolvedValue(mockExecutionResult)
306
-
307
- const request = new NextRequest('http://localhost/api/workflows/instances', {
308
- method: 'POST',
309
- body: JSON.stringify({
310
- workflowId: 'checkout',
311
- initialContext: {},
312
- }),
313
- })
314
-
315
- await startInstance(request)
316
-
317
- expect(workflowExecutor.startWorkflow).toHaveBeenCalledWith(
318
- mockEm,
319
- expect.objectContaining({
320
- metadata: expect.objectContaining({
321
- initiatedBy: testUserId,
322
- }),
323
- })
324
- )
325
- })
326
-
327
- test('should require create permission', async () => {
328
- mockRbacService.userHasAllFeatures.mockResolvedValue(false)
329
-
330
- const request = new NextRequest('http://localhost/api/workflows/instances', {
331
- method: 'POST',
332
- body: JSON.stringify({
333
- workflowId: 'checkout',
334
- }),
335
- })
336
-
337
- const response = await startInstance(request)
338
-
339
- expect(response.status).toBe(403)
340
- expect(mockRbacService.userHasAllFeatures).toHaveBeenCalledWith(
341
- testUserId,
342
- ['workflows.instances.create'],
343
- expect.any(Object)
344
- )
345
- })
346
-
347
- test('should validate input', async () => {
348
- const request = new NextRequest('http://localhost/api/workflows/instances', {
349
- method: 'POST',
350
- body: JSON.stringify({
351
- // Missing workflowId
352
- initialContext: {},
353
- }),
354
- })
355
-
356
- const response = await startInstance(request)
357
- const data = await response.json()
358
-
359
- expect(response.status).toBe(400)
360
- expect(data.error).toBe('Validation failed')
361
- expect(data.details).toBeDefined()
362
- })
363
-
364
- test('should handle workflow definition not found', async () => {
365
- const error = new workflowExecutor.WorkflowExecutionError(
366
- 'Workflow definition not found',
367
- 'DEFINITION_NOT_FOUND'
368
- );
369
- (workflowExecutor.startWorkflow as jest.Mock).mockRejectedValue(error)
370
-
371
- const request = new NextRequest('http://localhost/api/workflows/instances', {
372
- method: 'POST',
373
- body: JSON.stringify({
374
- workflowId: 'nonexistent',
375
- }),
376
- })
377
-
378
- const response = await startInstance(request)
379
-
380
- expect(response.status).toBe(404)
381
- })
382
-
383
- test('should handle disabled workflow definition', async () => {
384
- const error = new workflowExecutor.WorkflowExecutionError(
385
- 'Workflow definition is disabled',
386
- 'DEFINITION_DISABLED'
387
- );
388
- (workflowExecutor.startWorkflow as jest.Mock).mockRejectedValue(error)
389
-
390
- const request = new NextRequest('http://localhost/api/workflows/instances', {
391
- method: 'POST',
392
- body: JSON.stringify({
393
- workflowId: 'checkout',
394
- }),
395
- })
396
-
397
- const response = await startInstance(request)
398
-
399
- expect(response.status).toBe(400)
400
- })
401
-
402
- test('should handle invalid workflow definition', async () => {
403
- const error = new workflowExecutor.WorkflowExecutionError(
404
- 'Workflow definition must have at least START and END steps',
405
- 'INVALID_DEFINITION'
406
- );
407
- (workflowExecutor.startWorkflow as jest.Mock).mockRejectedValue(error)
408
-
409
- const request = new NextRequest('http://localhost/api/workflows/instances', {
410
- method: 'POST',
411
- body: JSON.stringify({
412
- workflowId: 'checkout',
413
- }),
414
- })
415
-
416
- const response = await startInstance(request)
417
-
418
- expect(response.status).toBe(400)
419
- })
420
-
421
- test('should return 401 when not authenticated', async () => {
422
- const { getAuthFromRequest } = require('@open-mercato/shared/lib/auth/server')
423
- getAuthFromRequest.mockResolvedValue(null)
424
-
425
- const request = new NextRequest('http://localhost/api/workflows/instances', {
426
- method: 'POST',
427
- body: JSON.stringify({
428
- workflowId: 'checkout',
429
- }),
430
- })
431
-
432
- const response = await startInstance(request)
433
-
434
- expect(response.status).toBe(401)
435
- })
436
-
437
- test('should handle generic errors', async () => {
438
- (workflowExecutor.startWorkflow as jest.Mock).mockRejectedValue(new Error('Database error'))
439
-
440
- const request = new NextRequest('http://localhost/api/workflows/instances', {
441
- method: 'POST',
442
- body: JSON.stringify({
443
- workflowId: 'checkout',
444
- }),
445
- })
446
-
447
- const response = await startInstance(request)
448
-
449
- expect(response.status).toBe(500)
450
- })
451
- })
452
-
453
- // ============================================================================
454
- // GET /api/workflows/instances/[id] - Get Instance
455
- // ============================================================================
456
-
457
- describe('GET /api/workflows/instances/[id]', () => {
458
- test('should get instance by id', async () => {
459
- const mockInstance = {
460
- id: testInstanceId,
461
- workflowId: 'checkout',
462
- status: 'RUNNING',
463
- tenantId: testTenantId,
464
- organizationId: testOrgId,
465
- }
466
-
467
- mockEm.findOne.mockResolvedValue(mockInstance)
468
-
469
- const request = new NextRequest(`http://localhost/api/workflows/instances/${testInstanceId}`)
470
- const response = await getInstance(request, { params: Promise.resolve({ id: testInstanceId }) })
471
- const data = await response.json()
472
-
473
- expect(response.status).toBe(200)
474
- expect(data.data).toEqual(mockInstance)
475
- expect(mockEm.findOne).toHaveBeenCalledWith(
476
- WorkflowInstance,
477
- expect.objectContaining({
478
- id: testInstanceId,
479
- tenantId: testTenantId,
480
- organizationId: testOrgId,
481
- })
482
- )
483
- })
484
-
485
- test('should return 404 when instance not found', async () => {
486
- mockEm.findOne.mockResolvedValue(null)
487
-
488
- const request = new NextRequest(`http://localhost/api/workflows/instances/${testInstanceId}`)
489
- const response = await getInstance(request, { params: Promise.resolve({ id: testInstanceId }) })
490
-
491
- expect(response.status).toBe(404)
492
- })
493
-
494
- test('should enforce tenant isolation', async () => {
495
- mockEm.findOne.mockResolvedValue(null)
496
-
497
- const request = new NextRequest(`http://localhost/api/workflows/instances/${testInstanceId}`)
498
- await getInstance(request, { params: Promise.resolve({ id: testInstanceId }) })
499
-
500
- expect(mockEm.findOne).toHaveBeenCalledWith(
501
- WorkflowInstance,
502
- expect.objectContaining({
503
- tenantId: testTenantId,
504
- organizationId: testOrgId,
505
- })
506
- )
507
- })
508
-
509
- test('should return 401 when not authenticated', async () => {
510
- const { getAuthFromRequest } = require('@open-mercato/shared/lib/auth/server')
511
- getAuthFromRequest.mockResolvedValue(null)
512
-
513
- const request = new NextRequest(`http://localhost/api/workflows/instances/${testInstanceId}`)
514
- const response = await getInstance(request, { params: Promise.resolve({ id: testInstanceId }) })
515
-
516
- expect(response.status).toBe(401)
517
- })
518
- })
519
-
520
- // ============================================================================
521
- // POST /api/workflows/instances/[id]/cancel - Cancel Instance
522
- // ============================================================================
523
-
524
- describe('POST /api/workflows/instances/[id]/cancel', () => {
525
- test('should cancel running instance', async () => {
526
- const mockInstance = {
527
- id: testInstanceId,
528
- workflowId: 'checkout',
529
- status: 'RUNNING',
530
- tenantId: testTenantId,
531
- organizationId: testOrgId,
532
- }
533
-
534
- mockEm.findOne.mockResolvedValue(mockInstance);
535
- (workflowExecutor.completeWorkflow as jest.Mock).mockResolvedValue(undefined)
536
-
537
- const request = new NextRequest(`http://localhost/api/workflows/instances/${testInstanceId}/cancel`, {
538
- method: 'POST',
539
- })
540
- const response = await cancelInstance(request, { params: Promise.resolve({ id: testInstanceId }) })
541
- const data = await response.json()
542
-
543
- expect(response.status).toBe(200)
544
- expect(data.message).toBe('Workflow cancelled successfully')
545
- expect(workflowExecutor.completeWorkflow).toHaveBeenCalledWith(mockEm, expect.any(Object), testInstanceId, 'CANCELLED')
546
- expect(mockEm.refresh).toHaveBeenCalledWith(mockInstance)
547
- })
548
-
549
- test('should cancel paused instance', async () => {
550
- const mockInstance = {
551
- id: testInstanceId,
552
- status: 'PAUSED',
553
- tenantId: testTenantId,
554
- organizationId: testOrgId,
555
- }
556
-
557
- mockEm.findOne.mockResolvedValue(mockInstance);
558
- (workflowExecutor.completeWorkflow as jest.Mock).mockResolvedValue(undefined)
559
-
560
- const request = new NextRequest(`http://localhost/api/workflows/instances/${testInstanceId}/cancel`, {
561
- method: 'POST',
562
- })
563
- const response = await cancelInstance(request, { params: Promise.resolve({ id: testInstanceId }) })
564
-
565
- expect(response.status).toBe(200)
566
- })
567
-
568
- test('should require cancel permission', async () => {
569
- mockRbacService.userHasAllFeatures.mockResolvedValue(false)
570
-
571
- const request = new NextRequest(`http://localhost/api/workflows/instances/${testInstanceId}/cancel`, {
572
- method: 'POST',
573
- })
574
- const response = await cancelInstance(request, { params: Promise.resolve({ id: testInstanceId }) })
575
-
576
- expect(response.status).toBe(403)
577
- })
578
-
579
- test('should return 404 when instance not found', async () => {
580
- mockEm.findOne.mockResolvedValue(null)
581
-
582
- const request = new NextRequest(`http://localhost/api/workflows/instances/${testInstanceId}/cancel`, {
583
- method: 'POST',
584
- })
585
- const response = await cancelInstance(request, { params: Promise.resolve({ id: testInstanceId }) })
586
-
587
- expect(response.status).toBe(404)
588
- })
589
-
590
- test('should reject cancelling completed workflow', async () => {
591
- const mockInstance = {
592
- id: testInstanceId,
593
- status: 'COMPLETED',
594
- tenantId: testTenantId,
595
- organizationId: testOrgId,
596
- }
597
-
598
- mockEm.findOne.mockResolvedValue(mockInstance)
599
-
600
- const request = new NextRequest(`http://localhost/api/workflows/instances/${testInstanceId}/cancel`, {
601
- method: 'POST',
602
- })
603
- const response = await cancelInstance(request, { params: Promise.resolve({ id: testInstanceId }) })
604
- const data = await response.json()
605
-
606
- expect(response.status).toBe(400)
607
- expect(data.error).toContain('Cannot cancel workflow in COMPLETED status')
608
- })
609
-
610
- test('should reject cancelling failed workflow', async () => {
611
- const mockInstance = {
612
- id: testInstanceId,
613
- status: 'FAILED',
614
- tenantId: testTenantId,
615
- organizationId: testOrgId,
616
- }
617
-
618
- mockEm.findOne.mockResolvedValue(mockInstance)
619
-
620
- const request = new NextRequest(`http://localhost/api/workflows/instances/${testInstanceId}/cancel`, {
621
- method: 'POST',
622
- })
623
- const response = await cancelInstance(request, { params: Promise.resolve({ id: testInstanceId }) })
624
-
625
- expect(response.status).toBe(400)
626
- })
627
- })
628
-
629
- // ============================================================================
630
- // POST /api/workflows/instances/[id]/retry - Retry Instance
631
- // ============================================================================
632
-
633
- describe('POST /api/workflows/instances/[id]/retry', () => {
634
- test('should retry failed instance', async () => {
635
- const mockInstance = {
636
- id: testInstanceId,
637
- workflowId: 'checkout',
638
- status: 'FAILED',
639
- retryCount: 0,
640
- tenantId: testTenantId,
641
- organizationId: testOrgId,
642
- errorMessage: 'Test error',
643
- definitionId: 'def-1',
644
- version: 1,
645
- currentStepId: 'payment',
646
- context: {},
647
- startedAt: new Date(),
648
- createdAt: new Date(),
649
- updatedAt: new Date(),
650
- }
651
-
652
- const mockExecutionResult = {
653
- status: 'RUNNING',
654
- currentStep: 'payment',
655
- context: {},
656
- events: [],
657
- executionTime: 100,
658
- }
659
-
660
- mockEm.findOne.mockResolvedValue(mockInstance);
661
- (workflowExecutor.executeWorkflow as jest.Mock).mockResolvedValue(mockExecutionResult)
662
-
663
- const request = new NextRequest(`http://localhost/api/workflows/instances/${testInstanceId}/retry`, {
664
- method: 'POST',
665
- })
666
- const response = await retryInstance(request, { params: Promise.resolve({ id: testInstanceId }) })
667
- const data = await response.json()
668
-
669
- expect(response.status).toBe(200)
670
- expect(data.message).toBe('Workflow retry initiated successfully')
671
- expect(mockInstance.status).toBe('RUNNING')
672
- expect(mockInstance.retryCount).toBe(1)
673
- expect(mockInstance.errorMessage).toBeNull()
674
- expect(mockEm.flush).toHaveBeenCalled()
675
- expect(workflowExecutor.executeWorkflow).toHaveBeenCalledWith(mockEm, mockContainer, testInstanceId)
676
- })
677
-
678
- test('should require retry permission', async () => {
679
- mockRbacService.userHasAllFeatures.mockResolvedValue(false)
680
-
681
- const request = new NextRequest(`http://localhost/api/workflows/instances/${testInstanceId}/retry`, {
682
- method: 'POST',
683
- })
684
- const response = await retryInstance(request, { params: Promise.resolve({ id: testInstanceId }) })
685
-
686
- expect(response.status).toBe(403)
687
- })
688
-
689
- test('should return 404 when instance not found', async () => {
690
- mockEm.findOne.mockResolvedValue(null)
691
-
692
- const request = new NextRequest(`http://localhost/api/workflows/instances/${testInstanceId}/retry`, {
693
- method: 'POST',
694
- })
695
- const response = await retryInstance(request, { params: Promise.resolve({ id: testInstanceId }) })
696
-
697
- expect(response.status).toBe(404)
698
- })
699
-
700
- test('should reject retrying non-failed workflow', async () => {
701
- const mockInstance = {
702
- id: testInstanceId,
703
- status: 'RUNNING',
704
- tenantId: testTenantId,
705
- organizationId: testOrgId,
706
- }
707
-
708
- mockEm.findOne.mockResolvedValue(mockInstance)
709
-
710
- const request = new NextRequest(`http://localhost/api/workflows/instances/${testInstanceId}/retry`, {
711
- method: 'POST',
712
- })
713
- const response = await retryInstance(request, { params: Promise.resolve({ id: testInstanceId }) })
714
- const data = await response.json()
715
-
716
- expect(response.status).toBe(400)
717
- expect(data.error).toContain('Cannot retry workflow in RUNNING status')
718
- })
719
-
720
- test('should handle execution errors during retry', async () => {
721
- const mockInstance = {
722
- id: testInstanceId,
723
- status: 'FAILED',
724
- retryCount: 0,
725
- tenantId: testTenantId,
726
- organizationId: testOrgId,
727
- }
728
-
729
- mockEm.findOne.mockResolvedValue(mockInstance)
730
- const error = new workflowExecutor.WorkflowExecutionError('Execution failed', 'EXECUTION_ERROR');
731
- (workflowExecutor.executeWorkflow as jest.Mock).mockRejectedValue(error)
732
-
733
- const request = new NextRequest(`http://localhost/api/workflows/instances/${testInstanceId}/retry`, {
734
- method: 'POST',
735
- })
736
- const response = await retryInstance(request, { params: Promise.resolve({ id: testInstanceId }) })
737
-
738
- expect(response.status).toBe(400)
739
- })
740
- })
741
-
742
- // ============================================================================
743
- // GET /api/workflows/instances/[id]/events - Get Instance Events
744
- // ============================================================================
745
-
746
- describe('GET /api/workflows/instances/[id]/events', () => {
747
- const mockInstance = {
748
- id: testInstanceId,
749
- tenantId: testTenantId,
750
- organizationId: testOrgId,
751
- }
752
-
753
- test('should get events for instance', async () => {
754
- const testDate = new Date('2025-01-01T00:00:00Z')
755
- const mockEvents = [
756
- {
757
- id: 'event-1',
758
- workflowInstanceId: testInstanceId,
759
- eventType: 'WORKFLOW_STARTED',
760
- eventData: {},
761
- occurredAt: testDate,
762
- tenantId: testTenantId,
763
- organizationId: testOrgId,
764
- },
765
- {
766
- id: 'event-2',
767
- workflowInstanceId: testInstanceId,
768
- eventType: 'TRANSITION_EXECUTED',
769
- eventData: {},
770
- occurredAt: testDate,
771
- tenantId: testTenantId,
772
- organizationId: testOrgId,
773
- },
774
- ]
775
-
776
- mockEm.findOne.mockResolvedValue(mockInstance)
777
- mockEm.findAndCount.mockResolvedValue([mockEvents, 2])
778
-
779
- const request = new NextRequest(`http://localhost/api/workflows/instances/${testInstanceId}/events`)
780
- const response = await getInstanceEvents(request, { params: Promise.resolve({ id: testInstanceId }) })
781
- const data = await response.json()
782
-
783
- expect(response.status).toBe(200)
784
- expect(data.data).toHaveLength(2)
785
- expect(data.data[0].eventType).toBe('WORKFLOW_STARTED')
786
- expect(data.data[1].eventType).toBe('TRANSITION_EXECUTED')
787
- expect(data.pagination.total).toBe(2)
788
- expect(mockEm.findAndCount).toHaveBeenCalledWith(
789
- WorkflowEvent,
790
- expect.objectContaining({
791
- workflowInstanceId: testInstanceId,
792
- tenantId: testTenantId,
793
- organizationId: testOrgId,
794
- }),
795
- expect.objectContaining({
796
- orderBy: { occurredAt: 'DESC' },
797
- })
798
- )
799
- })
800
-
801
- test('should filter events by eventType', async () => {
802
- mockEm.findOne.mockResolvedValue(mockInstance)
803
- mockEm.findAndCount.mockResolvedValue([[], 0])
804
-
805
- const request = new NextRequest(`http://localhost/api/workflows/instances/${testInstanceId}/events?eventType=TRANSITION_EXECUTED`)
806
- await getInstanceEvents(request, { params: Promise.resolve({ id: testInstanceId }) })
807
-
808
- expect(mockEm.findAndCount).toHaveBeenCalledWith(
809
- WorkflowEvent,
810
- expect.objectContaining({
811
- eventType: 'TRANSITION_EXECUTED',
812
- }),
813
- expect.any(Object)
814
- )
815
- })
816
-
817
- test('should support pagination', async () => {
818
- mockEm.findOne.mockResolvedValue(mockInstance)
819
- mockEm.findAndCount.mockResolvedValue([[], 200])
820
-
821
- const request = new NextRequest(`http://localhost/api/workflows/instances/${testInstanceId}/events?limit=20&offset=40`)
822
- const response = await getInstanceEvents(request, { params: Promise.resolve({ id: testInstanceId }) })
823
- const data = await response.json()
824
-
825
- expect(data.pagination).toEqual({
826
- total: 200,
827
- limit: 20,
828
- offset: 40,
829
- hasMore: true,
830
- })
831
- })
832
-
833
- test('should return 404 when instance not found', async () => {
834
- mockEm.findOne.mockResolvedValue(null)
835
-
836
- const request = new NextRequest(`http://localhost/api/workflows/instances/${testInstanceId}/events`)
837
- const response = await getInstanceEvents(request, { params: Promise.resolve({ id: testInstanceId }) })
838
-
839
- expect(response.status).toBe(404)
840
- })
841
-
842
- test('should enforce tenant isolation', async () => {
843
- mockEm.findOne.mockResolvedValue(mockInstance)
844
- mockEm.findAndCount.mockResolvedValue([[], 0])
845
-
846
- const request = new NextRequest(`http://localhost/api/workflows/instances/${testInstanceId}/events`)
847
- await getInstanceEvents(request, { params: Promise.resolve({ id: testInstanceId }) })
848
-
849
- // Verify instance lookup uses tenant context
850
- expect(mockEm.findOne).toHaveBeenCalledWith(
851
- WorkflowInstance,
852
- expect.objectContaining({
853
- tenantId: testTenantId,
854
- organizationId: testOrgId,
855
- })
856
- )
857
-
858
- // Verify events query uses tenant context
859
- expect(mockEm.findAndCount).toHaveBeenCalledWith(
860
- WorkflowEvent,
861
- expect.objectContaining({
862
- tenantId: testTenantId,
863
- organizationId: testOrgId,
864
- }),
865
- expect.any(Object)
866
- )
867
- })
868
- })
869
- })