@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,1184 +0,0 @@
1
- jest.mock('@open-mercato/shared/lib/i18n/server', () => ({
2
- resolveTranslations: async () => ({
3
- translate: (_key: string, fallback?: string) => fallback ?? _key,
4
- }),
5
- }))
6
-
7
- import '@open-mercato/core/modules/customers/commands'
8
- import { commandRegistry, registerCommand } from '@open-mercato/shared/lib/commands/registry'
9
- import type { CommandHandler, CommandRuntimeContext } from '@open-mercato/shared/lib/commands'
10
- import type { DataEngine } from '@open-mercato/shared/lib/data/engine'
11
- import type { EntityManager } from '@mikro-orm/postgresql'
12
- import {
13
- CustomerEntity,
14
- CustomerPersonProfile,
15
- CustomerCompanyProfile,
16
- CustomerDeal,
17
- CustomerActivity,
18
- CustomerComment,
19
- CustomerAddress,
20
- CustomerTag,
21
- CustomerTagAssignment,
22
- CustomerTodoLink,
23
- } from '../../data/entities'
24
- // Todo type removed - example package no longer exists
25
- type Todo = {
26
- id: string
27
- title: string
28
- isDone: boolean
29
- tenantId: string | null
30
- organizationId: string | null
31
- }
32
-
33
- const TEST_TENANT_ID = '00000000-0000-0000-0000-000000000000'
34
- const TEST_ORG_ID = '123e4567-e89b-41d3-a456-426614174000'
35
- const TEST_ENTITY_ID = '123e4567-e89b-41d3-a456-426614174001'
36
-
37
- function createMockContext(deps: {
38
- em: Record<string, unknown>
39
- dataEngine: Pick<DataEngine, 'setCustomFields' | 'emitOrmEntityEvent'>
40
- tenantId?: string
41
- organizationId?: string
42
- }): CommandRuntimeContext {
43
- const engine = deps.dataEngine as unknown as Record<string, any>
44
- if (typeof engine.markOrmEntityChange !== 'function' || typeof engine.flushOrmEntityChanges !== 'function') {
45
- const queue: any[] = []
46
- engine.markOrmEntityChange = jest.fn((entry: any) => {
47
- if (!entry || !entry.entity) return
48
- queue.push(entry)
49
- })
50
- engine.flushOrmEntityChanges = jest.fn(async () => {
51
- while (queue.length > 0) {
52
- const next = queue.shift()
53
- await engine.emitOrmEntityEvent(next)
54
- }
55
- })
56
- }
57
- const container = {
58
- resolve: (token: string) => {
59
- switch (token) {
60
- case 'em':
61
- return deps.em
62
- case 'dataEngine':
63
- return engine
64
- default:
65
- throw new Error(`Unexpected dependency: ${token}`)
66
- }
67
- },
68
- }
69
-
70
- return {
71
- container: container as any,
72
- auth: {
73
- sub: 'actor-user',
74
- tenantId: deps.tenantId ?? 'tenant-1',
75
- orgId: deps.organizationId ?? 'org-1',
76
- } as any,
77
- selectedOrganizationId: deps.organizationId ?? 'org-1',
78
- organizationScope: null,
79
- organizationIds: null,
80
- request: undefined as any,
81
- }
82
- }
83
-
84
- describe('customers commands undo custom fields', () => {
85
- afterEach(() => {
86
- jest.clearAllMocks()
87
- })
88
-
89
- it('people.update undo restores custom fields', async () => {
90
- const handler = commandRegistry.get('customers.people.update') as CommandHandler
91
- expect(handler).toBeDefined()
92
-
93
- const existingEntity: CustomerEntity = {
94
- id: 'person-1',
95
- organizationId: 'org-1',
96
- tenantId: 'tenant-1',
97
- kind: 'person',
98
- displayName: 'After Name',
99
- description: null,
100
- ownerUserId: null,
101
- primaryEmail: null,
102
- primaryPhone: null,
103
- status: null,
104
- lifecycleStage: null,
105
- source: null,
106
- nextInteractionAt: null,
107
- nextInteractionName: null,
108
- nextInteractionRefId: null,
109
- isActive: true,
110
- createdAt: new Date(),
111
- updatedAt: new Date(),
112
- deletedAt: null,
113
- personProfile: undefined,
114
- companyProfile: undefined,
115
- addresses: [] as any,
116
- activities: [] as any,
117
- comments: [] as any,
118
- tagAssignments: [] as any,
119
- todoLinks: [] as any,
120
- dealPersonLinks: [] as any,
121
- dealCompanyLinks: [] as any,
122
- companyMembers: [] as any,
123
- }
124
- const existingProfile: CustomerPersonProfile = {
125
- id: 'profile-1',
126
- entity: existingEntity,
127
- organizationId: 'org-1',
128
- tenantId: 'tenant-1',
129
- firstName: 'After',
130
- lastName: 'User',
131
- preferredName: null,
132
- jobTitle: null,
133
- department: null,
134
- seniority: null,
135
- timezone: null,
136
- linkedInUrl: null,
137
- twitterUrl: null,
138
- company: null,
139
- createdAt: new Date(),
140
- updatedAt: new Date(),
141
- }
142
- existingEntity.personProfile = existingProfile
143
-
144
- const em = {
145
- fork: () => em,
146
- findOne: jest.fn(async (ctor, where: any) => {
147
- if (ctor === CustomerEntity) {
148
- if ('id' in where && where.id === existingEntity.id) return existingEntity
149
- return null
150
- }
151
- if (ctor === CustomerPersonProfile) {
152
- if (where.entity === existingEntity) return existingProfile
153
- }
154
- return null
155
- }),
156
- find: jest.fn(async () => []),
157
- nativeDelete: jest.fn(async () => {}),
158
- create: jest.fn((_ctor, data) => data),
159
- persist: jest.fn(() => {}),
160
- flush: jest.fn(async () => {}),
161
- getReference: jest.fn((_ctor, id) => ({ id })),
162
- remove: jest.fn(() => {}),
163
- }
164
-
165
- const setCustomFields = jest.fn(async () => {})
166
- const dataEngine: Pick<DataEngine, 'setCustomFields' | 'emitOrmEntityEvent'> = {
167
- setCustomFields,
168
- emitOrmEntityEvent: jest.fn(async () => {}),
169
- }
170
-
171
- const ctx = createMockContext({
172
- em,
173
- dataEngine,
174
- })
175
-
176
- const logEntry = {
177
- commandPayload: {
178
- undo: {
179
- before: {
180
- entity: {
181
- id: 'person-1',
182
- organizationId: 'org-1',
183
- tenantId: 'tenant-1',
184
- displayName: 'Before Name',
185
- description: 'before',
186
- ownerUserId: 'user-2',
187
- primaryEmail: 'before@example.com',
188
- primaryPhone: null,
189
- status: 'lead',
190
- lifecycleStage: null,
191
- source: 'import',
192
- nextInteractionAt: null,
193
- nextInteractionName: null,
194
- nextInteractionRefId: null,
195
- isActive: true,
196
- },
197
- profile: {
198
- id: 'profile-1',
199
- firstName: 'Before',
200
- lastName: 'User',
201
- preferredName: null,
202
- jobTitle: 'Developer',
203
- department: null,
204
- seniority: null,
205
- timezone: null,
206
- linkedInUrl: null,
207
- twitterUrl: null,
208
- companyEntityId: null,
209
- },
210
- tagIds: [],
211
- custom: { priority: 'high' },
212
- },
213
- after: {
214
- entity: {
215
- id: 'person-1',
216
- organizationId: 'org-1',
217
- tenantId: 'tenant-1',
218
- displayName: 'After Name',
219
- description: null,
220
- ownerUserId: null,
221
- primaryEmail: null,
222
- primaryPhone: null,
223
- status: null,
224
- lifecycleStage: null,
225
- source: null,
226
- nextInteractionAt: null,
227
- nextInteractionName: null,
228
- nextInteractionRefId: null,
229
- isActive: true,
230
- },
231
- profile: {
232
- id: 'profile-1',
233
- firstName: 'After',
234
- lastName: 'User',
235
- preferredName: null,
236
- jobTitle: null,
237
- department: null,
238
- seniority: null,
239
- timezone: null,
240
- linkedInUrl: null,
241
- twitterUrl: null,
242
- companyEntityId: null,
243
- },
244
- tagIds: [],
245
- custom: { priority: 'low', rating: 'gold' },
246
- },
247
- },
248
- },
249
- }
250
-
251
- await handler.undo!({ input: undefined, logEntry, ctx })
252
-
253
- expect(setCustomFields).toHaveBeenCalledWith(
254
- expect.objectContaining({
255
- recordId: 'profile-1',
256
- entityId: 'customers:customer_person_profile',
257
- organizationId: 'org-1',
258
- tenantId: 'tenant-1',
259
- values: { priority: 'high', rating: null },
260
- notify: true,
261
- })
262
- )
263
- expect(existingEntity.displayName).toBe('Before Name')
264
- })
265
-
266
- it('companies.update undo restores custom fields', async () => {
267
- const handler = commandRegistry.get('customers.companies.update') as CommandHandler
268
- expect(handler).toBeDefined()
269
-
270
- const existingEntity: CustomerEntity = {
271
- id: 'company-1',
272
- organizationId: 'org-1',
273
- tenantId: 'tenant-1',
274
- kind: 'company',
275
- displayName: 'After Co',
276
- description: null,
277
- ownerUserId: null,
278
- primaryEmail: null,
279
- primaryPhone: null,
280
- status: null,
281
- lifecycleStage: null,
282
- source: null,
283
- nextInteractionAt: null,
284
- nextInteractionName: null,
285
- nextInteractionRefId: null,
286
- isActive: true,
287
- createdAt: new Date(),
288
- updatedAt: new Date(),
289
- deletedAt: null,
290
- personProfile: undefined,
291
- companyProfile: undefined,
292
- addresses: [] as any,
293
- activities: [] as any,
294
- comments: [] as any,
295
- tagAssignments: [] as any,
296
- todoLinks: [] as any,
297
- dealPersonLinks: [] as any,
298
- dealCompanyLinks: [] as any,
299
- companyMembers: [] as any,
300
- }
301
- const existingProfile: CustomerCompanyProfile = {
302
- id: 'company-profile-1',
303
- entity: existingEntity,
304
- organizationId: 'org-1',
305
- tenantId: 'tenant-1',
306
- legalName: 'After Co LLC',
307
- brandName: 'After',
308
- domain: 'after.com',
309
- websiteUrl: 'https://after.com',
310
- industry: 'SaaS',
311
- sizeBucket: '100-500',
312
- annualRevenue: '2000000',
313
- createdAt: new Date(),
314
- updatedAt: new Date(),
315
- }
316
- existingEntity.companyProfile = existingProfile
317
-
318
- const em = {
319
- fork: () => em,
320
- findOne: jest.fn(async (ctor, where: any) => {
321
- if (ctor === CustomerEntity && where.id === existingEntity.id) return existingEntity
322
- if (ctor === CustomerCompanyProfile && where.entity === existingEntity) return existingProfile
323
- return null
324
- }),
325
- find: jest.fn(async () => []),
326
- nativeDelete: jest.fn(async () => {}),
327
- create: jest.fn((_ctor, data) => data),
328
- persist: jest.fn(() => {}),
329
- flush: jest.fn(async () => {}),
330
- getReference: jest.fn((_ctor, id) => ({ id })),
331
- }
332
-
333
- const setCustomFields = jest.fn(async () => {})
334
- const dataEngine: Pick<DataEngine, 'setCustomFields' | 'emitOrmEntityEvent'> = {
335
- setCustomFields,
336
- emitOrmEntityEvent: jest.fn(async () => {}),
337
- }
338
-
339
- const tenantId = 'tenant-1'
340
- const organizationId = 'org-1'
341
- const ctx = createMockContext({ em, dataEngine })
342
-
343
- const logEntry = {
344
- commandPayload: {
345
- undo: {
346
- before: {
347
- entity: {
348
- id: 'company-1',
349
- organizationId: 'org-1',
350
- tenantId: 'tenant-1',
351
- displayName: 'Before Co',
352
- description: 'legacy description',
353
- ownerUserId: 'user-5',
354
- primaryEmail: 'info@before.com',
355
- primaryPhone: null,
356
- status: 'customer',
357
- lifecycleStage: 'paying',
358
- source: 'import',
359
- nextInteractionAt: null,
360
- nextInteractionName: null,
361
- nextInteractionRefId: null,
362
- isActive: true,
363
- },
364
- profile: {
365
- id: 'company-profile-1',
366
- legalName: 'Before Co LTD',
367
- brandName: 'Before',
368
- domain: 'before.com',
369
- websiteUrl: 'https://before.com',
370
- industry: 'Retail',
371
- sizeBucket: '10-50',
372
- annualRevenue: '500000',
373
- },
374
- tagIds: [],
375
- custom: { tier: 'gold' },
376
- },
377
- after: {
378
- entity: {
379
- id: 'company-1',
380
- organizationId: 'org-1',
381
- tenantId: 'tenant-1',
382
- displayName: 'After Co',
383
- description: null,
384
- ownerUserId: null,
385
- primaryEmail: null,
386
- primaryPhone: null,
387
- status: null,
388
- lifecycleStage: null,
389
- source: null,
390
- nextInteractionAt: null,
391
- nextInteractionName: null,
392
- nextInteractionRefId: null,
393
- isActive: true,
394
- },
395
- profile: {
396
- id: 'company-profile-1',
397
- legalName: 'After Co LLC',
398
- brandName: 'After',
399
- domain: 'after.com',
400
- websiteUrl: 'https://after.com',
401
- industry: 'SaaS',
402
- sizeBucket: '100-500',
403
- annualRevenue: '2000000',
404
- },
405
- tagIds: [],
406
- custom: { tier: 'silver', account_manager: 'user-9' },
407
- },
408
- },
409
- },
410
- }
411
-
412
- await handler.undo!({ input: undefined, logEntry, ctx })
413
-
414
- expect(setCustomFields).toHaveBeenCalledWith(
415
- expect.objectContaining({
416
- recordId: 'company-profile-1',
417
- entityId: 'customers:customer_company_profile',
418
- organizationId: 'org-1',
419
- tenantId: 'tenant-1',
420
- values: { tier: 'gold', account_manager: null },
421
- notify: false,
422
- })
423
- )
424
- expect(existingEntity.displayName).toBe('Before Co')
425
- })
426
-
427
- it('deals.update undo restores custom fields', async () => {
428
- const handler = commandRegistry.get('customers.deals.update') as CommandHandler
429
- expect(handler).toBeDefined()
430
- const tenantId = TEST_TENANT_ID
431
- const organizationId = TEST_ORG_ID
432
-
433
- const personEntity: CustomerEntity = {
434
- id: 'person-1',
435
- organizationId,
436
- tenantId,
437
- kind: 'person',
438
- displayName: 'Person',
439
- description: null,
440
- ownerUserId: null,
441
- primaryEmail: null,
442
- primaryPhone: null,
443
- status: null,
444
- lifecycleStage: null,
445
- source: null,
446
- nextInteractionAt: null,
447
- nextInteractionName: null,
448
- nextInteractionRefId: null,
449
- isActive: true,
450
- createdAt: new Date(),
451
- updatedAt: new Date(),
452
- deletedAt: null,
453
- personProfile: undefined,
454
- companyProfile: undefined,
455
- addresses: [] as any,
456
- activities: [] as any,
457
- comments: [] as any,
458
- tagAssignments: [] as any,
459
- todoLinks: [] as any,
460
- dealPersonLinks: [] as any,
461
- dealCompanyLinks: [] as any,
462
- companyMembers: [] as any,
463
- }
464
-
465
- const companyEntity: CustomerEntity = {
466
- ...personEntity,
467
- id: 'company-1',
468
- kind: 'company',
469
- displayName: 'Company',
470
- }
471
-
472
- const existingDeal: CustomerDeal = {
473
- id: 'deal-1',
474
- organizationId,
475
- tenantId,
476
- title: 'After Deal',
477
- description: null,
478
- status: 'won',
479
- pipelineStage: 'closed',
480
- valueAmount: '5000',
481
- valueCurrency: 'USD',
482
- probability: 90,
483
- expectedCloseAt: new Date('2024-01-01'),
484
- ownerUserId: 'user-10',
485
- source: 'referral',
486
- createdAt: new Date(),
487
- updatedAt: new Date(),
488
- deletedAt: null,
489
- people: [] as any,
490
- companies: [] as any,
491
- activities: [] as any,
492
- comments: [] as any,
493
- }
494
-
495
- const em = {
496
- fork: () => em,
497
- findOne: jest.fn(async (ctor, where: any) => {
498
- if (ctor === CustomerDeal && where.id === existingDeal.id) return existingDeal
499
- if (ctor === CustomerEntity) {
500
- if (where.id === personEntity.id) return personEntity
501
- if (where.id === companyEntity.id) return companyEntity
502
- }
503
- return null
504
- }),
505
- find: jest.fn(async () => []),
506
- nativeDelete: jest.fn(async () => {}),
507
- create: jest.fn((_ctor, data) => data),
508
- persist: jest.fn(() => {}),
509
- flush: jest.fn(async () => {}),
510
- }
511
-
512
- const setCustomFields = jest.fn(async () => {})
513
- const dataEngine: Pick<DataEngine, 'setCustomFields' | 'emitOrmEntityEvent'> = {
514
- setCustomFields,
515
- emitOrmEntityEvent: jest.fn(async () => {}),
516
- }
517
-
518
- const ctx = createMockContext({ em, dataEngine, tenantId, organizationId })
519
- if (!ctx.auth) {
520
- throw new Error('Expected auth context in mock command runtime')
521
- }
522
- ctx.auth.tenantId = tenantId
523
- ctx.auth.orgId = organizationId
524
- ctx.selectedOrganizationId = organizationId
525
-
526
- const logEntry = {
527
- commandPayload: {
528
- undo: {
529
- before: {
530
- deal: {
531
- id: 'deal-1',
532
- organizationId: 'org-1',
533
- tenantId: 'tenant-1',
534
- title: 'Before Deal',
535
- description: 'Initial deal',
536
- status: 'open',
537
- pipelineStage: 'prospecting',
538
- valueAmount: '1000',
539
- valueCurrency: 'USD',
540
- probability: 20,
541
- expectedCloseAt: null,
542
- ownerUserId: 'user-8',
543
- source: 'event',
544
- },
545
- people: ['person-1'],
546
- companies: ['company-1'],
547
- custom: { priority: 'high' },
548
- },
549
- after: {
550
- deal: {
551
- id: 'deal-1',
552
- organizationId: 'org-1',
553
- tenantId: 'tenant-1',
554
- title: 'After Deal',
555
- description: null,
556
- status: 'won',
557
- pipelineStage: 'closed',
558
- valueAmount: '5000',
559
- valueCurrency: 'USD',
560
- probability: 90,
561
- expectedCloseAt: new Date('2024-01-01'),
562
- ownerUserId: 'user-10',
563
- source: 'referral',
564
- },
565
- people: ['person-1', 'person-2'],
566
- companies: ['company-1'],
567
- custom: { priority: 'low', segment: 'enterprise' },
568
- },
569
- },
570
- },
571
- }
572
-
573
- await handler.undo!({ input: undefined, logEntry, ctx })
574
-
575
- expect(setCustomFields).toHaveBeenCalledWith(
576
- expect.objectContaining({
577
- recordId: 'deal-1',
578
- entityId: 'customers:customer_deal',
579
- organizationId,
580
- tenantId,
581
- values: { priority: 'high', segment: null },
582
- notify: false,
583
- })
584
- )
585
- expect(existingDeal.title).toBe('Before Deal')
586
- })
587
-
588
- it('activities.update undo restores custom fields', async () => {
589
- const handler = commandRegistry.get('customers.activities.update') as CommandHandler
590
- expect(handler).toBeDefined()
591
-
592
- const entity: CustomerEntity = {
593
- id: 'person-1',
594
- organizationId: 'org-1',
595
- tenantId: 'tenant-1',
596
- kind: 'person',
597
- displayName: 'Person',
598
- description: null,
599
- ownerUserId: null,
600
- primaryEmail: null,
601
- primaryPhone: null,
602
- status: null,
603
- lifecycleStage: null,
604
- source: null,
605
- nextInteractionAt: null,
606
- nextInteractionName: null,
607
- nextInteractionRefId: null,
608
- isActive: true,
609
- createdAt: new Date(),
610
- updatedAt: new Date(),
611
- deletedAt: null,
612
- personProfile: undefined,
613
- companyProfile: undefined,
614
- addresses: [] as any,
615
- activities: [] as any,
616
- comments: [] as any,
617
- tagAssignments: [] as any,
618
- todoLinks: [] as any,
619
- dealPersonLinks: [] as any,
620
- dealCompanyLinks: [] as any,
621
- companyMembers: [] as any,
622
- }
623
-
624
- const deal: CustomerDeal = {
625
- id: 'deal-1',
626
- organizationId: 'org-1',
627
- tenantId: 'tenant-1',
628
- title: 'Deal',
629
- description: null,
630
- status: 'open',
631
- pipelineStage: null,
632
- valueAmount: null,
633
- valueCurrency: null,
634
- probability: null,
635
- expectedCloseAt: null,
636
- ownerUserId: null,
637
- source: null,
638
- createdAt: new Date(),
639
- updatedAt: new Date(),
640
- deletedAt: null,
641
- people: [] as any,
642
- companies: [] as any,
643
- activities: [] as any,
644
- comments: [] as any,
645
- }
646
-
647
- const em = {
648
- fork: () => em,
649
- findOne: jest.fn(async (ctor, where: any) => {
650
- if (ctor === CustomerEntity && where.id === entity.id) return entity
651
- if (ctor === CustomerDeal && where.id === deal.id) return deal
652
- if (ctor === CustomerActivity && where.id === 'activity-1') {
653
- return {
654
- id: 'activity-1',
655
- organizationId: 'org-1',
656
- tenantId: 'tenant-1',
657
- entity,
658
- deal,
659
- activityType: 'call',
660
- subject: 'After',
661
- body: 'After body',
662
- occurredAt: new Date('2024-02-01'),
663
- authorUserId: 'user-2',
664
- } as any
665
- }
666
- return null
667
- }),
668
- create: jest.fn((_ctor, data) => data),
669
- persist: jest.fn(() => {}),
670
- flush: jest.fn(async () => {}),
671
- remove: jest.fn(() => {}),
672
- }
673
-
674
- const setCustomFields = jest.fn(async () => {})
675
- const dataEngine: Pick<DataEngine, 'setCustomFields' | 'emitOrmEntityEvent'> = {
676
- setCustomFields,
677
- emitOrmEntityEvent: jest.fn(async () => {}),
678
- }
679
-
680
- const ctx = createMockContext({ em, dataEngine })
681
-
682
- const logEntry = {
683
- commandPayload: {
684
- undo: {
685
- before: {
686
- activity: {
687
- id: 'activity-1',
688
- organizationId: 'org-1',
689
- tenantId: 'tenant-1',
690
- entityId: 'person-1',
691
- dealId: 'deal-1',
692
- activityType: 'meeting',
693
- subject: 'Before subject',
694
- body: 'Before body',
695
- occurredAt: new Date('2024-01-01'),
696
- authorUserId: 'user-1',
697
- },
698
- custom: { notes: 'important' },
699
- },
700
- after: {
701
- activity: {
702
- id: 'activity-1',
703
- organizationId: 'org-1',
704
- tenantId: 'tenant-1',
705
- entityId: 'person-1',
706
- dealId: 'deal-1',
707
- activityType: 'call',
708
- subject: 'After',
709
- body: 'After body',
710
- occurredAt: new Date('2024-02-01'),
711
- authorUserId: 'user-2',
712
- },
713
- custom: { notes: 'follow up', outcome: 'positive' },
714
- },
715
- },
716
- },
717
- }
718
-
719
- await handler.undo!({ input: undefined, logEntry, ctx })
720
-
721
- expect(setCustomFields).toHaveBeenCalledWith(
722
- expect.objectContaining({
723
- recordId: 'activity-1',
724
- entityId: 'customers:customer_activity',
725
- organizationId: 'org-1',
726
- tenantId: 'tenant-1',
727
- values: { notes: 'important', outcome: null },
728
- notify: false,
729
- })
730
- )
731
- })
732
-
733
- it('comments.delete undo recreates comment', async () => {
734
- const handler = commandRegistry.get('customers.comments.delete') as CommandHandler
735
- expect(handler).toBeDefined()
736
-
737
- const entity: CustomerEntity = {
738
- id: 'person-1',
739
- organizationId: 'org-1',
740
- tenantId: 'tenant-1',
741
- kind: 'person',
742
- displayName: 'Person',
743
- description: null,
744
- ownerUserId: null,
745
- primaryEmail: null,
746
- primaryPhone: null,
747
- status: null,
748
- lifecycleStage: null,
749
- source: null,
750
- nextInteractionAt: null,
751
- nextInteractionName: null,
752
- nextInteractionRefId: null,
753
- isActive: true,
754
- createdAt: new Date(),
755
- updatedAt: new Date(),
756
- deletedAt: null,
757
- personProfile: undefined,
758
- companyProfile: undefined,
759
- addresses: [] as any,
760
- activities: [] as any,
761
- comments: [] as any,
762
- tagAssignments: [] as any,
763
- todoLinks: [] as any,
764
- dealPersonLinks: [] as any,
765
- dealCompanyLinks: [] as any,
766
- companyMembers: [] as any,
767
- }
768
-
769
- const em = {
770
- fork: () => em,
771
- findOne: jest.fn(async (ctor, where: any) => {
772
- if (ctor === CustomerEntity && where.id === entity.id) return entity
773
- if (ctor === CustomerComment && where.id === 'comment-1') return null
774
- return null
775
- }),
776
- create: jest.fn((_ctor, data) => data),
777
- persist: jest.fn(() => {}),
778
- flush: jest.fn(async () => {}),
779
- }
780
-
781
- const dataEngine: Pick<DataEngine, 'setCustomFields' | 'emitOrmEntityEvent'> = {
782
- setCustomFields: jest.fn(async () => {}),
783
- emitOrmEntityEvent: jest.fn(async () => {}),
784
- }
785
-
786
- const ctx = createMockContext({ em, dataEngine })
787
-
788
- const logEntry = {
789
- commandPayload: {
790
- undo: {
791
- before: {
792
- id: 'comment-1',
793
- organizationId: 'org-1',
794
- tenantId: 'tenant-1',
795
- entityId: 'person-1',
796
- dealId: null,
797
- body: 'Note body',
798
- authorUserId: 'user-1',
799
- },
800
- },
801
- },
802
- }
803
-
804
- await handler.undo!({ input: undefined, logEntry, ctx })
805
-
806
- expect(em.create).toHaveBeenCalledWith(
807
- CustomerComment,
808
- expect.objectContaining({ id: 'comment-1', body: 'Note body' })
809
- )
810
- })
811
-
812
- it('addresses.delete undo recreates address and clears other primaries', async () => {
813
- const handler = commandRegistry.get('customers.addresses.delete') as CommandHandler
814
- expect(handler).toBeDefined()
815
-
816
- const entity: CustomerEntity = {
817
- id: 'person-1',
818
- organizationId: 'org-1',
819
- tenantId: 'tenant-1',
820
- kind: 'person',
821
- displayName: 'Person',
822
- description: null,
823
- ownerUserId: null,
824
- primaryEmail: null,
825
- primaryPhone: null,
826
- status: null,
827
- lifecycleStage: null,
828
- source: null,
829
- nextInteractionAt: null,
830
- nextInteractionName: null,
831
- nextInteractionRefId: null,
832
- isActive: true,
833
- createdAt: new Date(),
834
- updatedAt: new Date(),
835
- deletedAt: null,
836
- personProfile: undefined,
837
- companyProfile: undefined,
838
- addresses: [] as any,
839
- activities: [] as any,
840
- comments: [] as any,
841
- tagAssignments: [] as any,
842
- todoLinks: [] as any,
843
- dealPersonLinks: [] as any,
844
- dealCompanyLinks: [] as any,
845
- companyMembers: [] as any,
846
- }
847
-
848
- const nativeUpdate = jest.fn(async () => {})
849
- const em = {
850
- fork: () => em,
851
- findOne: jest.fn(async (ctor, where: any) => {
852
- if (ctor === CustomerEntity && where.id === entity.id) return entity
853
- if (ctor === CustomerAddress && where.id === 'address-1') return null
854
- return null
855
- }),
856
- create: jest.fn((_ctor, data) => data),
857
- persist: jest.fn(() => {}),
858
- flush: jest.fn(async () => {}),
859
- nativeUpdate,
860
- }
861
-
862
- const dataEngine: Pick<DataEngine, 'setCustomFields' | 'emitOrmEntityEvent'> = {
863
- setCustomFields: jest.fn(async () => {}),
864
- emitOrmEntityEvent: jest.fn(async () => {}),
865
- }
866
-
867
- const ctx = createMockContext({ em, dataEngine })
868
-
869
- const logEntry = {
870
- commandPayload: {
871
- undo: {
872
- before: {
873
- id: 'address-1',
874
- organizationId: 'org-1',
875
- tenantId: 'tenant-1',
876
- entityId: 'person-1',
877
- name: 'HQ',
878
- purpose: 'billing',
879
- addressLine1: 'Street 1',
880
- addressLine2: null,
881
- city: 'City',
882
- region: null,
883
- postalCode: '00-001',
884
- country: 'PL',
885
- latitude: null,
886
- longitude: null,
887
- isPrimary: true,
888
- },
889
- },
890
- },
891
- }
892
-
893
- await handler.undo!({ input: undefined, logEntry, ctx })
894
-
895
- expect(em.create).toHaveBeenCalledWith(
896
- CustomerAddress,
897
- expect.objectContaining({ id: 'address-1', name: 'HQ', isPrimary: true })
898
- )
899
- expect(nativeUpdate).toHaveBeenCalled()
900
- })
901
-
902
- it('tags.unassign undo re-creates tag assignment', async () => {
903
- const handler = commandRegistry.get('customers.tags.unassign') as CommandHandler
904
- expect(handler).toBeDefined()
905
-
906
- const tag: CustomerTag = {
907
- id: 'tag-1',
908
- organizationId: 'org-1',
909
- tenantId: 'tenant-1',
910
- slug: 'vip',
911
- label: 'VIP',
912
- color: null,
913
- description: null,
914
- createdAt: new Date(),
915
- updatedAt: new Date(),
916
- assignments: [] as any,
917
- }
918
-
919
- const entity: CustomerEntity = {
920
- id: 'person-1',
921
- organizationId: 'org-1',
922
- tenantId: 'tenant-1',
923
- kind: 'person',
924
- displayName: 'Person',
925
- description: null,
926
- ownerUserId: null,
927
- primaryEmail: null,
928
- primaryPhone: null,
929
- status: null,
930
- lifecycleStage: null,
931
- source: null,
932
- nextInteractionAt: null,
933
- nextInteractionName: null,
934
- nextInteractionRefId: null,
935
- isActive: true,
936
- createdAt: new Date(),
937
- updatedAt: new Date(),
938
- deletedAt: null,
939
- personProfile: undefined,
940
- companyProfile: undefined,
941
- addresses: [] as any,
942
- activities: [] as any,
943
- comments: [] as any,
944
- tagAssignments: [] as any,
945
- todoLinks: [] as any,
946
- dealPersonLinks: [] as any,
947
- dealCompanyLinks: [] as any,
948
- companyMembers: [] as any,
949
- }
950
-
951
- const findOne = jest.fn(async (ctor, where: any) => {
952
- if (ctor === CustomerTag && where.id === tag.id) return tag
953
- if (ctor === CustomerEntity && where.id === entity.id) return entity
954
- if (ctor === CustomerTagAssignment) return null
955
- return null
956
- })
957
-
958
- const em = {
959
- fork: () => em,
960
- findOne,
961
- create: jest.fn((_ctor, data) => data),
962
- persist: jest.fn(() => {}),
963
- flush: jest.fn(async () => {}),
964
- }
965
-
966
- const dataEngine: Pick<DataEngine, 'setCustomFields' | 'emitOrmEntityEvent'> = {
967
- setCustomFields: jest.fn(async () => {}),
968
- emitOrmEntityEvent: jest.fn(async () => {}),
969
- }
970
-
971
- const ctx = createMockContext({ em, dataEngine })
972
-
973
- const logEntry = {
974
- commandPayload: {
975
- undo: {
976
- before: {
977
- tagId: 'tag-1',
978
- entityId: 'person-1',
979
- organizationId: 'org-1',
980
- tenantId: 'tenant-1',
981
- },
982
- },
983
- },
984
- }
985
-
986
- await handler.undo!({ input: undefined, logEntry, ctx })
987
-
988
- expect(em.create).toHaveBeenCalledWith(
989
- CustomerTagAssignment,
990
- expect.objectContaining({
991
- tag,
992
- entity,
993
- })
994
- )
995
- })
996
-
997
- it('todos.unlink undo re-creates todo link', async () => {
998
- const handler = commandRegistry.get('customers.todos.unlink') as CommandHandler
999
- expect(handler).toBeDefined()
1000
-
1001
- const entity: CustomerEntity = {
1002
- id: 'person-1',
1003
- organizationId: 'org-1',
1004
- tenantId: 'tenant-1',
1005
- kind: 'person',
1006
- displayName: 'Person',
1007
- description: null,
1008
- ownerUserId: null,
1009
- primaryEmail: null,
1010
- primaryPhone: null,
1011
- status: null,
1012
- lifecycleStage: null,
1013
- source: null,
1014
- nextInteractionAt: null,
1015
- nextInteractionName: null,
1016
- nextInteractionRefId: null,
1017
- isActive: true,
1018
- createdAt: new Date(),
1019
- updatedAt: new Date(),
1020
- deletedAt: null,
1021
- personProfile: undefined,
1022
- companyProfile: undefined,
1023
- addresses: [] as any,
1024
- activities: [] as any,
1025
- comments: [] as any,
1026
- tagAssignments: [] as any,
1027
- todoLinks: [] as any,
1028
- dealPersonLinks: [] as any,
1029
- dealCompanyLinks: [] as any,
1030
- companyMembers: [] as any,
1031
- }
1032
-
1033
- const findOne = jest.fn(async (ctor, where: any) => {
1034
- if (ctor === CustomerEntity && where.id === entity.id) return entity
1035
- if (ctor === CustomerTodoLink && where.id === 'link-1') return null
1036
- return null
1037
- })
1038
-
1039
- const em = {
1040
- fork: () => em,
1041
- findOne,
1042
- create: jest.fn((_ctor, data) => data),
1043
- persist: jest.fn(() => {}),
1044
- flush: jest.fn(async () => {}),
1045
- nativeDelete: jest.fn(async () => {}),
1046
- }
1047
-
1048
- const dataEngine: Pick<DataEngine, 'setCustomFields' | 'emitOrmEntityEvent'> = {
1049
- setCustomFields: jest.fn(async () => {}),
1050
- emitOrmEntityEvent: jest.fn(async () => {}),
1051
- }
1052
-
1053
- const ctx = createMockContext({ em, dataEngine })
1054
-
1055
- const logEntry = {
1056
- commandPayload: {
1057
- undo: {
1058
- link: {
1059
- id: 'link-1',
1060
- entityId: 'person-1',
1061
- organizationId: 'org-1',
1062
- tenantId: 'tenant-1',
1063
- todoId: 'todo-1',
1064
- todoSource: 'example:todo',
1065
- createdByUserId: 'user-1',
1066
- },
1067
- },
1068
- },
1069
- }
1070
-
1071
- await handler.undo!({ input: undefined, logEntry, ctx })
1072
-
1073
- expect(em.create).toHaveBeenCalledWith(
1074
- CustomerTodoLink,
1075
- expect.objectContaining({ id: 'link-1', todoId: 'todo-1' })
1076
- )
1077
- })
1078
-
1079
- it('todos.create undo removes link and calls example undo', async () => {
1080
- // example package no longer exists, so we just register a mock handler
1081
- const originalHandler = commandRegistry.get('example.todos.create') as CommandHandler | null
1082
- const tenantId = TEST_TENANT_ID
1083
- const organizationId = TEST_ORG_ID
1084
- const entityId = TEST_ENTITY_ID
1085
-
1086
- const fakeTodo = {
1087
- id: 'todo-created',
1088
- title: 'Follow up',
1089
- isDone: false,
1090
- tenantId,
1091
- organizationId,
1092
- } as unknown as Todo
1093
-
1094
- const executeMock = jest.fn(async (payload: Record<string, unknown>) => fakeTodo)
1095
- const captureAfterMock = jest.fn(async () => ({
1096
- id: 'todo-created',
1097
- title: 'Follow up',
1098
- is_done: false,
1099
- tenantId,
1100
- organizationId,
1101
- }))
1102
- const undoMock = jest.fn(async () => {})
1103
-
1104
- commandRegistry.unregister('example.todos.create')
1105
- registerCommand({
1106
- id: 'example.todos.create',
1107
- execute: executeMock,
1108
- captureAfter: captureAfterMock,
1109
- undo: undoMock,
1110
- } as CommandHandler)
1111
-
1112
- const em = {
1113
- fork: () => em,
1114
- findOne: jest.fn(async (ctor, where: any) => {
1115
- if (ctor === CustomerEntity && where.id === entityId) {
1116
- return {
1117
- id: entityId,
1118
- organizationId,
1119
- tenantId,
1120
- kind: 'person',
1121
- } as CustomerEntity
1122
- }
1123
- if (ctor === CustomerTodoLink && where.id === 'link-1') return null
1124
- return null
1125
- }),
1126
- create: jest.fn((_ctor, data) => ({ id: data.id ?? 'link-1', ...data })),
1127
- persist: jest.fn(() => {}),
1128
- flush: jest.fn(async () => {}),
1129
- nativeDelete: jest.fn(async () => {}),
1130
- }
1131
-
1132
- const dataEngine: Pick<DataEngine, 'setCustomFields' | 'emitOrmEntityEvent'> = {
1133
- setCustomFields: jest.fn(async () => {}),
1134
- emitOrmEntityEvent: jest.fn(async () => {}),
1135
- }
1136
-
1137
- const ctx = createMockContext({ em, dataEngine, tenantId, organizationId })
1138
- if (!ctx.auth) {
1139
- throw new Error('Expected auth context in mock command runtime')
1140
- }
1141
- ctx.auth = { ...ctx.auth, tenantId, orgId: organizationId } as any
1142
- ctx.selectedOrganizationId = organizationId
1143
-
1144
- const handler = commandRegistry.get('customers.todos.create') as CommandHandler
1145
- expect(handler).toBeDefined()
1146
-
1147
- const input = {
1148
- tenantId,
1149
- organizationId,
1150
- entityId,
1151
- title: 'Follow up',
1152
- todoCustom: { priority: 'high' },
1153
- }
1154
-
1155
- expect(ctx.auth!.tenantId).toBe(tenantId)
1156
- expect(ctx.auth!.orgId).toBe(organizationId)
1157
-
1158
- const result = await handler.execute(input, ctx) as { linkId: string }
1159
- expect(executeMock).toHaveBeenCalled()
1160
- const firstExecuteCall = executeMock.mock.calls[0] as [Record<string, unknown>]
1161
- expect(firstExecuteCall[0]).toMatchObject({
1162
- title: 'Follow up',
1163
- is_done: false,
1164
- custom: { priority: 'high' },
1165
- })
1166
- expect(em.persist).toHaveBeenCalled()
1167
-
1168
- const log = await handler.buildLog?.({ input, result, ctx, snapshots: {} as any })
1169
- expect(log).toBeTruthy()
1170
-
1171
- await handler.undo?.({
1172
- input: undefined,
1173
- ctx,
1174
- logEntry: {
1175
- commandPayload: log?.payload ?? null,
1176
- } as any,
1177
- })
1178
-
1179
- expect(undoMock).toHaveBeenCalled()
1180
-
1181
- commandRegistry.unregister('example.todos.create')
1182
- if (originalHandler) registerCommand(originalHandler)
1183
- })
1184
- })