backend-manager 5.9.5 → 5.9.6

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 (244) hide show
  1. package/package.json +8 -1
  2. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/metadata.json +14 -0
  3. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/newsletter.html +486 -0
  4. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/newsletter.md +41 -0
  5. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/newsletter.mjml +97 -0
  6. package/{test/email/fixtures/clean.json → src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/structure.json} +16 -4
  7. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/summary.md +1 -0
  8. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/metadata.json +14 -0
  9. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/newsletter.html +486 -0
  10. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/newsletter.md +41 -0
  11. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/newsletter.mjml +97 -0
  12. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/structure.json +42 -0
  13. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/summary.md +1 -0
  14. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/metadata.json +14 -0
  15. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/newsletter.html +486 -0
  16. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/newsletter.md +41 -0
  17. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/newsletter.mjml +97 -0
  18. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/structure.json +42 -0
  19. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/summary.md +1 -0
  20. package/src/test/fixtures/firebase-project/.temp/test-mode.json +6 -0
  21. package/src/test/fixtures/firebase-project/database-debug.log +12 -0
  22. package/src/test/fixtures/firebase-project/firestore-debug.log +136 -0
  23. package/src/test/fixtures/firebase-project/pubsub-debug.log +17 -0
  24. package/.codeclimate.yml +0 -32
  25. package/.nvmrc +0 -1
  26. package/CHANGELOG.md +0 -1440
  27. package/PROGRESS.md +0 -93
  28. package/TODO-2.md +0 -121
  29. package/TODO-CHARGEBLAST.md +0 -32
  30. package/TODO-WEBHOOK-KEY-LEGACY-REMOVAL.md +0 -15
  31. package/TODO-WEBHOOK-KEY-UPGRADE.md +0 -138
  32. package/TODO-email-auth.md +0 -14
  33. package/TODO.md +0 -187
  34. package/plans/mcp2.md +0 -247
  35. package/plans/suspended-subscription-dead-zone.md +0 -97
  36. package/scripts/test-helper-providers.js +0 -162
  37. package/scripts/update-disposable-domains.js +0 -44
  38. package/templates/_.env +0 -42
  39. package/templates/_.gitignore +0 -60
  40. package/templates/backend-manager-config.json +0 -249
  41. package/templates/database.rules.json +0 -83
  42. package/templates/firebase.json +0 -66
  43. package/templates/firestore.indexes.json +0 -4
  44. package/templates/firestore.rules +0 -112
  45. package/templates/public/404.html +0 -26
  46. package/templates/public/index.html +0 -24
  47. package/templates/remoteconfig.template.json +0 -1
  48. package/templates/storage-lifecycle-config-1-day.json +0 -9
  49. package/templates/storage-lifecycle-config-30-days.json +0 -9
  50. package/templates/storage.rules +0 -8
  51. package/test/_init/accounts-validation.js +0 -58
  52. package/test/_legacy/ai/index.js +0 -231
  53. package/test/_legacy/ai/test.jpg +0 -0
  54. package/test/_legacy/ai/test.pdf +0 -0
  55. package/test/_legacy/index.js +0 -31
  56. package/test/_legacy/payment-resolver/chargebee/orders/refunded.json +0 -0
  57. package/test/_legacy/payment-resolver/chargebee/orders/unpaid.json +0 -98
  58. package/test/_legacy/payment-resolver/chargebee/subscriptions/active.json +0 -578
  59. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-in-trial.json +0 -38
  60. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-skipped-to-active.json +0 -135
  61. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-active-to-cancelled.json +0 -42
  62. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-active.json +0 -44
  63. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-cancelled.json +0 -39
  64. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-refund.json +0 -143
  65. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-suspended.json +0 -48
  66. package/test/_legacy/payment-resolver/coinbase/orders/regular.json +0 -204
  67. package/test/_legacy/payment-resolver/coinbase/subscriptions/cancelled.json +0 -204
  68. package/test/_legacy/payment-resolver/coinbase/subscriptions/paid-2.json +0 -125
  69. package/test/_legacy/payment-resolver/index.js +0 -1558
  70. package/test/_legacy/payment-resolver/paypal/orders/refunded.json +0 -0
  71. package/test/_legacy/payment-resolver/paypal/orders/regular.json +0 -120
  72. package/test/_legacy/payment-resolver/paypal/subscriptions/active-refund-previous-stmnt.json +0 -323
  73. package/test/_legacy/payment-resolver/paypal/subscriptions/active.json +0 -192
  74. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-in-trial.json +0 -125
  75. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-not-complete.json +0 -76
  76. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-overdue-2.json +0 -114
  77. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-overdue.json +0 -114
  78. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-active-to-cancelled.json +0 -111
  79. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-active.json +0 -132
  80. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-cancelled.json +0 -107
  81. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-expired.json +0 -91
  82. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-refund.json +0 -147
  83. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-suspended.json +0 -120
  84. package/test/_legacy/payment-resolver/stripe/orders/refunded.json +0 -0
  85. package/test/_legacy/payment-resolver/stripe/orders/regular.json +0 -91
  86. package/test/_legacy/payment-resolver/stripe/subscriptions/active.json +0 -421
  87. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-in-trial.json +0 -349
  88. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-active-failed-authorization.json +0 -430
  89. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-active.json +0 -319
  90. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-cancelled.json +0 -319
  91. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-refund.json +0 -414
  92. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-suspended.json +0 -319
  93. package/test/_legacy/payment-resolver/stripe/subscriptions/unsure.json +0 -339
  94. package/test/_legacy/test-new +0 -1178
  95. package/test/_legacy/test.md +0 -89
  96. package/test/_legacy/usage.js +0 -175
  97. package/test/_legacy/user.js +0 -31
  98. package/test/ai/tools-live.js +0 -170
  99. package/test/boot/emulator-boots.js +0 -37
  100. package/test/content/blog-generate.js +0 -160
  101. package/test/email/campaign-send.js +0 -45
  102. package/test/email/consent-lifecycle.js +0 -257
  103. package/test/email/feedback-and-plain-send.js +0 -52
  104. package/test/email/fixtures/editorial.json +0 -30
  105. package/test/email/fixtures/field-report.json +0 -53
  106. package/test/email/marketing-lifecycle.js +0 -132
  107. package/test/email/newsletter-generate.js +0 -819
  108. package/test/email/newsletter-templates.js +0 -491
  109. package/test/email/templates.js +0 -207
  110. package/test/email/transactional-send.js +0 -34
  111. package/test/email/transactional.js +0 -560
  112. package/test/email/validation.js +0 -710
  113. package/test/events/auth-delete-race.js +0 -201
  114. package/test/events/payments/journey-payments-cancel-endpoint.js +0 -100
  115. package/test/events/payments/journey-payments-cancel.js +0 -182
  116. package/test/events/payments/journey-payments-discount.js +0 -89
  117. package/test/events/payments/journey-payments-failure.js +0 -146
  118. package/test/events/payments/journey-payments-legacy-product.js +0 -149
  119. package/test/events/payments/journey-payments-one-time-failure.js +0 -111
  120. package/test/events/payments/journey-payments-one-time.js +0 -136
  121. package/test/events/payments/journey-payments-plan-change.js +0 -144
  122. package/test/events/payments/journey-payments-refund-webhook.js +0 -180
  123. package/test/events/payments/journey-payments-suspend.js +0 -181
  124. package/test/events/payments/journey-payments-trial-cancel.js +0 -130
  125. package/test/events/payments/journey-payments-trial.js +0 -171
  126. package/test/events/payments/journey-payments-uid-resolution.js +0 -132
  127. package/test/events/payments/journey-payments-upgrade.js +0 -135
  128. package/test/fixtures/chargebee/invoice-one-time.json +0 -27
  129. package/test/fixtures/chargebee/subscription-active.json +0 -44
  130. package/test/fixtures/chargebee/subscription-cancelled.json +0 -42
  131. package/test/fixtures/chargebee/subscription-in-trial.json +0 -41
  132. package/test/fixtures/chargebee/subscription-legacy-plan.json +0 -41
  133. package/test/fixtures/chargebee/subscription-non-renewing.json +0 -41
  134. package/test/fixtures/chargebee/subscription-paused.json +0 -42
  135. package/test/fixtures/chargebee/webhook-payment-failed.json +0 -51
  136. package/test/fixtures/chargebee/webhook-subscription-created.json +0 -47
  137. package/test/fixtures/paypal/order-approved.json +0 -62
  138. package/test/fixtures/paypal/order-completed.json +0 -110
  139. package/test/fixtures/paypal/subscription-active.json +0 -76
  140. package/test/fixtures/paypal/subscription-cancelled.json +0 -50
  141. package/test/fixtures/paypal/subscription-suspended.json +0 -65
  142. package/test/fixtures/stripe/checkout-session-completed.json +0 -130
  143. package/test/fixtures/stripe/invoice-payment-failed.json +0 -148
  144. package/test/fixtures/stripe/invoice-subscription-payment-failed.json +0 -28
  145. package/test/fixtures/stripe/subscription-active.json +0 -161
  146. package/test/fixtures/stripe/subscription-canceled.json +0 -161
  147. package/test/fixtures/stripe/subscription-trialing.json +0 -161
  148. package/test/functions/admin/database-read.js +0 -134
  149. package/test/functions/admin/database-write.js +0 -159
  150. package/test/functions/admin/edit-post.js +0 -366
  151. package/test/functions/admin/firestore-query.js +0 -207
  152. package/test/functions/admin/firestore-read.js +0 -129
  153. package/test/functions/admin/firestore-write.js +0 -105
  154. package/test/functions/admin/get-stats.js +0 -115
  155. package/test/functions/admin/send-email.js +0 -119
  156. package/test/functions/admin/send-notification.js +0 -208
  157. package/test/functions/admin/write-repo-content.js +0 -223
  158. package/test/functions/general/add-marketing-contact.js +0 -335
  159. package/test/functions/general/fetch-post.js +0 -54
  160. package/test/functions/general/generate-uuid.js +0 -114
  161. package/test/functions/test/authenticate.js +0 -64
  162. package/test/functions/user/create-custom-token.js +0 -73
  163. package/test/functions/user/delete.js +0 -135
  164. package/test/functions/user/get-active-sessions.js +0 -111
  165. package/test/functions/user/get-subscription-info.js +0 -99
  166. package/test/functions/user/regenerate-api-keys.js +0 -156
  167. package/test/functions/user/resolve.js +0 -52
  168. package/test/functions/user/sign-out-all-sessions.js +0 -94
  169. package/test/functions/user/sign-up.js +0 -252
  170. package/test/functions/user/submit-feedback.js +0 -104
  171. package/test/functions/user/validate-settings.js +0 -82
  172. package/test/helpers/ai-request-payload.js +0 -300
  173. package/test/helpers/ai-test-provider.js +0 -202
  174. package/test/helpers/ai-tools-format.js +0 -383
  175. package/test/helpers/content/blog-auto-publisher.js +0 -484
  176. package/test/helpers/content/feed-parser.js +0 -528
  177. package/test/helpers/content/ghostii-blocks.js +0 -134
  178. package/test/helpers/content/ghostii-feed-integration.js +0 -404
  179. package/test/helpers/content/ghostii-write-article.js +0 -243
  180. package/test/helpers/environment.js +0 -230
  181. package/test/helpers/infer-contact.js +0 -113
  182. package/test/helpers/merge-line-files.js +0 -271
  183. package/test/helpers/payment/chargebee/parse-webhook.js +0 -413
  184. package/test/helpers/payment/chargebee/to-unified-one-time.js +0 -147
  185. package/test/helpers/payment/chargebee/to-unified-subscription.js +0 -648
  186. package/test/helpers/payment/paypal/parse-webhook.js +0 -539
  187. package/test/helpers/payment/paypal/to-unified-one-time.js +0 -382
  188. package/test/helpers/payment/paypal/to-unified-subscription.js +0 -820
  189. package/test/helpers/payment/stripe/parse-webhook.js +0 -447
  190. package/test/helpers/payment/stripe/to-unified-one-time.js +0 -306
  191. package/test/helpers/payment/stripe/to-unified-subscription.js +0 -708
  192. package/test/helpers/sanitize.js +0 -222
  193. package/test/helpers/slugify.js +0 -394
  194. package/test/helpers/storage.js +0 -194
  195. package/test/helpers/user.js +0 -755
  196. package/test/helpers/webhook-forward.js +0 -418
  197. package/test/mcp/discovery.js +0 -53
  198. package/test/mcp/oauth.js +0 -161
  199. package/test/mcp/protocol.js +0 -268
  200. package/test/mcp/roles.js +0 -188
  201. package/test/mcp/utils.js +0 -245
  202. package/test/routes/admin/create-post.js +0 -364
  203. package/test/routes/admin/database.js +0 -131
  204. package/test/routes/admin/deduplicate-image-alts.js +0 -190
  205. package/test/routes/admin/email.js +0 -114
  206. package/test/routes/admin/firestore-query.js +0 -204
  207. package/test/routes/admin/firestore.js +0 -127
  208. package/test/routes/admin/infer-contact.js +0 -218
  209. package/test/routes/admin/notification.js +0 -198
  210. package/test/routes/admin/post-resize-image.js +0 -184
  211. package/test/routes/admin/post.js +0 -368
  212. package/test/routes/admin/repo-content.js +0 -223
  213. package/test/routes/admin/stats.js +0 -112
  214. package/test/routes/content/post.js +0 -54
  215. package/test/routes/general/uuid.js +0 -115
  216. package/test/routes/marketing/campaign.js +0 -125
  217. package/test/routes/marketing/contact.js +0 -370
  218. package/test/routes/marketing/email-preferences.js +0 -292
  219. package/test/routes/marketing/push-send.js +0 -32
  220. package/test/routes/marketing/webhook-forward.js +0 -61
  221. package/test/routes/marketing/webhook.js +0 -639
  222. package/test/routes/payments/cancel.js +0 -163
  223. package/test/routes/payments/discount.js +0 -80
  224. package/test/routes/payments/dispute-alert.js +0 -320
  225. package/test/routes/payments/intent.js +0 -336
  226. package/test/routes/payments/portal.js +0 -92
  227. package/test/routes/payments/refund.js +0 -179
  228. package/test/routes/payments/trial-eligibility.js +0 -71
  229. package/test/routes/payments/webhook.js +0 -107
  230. package/test/routes/test/authenticate.js +0 -59
  231. package/test/routes/test/schema.js +0 -554
  232. package/test/routes/test/usage.js +0 -342
  233. package/test/routes/user/api-keys.js +0 -156
  234. package/test/routes/user/delete.js +0 -136
  235. package/test/routes/user/feedback.js +0 -104
  236. package/test/routes/user/sessions.js +0 -199
  237. package/test/routes/user/settings-validate.js +0 -82
  238. package/test/routes/user/signup.js +0 -542
  239. package/test/routes/user/subscription.js +0 -99
  240. package/test/routes/user/token.js +0 -73
  241. package/test/routes/user/user.js +0 -157
  242. package/test/rules/notifications.js +0 -410
  243. package/test/rules/payments-carts.js +0 -371
  244. package/test/rules/user.js +0 -396
@@ -1,413 +0,0 @@
1
- /**
2
- * Test: Chargebee parseWebhook()
3
- * Unit tests for the Chargebee webhook processor's event categorization and routing
4
- *
5
- * Verifies that parseWebhook() correctly determines category, resourceType, resourceId,
6
- * and uid for each supported event type.
7
- */
8
- const chargebeeProcessor = require('../../../../src/manager/routes/payments/webhook/processors/chargebee.js');
9
-
10
- // Chargebee webhook fixtures
11
- const FIXTURE_SUB_CREATED = require('../../../fixtures/chargebee/webhook-subscription-created.json');
12
- const FIXTURE_PAYMENT_FAILED = require('../../../fixtures/chargebee/webhook-payment-failed.json');
13
-
14
- function parseWebhook(event) {
15
- return chargebeeProcessor.parseWebhook({ body: event });
16
- }
17
-
18
- module.exports = {
19
- description: 'Chargebee parseWebhook() event categorization',
20
- type: 'group',
21
-
22
- tests: [
23
- // ─── isSupported() ───
24
-
25
- {
26
- name: 'supports-subscription-created',
27
- async run({ assert }) {
28
- assert.ok(chargebeeProcessor.isSupported('subscription_created'), 'Should support subscription_created');
29
- },
30
- },
31
-
32
- {
33
- name: 'supports-subscription-cancelled',
34
- async run({ assert }) {
35
- assert.ok(chargebeeProcessor.isSupported('subscription_cancelled'), 'Should support subscription_cancelled');
36
- },
37
- },
38
-
39
- {
40
- name: 'supports-subscription-activated',
41
- async run({ assert }) {
42
- assert.ok(chargebeeProcessor.isSupported('subscription_activated'), 'Should support subscription_activated');
43
- },
44
- },
45
-
46
- {
47
- name: 'supports-subscription-changed',
48
- async run({ assert }) {
49
- assert.ok(chargebeeProcessor.isSupported('subscription_changed'), 'Should support subscription_changed');
50
- },
51
- },
52
-
53
- {
54
- name: 'supports-subscription-renewed',
55
- async run({ assert }) {
56
- assert.ok(chargebeeProcessor.isSupported('subscription_renewed'), 'Should support subscription_renewed');
57
- },
58
- },
59
-
60
- {
61
- name: 'supports-subscription-reactivated',
62
- async run({ assert }) {
63
- assert.ok(chargebeeProcessor.isSupported('subscription_reactivated'), 'Should support subscription_reactivated');
64
- },
65
- },
66
-
67
- {
68
- name: 'supports-cancellation-scheduled',
69
- async run({ assert }) {
70
- assert.ok(chargebeeProcessor.isSupported('subscription_cancellation_scheduled'), 'Should support subscription_cancellation_scheduled');
71
- },
72
- },
73
-
74
- {
75
- name: 'supports-cancellation-removed',
76
- async run({ assert }) {
77
- assert.ok(chargebeeProcessor.isSupported('subscription_scheduled_cancellation_removed'), 'Should support scheduled_cancellation_removed');
78
- },
79
- },
80
-
81
- {
82
- name: 'supports-payment-failed',
83
- async run({ assert }) {
84
- assert.ok(chargebeeProcessor.isSupported('payment_failed'), 'Should support payment_failed');
85
- },
86
- },
87
-
88
- {
89
- name: 'supports-payment-refunded',
90
- async run({ assert }) {
91
- assert.ok(chargebeeProcessor.isSupported('payment_refunded'), 'Should support payment_refunded');
92
- },
93
- },
94
-
95
- {
96
- name: 'supports-invoice-generated',
97
- async run({ assert }) {
98
- assert.ok(chargebeeProcessor.isSupported('invoice_generated'), 'Should support invoice_generated');
99
- },
100
- },
101
-
102
- {
103
- name: 'rejects-unsupported-event',
104
- async run({ assert }) {
105
- assert.equal(chargebeeProcessor.isSupported('customer_created'), false, 'Should not support customer_created');
106
- assert.equal(chargebeeProcessor.isSupported('coupon_created'), false, 'Should not support coupon_created');
107
- assert.equal(chargebeeProcessor.isSupported('subscription_deleted'), false, 'Should not support subscription_deleted');
108
- },
109
- },
110
-
111
- // ─── Validation ───
112
-
113
- {
114
- name: 'throws-on-empty-body',
115
- async run({ assert }) {
116
- try {
117
- parseWebhook(null);
118
- assert.fail('Should have thrown');
119
- } catch (e) {
120
- assert.match(e.message, /Invalid/, 'Should mention invalid payload');
121
- }
122
- },
123
- },
124
-
125
- {
126
- name: 'throws-on-missing-id',
127
- async run({ assert }) {
128
- try {
129
- parseWebhook({ event_type: 'subscription_created', content: {} });
130
- assert.fail('Should have thrown');
131
- } catch (e) {
132
- assert.match(e.message, /Invalid/, 'Should mention invalid payload');
133
- }
134
- },
135
- },
136
-
137
- {
138
- name: 'throws-on-missing-event-type',
139
- async run({ assert }) {
140
- try {
141
- parseWebhook({ id: 'ev_123', content: {} });
142
- assert.fail('Should have thrown');
143
- } catch (e) {
144
- assert.match(e.message, /Invalid/, 'Should mention invalid payload');
145
- }
146
- },
147
- },
148
-
149
- // ─── Subscription events ───
150
-
151
- {
152
- name: 'subscription-created-category',
153
- async run({ assert }) {
154
- const result = parseWebhook({
155
- id: 'ev_sub_created',
156
- event_type: 'subscription_created',
157
- content: {
158
- subscription: {
159
- id: 'sub_123',
160
- meta_data: '{"uid":"user-abc"}',
161
- },
162
- customer: { id: 'cust_123' },
163
- },
164
- });
165
-
166
- assert.equal(result.category, 'subscription', 'Category should be subscription');
167
- assert.equal(result.resourceType, 'subscription', 'Resource type should be subscription');
168
- assert.equal(result.resourceId, 'sub_123', 'Resource ID should be subscription ID');
169
- assert.equal(result.uid, 'user-abc', 'UID should come from meta_data');
170
- assert.equal(result.eventId, 'ev_sub_created', 'Event ID should match');
171
- assert.equal(result.eventType, 'subscription_created', 'Event type should match');
172
- },
173
- },
174
-
175
- {
176
- name: 'subscription-cancelled-category',
177
- async run({ assert }) {
178
- const result = parseWebhook({
179
- id: 'ev_sub_cancelled',
180
- event_type: 'subscription_cancelled',
181
- content: {
182
- subscription: {
183
- id: 'sub_456',
184
- meta_data: '{"uid":"user-def"}',
185
- },
186
- },
187
- });
188
-
189
- assert.equal(result.category, 'subscription', 'Category should be subscription');
190
- assert.equal(result.resourceId, 'sub_456', 'Resource ID should match');
191
- assert.equal(result.uid, 'user-def', 'UID should match');
192
- },
193
- },
194
-
195
- {
196
- name: 'subscription-cancellation-scheduled-category',
197
- async run({ assert }) {
198
- const result = parseWebhook({
199
- id: 'ev_cancel_scheduled',
200
- event_type: 'subscription_cancellation_scheduled',
201
- content: {
202
- subscription: {
203
- id: 'sub_789',
204
- meta_data: '{"uid":"user-ghi"}',
205
- status: 'non_renewing',
206
- },
207
- },
208
- });
209
-
210
- assert.equal(result.category, 'subscription', 'Category should be subscription');
211
- assert.equal(result.uid, 'user-ghi', 'UID should match');
212
- },
213
- },
214
-
215
- {
216
- name: 'subscription-event-uid-from-legacy-cf',
217
- async run({ assert }) {
218
- const result = parseWebhook({
219
- id: 'ev_legacy_uid',
220
- event_type: 'subscription_renewed',
221
- content: {
222
- subscription: {
223
- id: 'sub_legacy',
224
- cf_uid: 'legacy-user-123',
225
- },
226
- },
227
- });
228
-
229
- assert.equal(result.uid, 'legacy-user-123', 'UID should fall back to cf_uid');
230
- },
231
- },
232
-
233
- {
234
- name: 'subscription-event-null-uid-when-missing',
235
- async run({ assert }) {
236
- const result = parseWebhook({
237
- id: 'ev_no_uid',
238
- event_type: 'subscription_created',
239
- content: {
240
- subscription: { id: 'sub_no_uid' },
241
- },
242
- });
243
-
244
- assert.equal(result.uid, null, 'UID should be null when not available');
245
- assert.equal(result.category, 'subscription', 'Category should still be subscription');
246
- },
247
- },
248
-
249
- // ─── payment_failed ───
250
-
251
- {
252
- name: 'payment-failed-subscription-category',
253
- async run({ assert }) {
254
- const result = parseWebhook({
255
- id: 'ev_pay_fail',
256
- event_type: 'payment_failed',
257
- content: {
258
- subscription: {
259
- id: 'sub_fail',
260
- meta_data: '{"uid":"user-fail"}',
261
- },
262
- invoice: { id: 'inv_fail', subscription_id: 'sub_fail' },
263
- },
264
- });
265
-
266
- assert.equal(result.category, 'subscription', 'With subscription → subscription category');
267
- assert.equal(result.resourceType, 'subscription', 'Should fetch subscription');
268
- assert.equal(result.resourceId, 'sub_fail', 'Resource ID should be subscription ID');
269
- assert.equal(result.uid, 'user-fail', 'UID from subscription');
270
- },
271
- },
272
-
273
- {
274
- name: 'payment-failed-one-time-category',
275
- async run({ assert }) {
276
- const result = parseWebhook({
277
- id: 'ev_pay_fail_onetime',
278
- event_type: 'payment_failed',
279
- content: {
280
- invoice: { id: 'inv_onetime_fail' },
281
- customer: { id: 'cust_onetime' },
282
- },
283
- });
284
-
285
- assert.equal(result.category, 'one-time', 'No subscription → one-time');
286
- assert.equal(result.resourceType, 'invoice', 'Should fetch invoice');
287
- assert.equal(result.resourceId, 'inv_onetime_fail', 'Resource ID should be invoice ID');
288
- },
289
- },
290
-
291
- // ─── payment_refunded ───
292
-
293
- {
294
- name: 'payment-refunded-subscription-category',
295
- async run({ assert }) {
296
- const result = parseWebhook({
297
- id: 'ev_refund',
298
- event_type: 'payment_refunded',
299
- content: {
300
- subscription: {
301
- id: 'sub_refund',
302
- meta_data: '{"uid":"user-refund"}',
303
- },
304
- },
305
- });
306
-
307
- assert.equal(result.category, 'subscription', 'With subscription → subscription');
308
- assert.equal(result.resourceId, 'sub_refund', 'Resource ID should be subscription');
309
- assert.equal(result.uid, 'user-refund', 'UID from subscription');
310
- },
311
- },
312
-
313
- {
314
- name: 'payment-refunded-no-subscription-skipped',
315
- async run({ assert }) {
316
- const result = parseWebhook({
317
- id: 'ev_refund_no_sub',
318
- event_type: 'payment_refunded',
319
- content: {
320
- transaction: { id: 'txn_refund' },
321
- },
322
- });
323
-
324
- assert.equal(result.category, null, 'No subscription → null (skipped)');
325
- },
326
- },
327
-
328
- // ─── invoice_generated ───
329
-
330
- {
331
- name: 'invoice-generated-non-recurring-one-time',
332
- async run({ assert }) {
333
- const result = parseWebhook({
334
- id: 'ev_inv_gen',
335
- event_type: 'invoice_generated',
336
- content: {
337
- invoice: { id: 'inv_onetime_001' },
338
- customer: { id: 'cust_onetime' },
339
- },
340
- });
341
-
342
- assert.equal(result.category, 'one-time', 'Non-recurring invoice → one-time');
343
- assert.equal(result.resourceType, 'invoice', 'Should fetch invoice');
344
- assert.equal(result.resourceId, 'inv_onetime_001', 'Resource ID should be invoice ID');
345
- },
346
- },
347
-
348
- {
349
- name: 'invoice-generated-recurring-skipped',
350
- async run({ assert }) {
351
- const result = parseWebhook({
352
- id: 'ev_inv_recurring',
353
- event_type: 'invoice_generated',
354
- content: {
355
- invoice: { id: 'inv_recurring', subscription_id: 'sub_existing' },
356
- },
357
- });
358
-
359
- assert.equal(result.category, null, 'Recurring invoice → null (skipped)');
360
- },
361
- },
362
-
363
- // ─── Fixture tests ───
364
-
365
- {
366
- name: 'fixture-subscription-created',
367
- async run({ assert }) {
368
- const result = parseWebhook(FIXTURE_SUB_CREATED);
369
-
370
- assert.equal(result.eventId, FIXTURE_SUB_CREATED.id, 'Event ID matches fixture');
371
- assert.equal(result.eventType, 'subscription_created', 'Event type matches');
372
- assert.equal(result.category, 'subscription', 'Category is subscription');
373
- assert.equal(result.resourceType, 'subscription', 'Resource type is subscription');
374
- assert.equal(result.resourceId, 'cb_sub_active_001', 'Resource ID from content.subscription.id');
375
- assert.equal(result.uid, 'test-uid-001', 'UID from meta_data');
376
- },
377
- },
378
-
379
- {
380
- name: 'fixture-payment-failed',
381
- async run({ assert }) {
382
- const result = parseWebhook(FIXTURE_PAYMENT_FAILED);
383
-
384
- assert.equal(result.eventId, FIXTURE_PAYMENT_FAILED.id, 'Event ID matches fixture');
385
- assert.equal(result.eventType, 'payment_failed', 'Event type matches');
386
- assert.equal(result.category, 'subscription', 'Category is subscription (has subscription)');
387
- assert.equal(result.resourceType, 'subscription', 'Resource type is subscription');
388
- assert.equal(result.resourceId, 'cb_sub_active_001', 'Resource ID from content.subscription.id');
389
- assert.equal(result.uid, 'test-uid-001', 'UID from subscription meta_data');
390
- },
391
- },
392
-
393
- // ─── raw passthrough ───
394
-
395
- {
396
- name: 'raw-contains-full-event',
397
- async run({ assert }) {
398
- const event = {
399
- id: 'ev_raw',
400
- event_type: 'subscription_changed',
401
- content: {
402
- subscription: { id: 'sub_raw', meta_data: '{"uid":"user-raw"}' },
403
- },
404
- extra_field: 'preserved',
405
- };
406
-
407
- const result = parseWebhook(event);
408
- assert.equal(result.raw, event, 'Raw should be the full event object');
409
- assert.equal(result.raw.extra_field, 'preserved', 'Extra fields preserved in raw');
410
- },
411
- },
412
- ],
413
- };
@@ -1,147 +0,0 @@
1
- /**
2
- * Test: Chargebee toUnifiedOneTime()
3
- * Unit tests for the Chargebee library's invoice → unified one-time transformation
4
- */
5
- const Chargebee = require('../../../../src/manager/libraries/payment/processors/chargebee.js');
6
-
7
- const FIXTURE_INVOICE = require('../../../fixtures/chargebee/invoice-one-time.json');
8
-
9
- const MOCK_CONFIG = {
10
- payment: {
11
- products: [
12
- { id: 'basic', name: 'Basic', type: 'subscription' },
13
- {
14
- id: 'credits-100', name: '100 Credits', type: 'one-time',
15
- prices: { once: 9.99 },
16
- },
17
- ],
18
- },
19
- };
20
-
21
- function toUnifiedOneTime(rawResource, options) {
22
- return Chargebee.toUnifiedOneTime(rawResource, { config: MOCK_CONFIG, ...options });
23
- }
24
-
25
- module.exports = {
26
- description: 'Chargebee toUnifiedOneTime() transformation',
27
- type: 'group',
28
-
29
- tests: [
30
- {
31
- name: 'status-paid-to-completed',
32
- async run({ assert }) {
33
- const result = toUnifiedOneTime({ status: 'paid' });
34
- assert.equal(result.status, 'completed', 'paid → completed');
35
- },
36
- },
37
-
38
- {
39
- name: 'status-not-paid-to-failed',
40
- async run({ assert }) {
41
- const result = toUnifiedOneTime({ status: 'not_paid' });
42
- assert.equal(result.status, 'failed', 'not_paid → failed');
43
- },
44
- },
45
-
46
- {
47
- name: 'status-payment-due-to-failed',
48
- async run({ assert }) {
49
- const result = toUnifiedOneTime({ status: 'payment_due' });
50
- assert.equal(result.status, 'failed', 'payment_due → failed');
51
- },
52
- },
53
-
54
- {
55
- name: 'status-unknown-passthrough',
56
- async run({ assert }) {
57
- const result = toUnifiedOneTime({ status: 'pending' });
58
- assert.equal(result.status, 'pending', 'Other statuses pass through');
59
- },
60
- },
61
-
62
- {
63
- name: 'processor-always-chargebee',
64
- async run({ assert }) {
65
- const result = toUnifiedOneTime({});
66
- assert.equal(result.payment.processor, 'chargebee', 'Processor should be chargebee');
67
- },
68
- },
69
-
70
- {
71
- name: 'resource-id-from-invoice-id',
72
- async run({ assert }) {
73
- const result = toUnifiedOneTime({ id: 'inv_123' });
74
- assert.equal(result.payment.resourceId, 'inv_123', 'resourceId from invoice id');
75
- },
76
- },
77
-
78
- {
79
- name: 'order-id-from-meta-data',
80
- async run({ assert }) {
81
- const result = toUnifiedOneTime({ meta_data: '{"orderId":"1234-5678-9012"}' });
82
- assert.equal(result.payment.orderId, '1234-5678-9012', 'orderId from meta_data');
83
- },
84
- },
85
-
86
- {
87
- name: 'order-id-from-cf-legacy',
88
- async run({ assert }) {
89
- const result = toUnifiedOneTime({ cf_clientorderid: 'legacy-order' });
90
- assert.equal(result.payment.orderId, 'legacy-order', 'orderId from cf_clientorderid');
91
- },
92
- },
93
-
94
- {
95
- name: 'product-resolves-from-meta-data',
96
- async run({ assert }) {
97
- const result = toUnifiedOneTime({
98
- meta_data: '{"productId":"credits-100"}',
99
- status: 'paid',
100
- });
101
- assert.equal(result.product.id, 'credits-100', 'Product resolved from meta_data');
102
- assert.equal(result.product.name, '100 Credits', 'Product name resolved');
103
- },
104
- },
105
-
106
- {
107
- name: 'product-unknown-when-no-meta-data',
108
- async run({ assert }) {
109
- const result = toUnifiedOneTime({});
110
- assert.equal(result.product.id, 'unknown', 'No productId → unknown');
111
- },
112
- },
113
-
114
- {
115
- name: 'event-metadata-passed-through',
116
- async run({ assert }) {
117
- const result = toUnifiedOneTime({}, { eventName: 'invoice_generated', eventId: 'ev_inv' });
118
- assert.equal(result.payment.updatedBy.event.name, 'invoice_generated', 'Event name');
119
- assert.equal(result.payment.updatedBy.event.id, 'ev_inv', 'Event ID');
120
- },
121
- },
122
-
123
- {
124
- name: 'fixture-invoice-one-time',
125
- async run({ assert }) {
126
- const result = toUnifiedOneTime(FIXTURE_INVOICE);
127
- assert.equal(result.status, 'completed', 'Fixture paid → completed');
128
- assert.equal(result.payment.processor, 'chargebee', 'Processor is chargebee');
129
- assert.equal(result.payment.resourceId, FIXTURE_INVOICE.id, 'Resource ID matches fixture');
130
- assert.equal(result.payment.orderId, '6789-0123-4567', 'Order ID from meta_data');
131
- assert.equal(result.product.id, 'credits-100', 'Product from meta_data productId');
132
- },
133
- },
134
-
135
- {
136
- name: 'unified-shape-complete',
137
- async run({ assert }) {
138
- const result = toUnifiedOneTime(FIXTURE_INVOICE);
139
- assert.ok(result.product, 'Should have product');
140
- assert.ok(result.status, 'Should have status');
141
- assert.ok(result.payment, 'Should have payment');
142
- assert.ok(result.payment.updatedBy, 'Should have updatedBy');
143
- assert.ok(result.payment.updatedBy.date, 'Should have updatedBy.date');
144
- },
145
- },
146
- ],
147
- };