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,648 +0,0 @@
1
- /**
2
- * Test: Chargebee toUnifiedSubscription()
3
- * Unit tests for the Chargebee library's raw subscription → unified subscription transformation
4
- *
5
- * Tests the pure function directly — no emulator, no Firestore, no HTTP
6
- */
7
- const Chargebee = require('../../../../src/manager/libraries/payment/processors/chargebee.js');
8
-
9
- // Chargebee fixtures
10
- const FIXTURE_ACTIVE = require('../../../fixtures/chargebee/subscription-active.json');
11
- const FIXTURE_CANCELLED = require('../../../fixtures/chargebee/subscription-cancelled.json');
12
- const FIXTURE_TRIAL = require('../../../fixtures/chargebee/subscription-in-trial.json');
13
- const FIXTURE_NON_RENEWING = require('../../../fixtures/chargebee/subscription-non-renewing.json');
14
- const FIXTURE_PAUSED = require('../../../fixtures/chargebee/subscription-paused.json');
15
- const FIXTURE_LEGACY = require('../../../fixtures/chargebee/subscription-legacy-plan.json');
16
-
17
- // Mock config matching the BEM template
18
- const MOCK_CONFIG = {
19
- payment: {
20
- products: [
21
- { id: 'basic', name: 'Basic', type: 'subscription', limits: { requests: 100 } },
22
- {
23
- id: 'pro', name: 'Pro', type: 'subscription',
24
- prices: { monthly: 4.99, annually: 49.99 },
25
- chargebee: {
26
- itemId: 'somiibo-pro',
27
- legacyPlanIds: ['somiibo-premium-monthly-1', 'somiibo-premium-annually-1'],
28
- },
29
- },
30
- {
31
- id: 'plus', name: 'Plus', type: 'subscription',
32
- prices: { monthly: 2.99, annually: 29.99 },
33
- chargebee: {
34
- itemId: 'somiibo-plus',
35
- legacyPlanIds: [],
36
- },
37
- },
38
- ],
39
- },
40
- };
41
-
42
- function toUnifiedSubscription(rawSubscription, options) {
43
- return Chargebee.toUnifiedSubscription(rawSubscription, { config: MOCK_CONFIG, ...options });
44
- }
45
-
46
- module.exports = {
47
- description: 'Chargebee toUnifiedSubscription() transformation',
48
- type: 'group',
49
-
50
- tests: [
51
- // ─── Status mapping ───
52
-
53
- {
54
- name: 'status-active',
55
- async run({ assert }) {
56
- const result = toUnifiedSubscription({ status: 'active' });
57
- assert.equal(result.status, 'active', 'Chargebee active → unified active');
58
- },
59
- },
60
-
61
- {
62
- name: 'status-in-trial',
63
- async run({ assert }) {
64
- const result = toUnifiedSubscription({ status: 'in_trial', trial_start: 1000, trial_end: 2000 });
65
- assert.equal(result.status, 'active', 'Chargebee in_trial → unified active');
66
- },
67
- },
68
-
69
- {
70
- name: 'status-non-renewing',
71
- async run({ assert }) {
72
- const result = toUnifiedSubscription({ status: 'non_renewing' });
73
- assert.equal(result.status, 'active', 'Chargebee non_renewing → unified active');
74
- },
75
- },
76
-
77
- {
78
- name: 'status-future',
79
- async run({ assert }) {
80
- const result = toUnifiedSubscription({ status: 'future' });
81
- assert.equal(result.status, 'active', 'Chargebee future → unified active');
82
- },
83
- },
84
-
85
- {
86
- name: 'status-paused',
87
- async run({ assert }) {
88
- const result = toUnifiedSubscription({ status: 'paused' });
89
- assert.equal(result.status, 'suspended', 'Chargebee paused → unified suspended');
90
- },
91
- },
92
-
93
- {
94
- name: 'status-cancelled',
95
- async run({ assert }) {
96
- const result = toUnifiedSubscription({ status: 'cancelled' });
97
- assert.equal(result.status, 'cancelled', 'Chargebee cancelled → unified cancelled');
98
- },
99
- },
100
-
101
- {
102
- name: 'status-transferred',
103
- async run({ assert }) {
104
- const result = toUnifiedSubscription({ status: 'transferred' });
105
- assert.equal(result.status, 'cancelled', 'Chargebee transferred → unified cancelled');
106
- },
107
- },
108
-
109
- {
110
- name: 'status-unknown-defaults-to-cancelled',
111
- async run({ assert }) {
112
- const result = toUnifiedSubscription({ status: 'some_future_status' });
113
- assert.equal(result.status, 'cancelled', 'Unknown status → cancelled');
114
- },
115
- },
116
-
117
- // ─── Product resolution (Items model) ───
118
-
119
- {
120
- name: 'product-resolves-from-item-price-id',
121
- async run({ assert }) {
122
- const result = toUnifiedSubscription({
123
- subscription_items: [{ item_price_id: 'somiibo-pro-monthly' }],
124
- });
125
- assert.equal(result.product.id, 'pro', 'Should resolve to pro');
126
- assert.equal(result.product.name, 'Pro', 'Should have correct name');
127
- },
128
- },
129
-
130
- {
131
- name: 'product-resolves-plus-from-item-price-id',
132
- async run({ assert }) {
133
- const result = toUnifiedSubscription({
134
- subscription_items: [{ item_price_id: 'somiibo-plus-annually' }],
135
- });
136
- assert.equal(result.product.id, 'plus', 'Should resolve to plus');
137
- assert.equal(result.product.name, 'Plus', 'Should have correct name');
138
- },
139
- },
140
-
141
- // ─── Product resolution (Legacy Plans model) ───
142
-
143
- {
144
- name: 'product-resolves-from-legacy-plan-id',
145
- async run({ assert }) {
146
- const result = toUnifiedSubscription({
147
- plan_id: 'somiibo-premium-monthly-1',
148
- });
149
- assert.equal(result.product.id, 'pro', 'Legacy plan → pro');
150
- assert.equal(result.product.name, 'Pro', 'Legacy plan → Pro name');
151
- },
152
- },
153
-
154
- {
155
- name: 'product-resolves-from-legacy-annual-plan-id',
156
- async run({ assert }) {
157
- const result = toUnifiedSubscription({
158
- plan_id: 'somiibo-premium-annually-1',
159
- });
160
- assert.equal(result.product.id, 'pro', 'Legacy annual plan → pro');
161
- },
162
- },
163
-
164
- {
165
- name: 'product-falls-back-to-basic-on-unknown',
166
- async run({ assert }) {
167
- const result = toUnifiedSubscription({
168
- subscription_items: [{ item_price_id: 'unknown-product-monthly' }],
169
- });
170
- assert.equal(result.product.id, 'basic', 'Unknown item → basic');
171
- },
172
- },
173
-
174
- {
175
- name: 'product-falls-back-to-basic-on-missing',
176
- async run({ assert }) {
177
- const result = toUnifiedSubscription({});
178
- assert.equal(result.product.id, 'basic', 'No plan → basic');
179
- },
180
- },
181
-
182
- {
183
- name: 'product-falls-back-to-basic-without-config',
184
- async run({ assert }) {
185
- const result = Chargebee.toUnifiedSubscription(
186
- { subscription_items: [{ item_price_id: 'somiibo-pro-monthly' }] },
187
- {},
188
- );
189
- assert.equal(result.product.id, 'basic', 'No config → basic');
190
- },
191
- },
192
-
193
- // ─── Frequency resolution ───
194
-
195
- {
196
- name: 'frequency-monthly-from-item-price-id',
197
- async run({ assert }) {
198
- const result = toUnifiedSubscription({
199
- subscription_items: [{ item_price_id: 'somiibo-pro-monthly' }],
200
- });
201
- assert.equal(result.payment.frequency, 'monthly', 'item_price_id suffix monthly → monthly');
202
- },
203
- },
204
-
205
- {
206
- name: 'frequency-annually-from-item-price-id',
207
- async run({ assert }) {
208
- const result = toUnifiedSubscription({
209
- subscription_items: [{ item_price_id: 'somiibo-pro-annually' }],
210
- });
211
- assert.equal(result.payment.frequency, 'annually', 'item_price_id suffix annually → annually');
212
- },
213
- },
214
-
215
- {
216
- name: 'frequency-weekly-from-item-price-id',
217
- async run({ assert }) {
218
- const result = toUnifiedSubscription({
219
- subscription_items: [{ item_price_id: 'somiibo-pro-weekly' }],
220
- });
221
- assert.equal(result.payment.frequency, 'weekly', 'item_price_id suffix weekly → weekly');
222
- },
223
- },
224
-
225
- {
226
- name: 'frequency-daily-from-item-price-id',
227
- async run({ assert }) {
228
- const result = toUnifiedSubscription({
229
- subscription_items: [{ item_price_id: 'somiibo-pro-daily' }],
230
- });
231
- assert.equal(result.payment.frequency, 'daily', 'item_price_id suffix daily → daily');
232
- },
233
- },
234
-
235
- {
236
- name: 'frequency-from-legacy-billing-period-unit',
237
- async run({ assert }) {
238
- const result = toUnifiedSubscription({ billing_period_unit: 'month' });
239
- assert.equal(result.payment.frequency, 'monthly', 'Legacy month → monthly');
240
- },
241
- },
242
-
243
- {
244
- name: 'frequency-year-from-legacy',
245
- async run({ assert }) {
246
- const result = toUnifiedSubscription({ billing_period_unit: 'year' });
247
- assert.equal(result.payment.frequency, 'annually', 'Legacy year → annually');
248
- },
249
- },
250
-
251
- {
252
- name: 'frequency-null-when-missing',
253
- async run({ assert }) {
254
- const result = toUnifiedSubscription({});
255
- assert.equal(result.payment.frequency, null, 'Missing → null');
256
- },
257
- },
258
-
259
- // ─── Trial resolution ───
260
-
261
- {
262
- name: 'trial-claimed-when-both-dates-present',
263
- async run({ assert }) {
264
- const result = toUnifiedSubscription({ trial_start: 1700000000, trial_end: 1701209600 });
265
- assert.equal(result.trial.claimed, true, 'Both trial dates → claimed');
266
- assert.ok(result.trial.expires.timestampUNIX > 0, 'Trial expires should be set');
267
- },
268
- },
269
-
270
- {
271
- name: 'trial-not-claimed-when-no-dates',
272
- async run({ assert }) {
273
- const result = toUnifiedSubscription({});
274
- assert.equal(result.trial.claimed, false, 'No trial dates → not claimed');
275
- },
276
- },
277
-
278
- {
279
- name: 'trial-not-claimed-when-only-start',
280
- async run({ assert }) {
281
- const result = toUnifiedSubscription({ trial_start: 1700000000 });
282
- assert.equal(result.trial.claimed, false, 'Only trial_start → not claimed');
283
- },
284
- },
285
-
286
- // ─── Cancellation resolution ───
287
-
288
- {
289
- name: 'cancellation-pending-when-non-renewing',
290
- async run({ assert }) {
291
- const futureTimestamp = Math.floor(Date.now() / 1000) + 86400 * 30;
292
- const result = toUnifiedSubscription({
293
- status: 'non_renewing',
294
- current_term_end: futureTimestamp,
295
- });
296
- assert.equal(result.cancellation.pending, true, 'non_renewing → pending');
297
- assert.ok(result.cancellation.date.timestampUNIX > 0, 'Should have cancellation date');
298
- },
299
- },
300
-
301
- {
302
- name: 'cancellation-completed-when-cancelled',
303
- async run({ assert }) {
304
- const pastTimestamp = Math.floor(Date.now() / 1000) - 86400;
305
- const result = toUnifiedSubscription({
306
- status: 'cancelled',
307
- cancelled_at: pastTimestamp,
308
- });
309
- assert.equal(result.cancellation.pending, false, 'cancelled → not pending');
310
- assert.ok(result.cancellation.date.timestampUNIX > 0, 'Should have cancellation date');
311
- },
312
- },
313
-
314
- {
315
- name: 'cancellation-none',
316
- async run({ assert }) {
317
- const result = toUnifiedSubscription({ status: 'active' });
318
- assert.equal(result.cancellation.pending, false, 'No cancellation → not pending');
319
- },
320
- },
321
-
322
- // ─── Expiration and start date ───
323
-
324
- {
325
- name: 'expires-from-current-term-end',
326
- async run({ assert }) {
327
- const futureTimestamp = Math.floor(Date.now() / 1000) + 86400 * 30;
328
- const result = toUnifiedSubscription({ current_term_end: futureTimestamp });
329
- assert.ok(result.expires.timestampUNIX > 0, 'Should have expiration');
330
- },
331
- },
332
-
333
- {
334
- name: 'expires-defaults-to-epoch-when-missing',
335
- async run({ assert }) {
336
- const result = toUnifiedSubscription({});
337
- assert.equal(result.expires.timestampUNIX, 0, 'Missing current_term_end → epoch');
338
- },
339
- },
340
-
341
- {
342
- name: 'start-date-from-started-at',
343
- async run({ assert }) {
344
- const startTimestamp = Math.floor(Date.now() / 1000) - 86400 * 30;
345
- const result = toUnifiedSubscription({ started_at: startTimestamp });
346
- assert.ok(result.payment.startDate.timestampUNIX > 0, 'Should have start date');
347
- },
348
- },
349
-
350
- {
351
- name: 'start-date-fallback-to-created-at',
352
- async run({ assert }) {
353
- const createTimestamp = Math.floor(Date.now() / 1000) - 86400 * 60;
354
- const result = toUnifiedSubscription({ created_at: createTimestamp });
355
- assert.ok(result.payment.startDate.timestampUNIX > 0, 'Should use created_at as fallback');
356
- },
357
- },
358
-
359
- {
360
- name: 'start-date-defaults-to-epoch-when-missing',
361
- async run({ assert }) {
362
- const result = toUnifiedSubscription({});
363
- assert.equal(result.payment.startDate.timestampUNIX, 0, 'Missing start dates → epoch');
364
- },
365
- },
366
-
367
- // ─── Payment metadata ───
368
-
369
- {
370
- name: 'payment-processor-always-chargebee',
371
- async run({ assert }) {
372
- const result = toUnifiedSubscription({});
373
- assert.equal(result.payment.processor, 'chargebee', 'Processor should always be chargebee');
374
- },
375
- },
376
-
377
- {
378
- name: 'payment-resource-id-from-subscription-id',
379
- async run({ assert }) {
380
- const result = toUnifiedSubscription({ id: 'sub_abc123' });
381
- assert.equal(result.payment.resourceId, 'sub_abc123', 'resourceId should be subscription ID');
382
- },
383
- },
384
-
385
- {
386
- name: 'payment-order-id-from-meta-data',
387
- async run({ assert }) {
388
- const result = toUnifiedSubscription({ meta_data: '{"orderId":"1234-5678-9012"}' });
389
- assert.equal(result.payment.orderId, '1234-5678-9012', 'orderId should come from meta_data');
390
- },
391
- },
392
-
393
- {
394
- name: 'payment-order-id-from-cf-clientorderid-legacy',
395
- async run({ assert }) {
396
- const result = toUnifiedSubscription({ cf_clientorderid: '1678790168794-0784' });
397
- assert.equal(result.payment.orderId, '1678790168794-0784', 'orderId should come from cf_clientorderid');
398
- },
399
- },
400
-
401
- {
402
- name: 'payment-order-id-null-when-missing',
403
- async run({ assert }) {
404
- const result = toUnifiedSubscription({});
405
- assert.equal(result.payment.orderId, null, 'Missing metadata → null orderId');
406
- },
407
- },
408
-
409
- {
410
- name: 'payment-event-metadata-passed-through',
411
- async run({ assert }) {
412
- const result = toUnifiedSubscription({}, { eventName: 'subscription_created', eventId: 'ev_123' });
413
- assert.equal(result.payment.updatedBy.event.name, 'subscription_created', 'Event name passed through');
414
- assert.equal(result.payment.updatedBy.event.id, 'ev_123', 'Event ID passed through');
415
- },
416
- },
417
-
418
- // ─── UID extraction ───
419
-
420
- {
421
- name: 'uid-from-meta-data',
422
- async run({ assert }) {
423
- const resource = { meta_data: '{"uid":"test-user-123","orderId":"1234-5678-9012"}' };
424
- assert.equal(Chargebee.getUid(resource), 'test-user-123', 'UID from meta_data');
425
- },
426
- },
427
-
428
- {
429
- name: 'uid-from-cf-uid-legacy',
430
- async run({ assert }) {
431
- const resource = { cf_uid: 'legacy-user-456' };
432
- assert.equal(Chargebee.getUid(resource), 'legacy-user-456', 'UID from cf_uid');
433
- },
434
- },
435
-
436
- {
437
- name: 'uid-null-when-missing',
438
- async run({ assert }) {
439
- assert.equal(Chargebee.getUid({}), null, 'No metadata → null');
440
- },
441
- },
442
-
443
- // ─── Full unified shape ───
444
-
445
- {
446
- name: 'full-active-subscription-shape',
447
- async run({ assert }) {
448
- const now = Math.floor(Date.now() / 1000);
449
- const result = toUnifiedSubscription({
450
- id: 'sub_full_test',
451
- status: 'active',
452
- subscription_items: [{ item_price_id: 'somiibo-pro-monthly' }],
453
- current_term_end: now + 86400 * 30,
454
- started_at: now - 86400 * 60,
455
- meta_data: '{"uid":"full-test-uid","orderId":"9999-8888-7777"}',
456
- }, { eventName: 'subscription_changed', eventId: 'ev_full' });
457
-
458
- assert.ok(result.product, 'Should have product');
459
- assert.ok(result.status, 'Should have status');
460
- assert.ok(result.expires, 'Should have expires');
461
- assert.ok(result.trial, 'Should have trial');
462
- assert.ok(result.cancellation, 'Should have cancellation');
463
- assert.ok(result.payment, 'Should have payment');
464
-
465
- assert.equal(result.product.id, 'pro', 'Product should be pro');
466
- assert.equal(result.status, 'active', 'Status should be active');
467
- assert.equal(result.trial.claimed, false, 'Trial should not be claimed');
468
- assert.equal(result.cancellation.pending, false, 'Should not be pending cancellation');
469
- assert.equal(result.payment.processor, 'chargebee', 'Processor should be chargebee');
470
- assert.equal(result.payment.resourceId, 'sub_full_test', 'Resource ID should match');
471
- assert.equal(result.payment.frequency, 'monthly', 'Frequency should be monthly');
472
- assert.equal(result.payment.orderId, '9999-8888-7777', 'Order ID from meta_data');
473
- assert.equal(result.payment.updatedBy.event.name, 'subscription_changed', 'Event name should match');
474
- },
475
- },
476
-
477
- {
478
- name: 'empty-subscription-gets-safe-defaults',
479
- async run({ assert }) {
480
- const result = toUnifiedSubscription({});
481
-
482
- assert.equal(result.product.id, 'basic', 'Empty → basic product');
483
- assert.equal(result.status, 'cancelled', 'Empty → cancelled (no status field)');
484
- assert.equal(result.trial.claimed, false, 'Empty → trial not claimed');
485
- assert.equal(result.cancellation.pending, false, 'Empty → not pending');
486
- assert.equal(result.payment.processor, 'chargebee', 'Empty → still chargebee');
487
- assert.equal(result.payment.orderId, null, 'Empty → null orderId');
488
- assert.equal(result.payment.resourceId, null, 'Empty → null resourceId');
489
- assert.equal(result.payment.frequency, null, 'Empty → null frequency');
490
- },
491
- },
492
-
493
- // ─── Real fixtures ───
494
-
495
- {
496
- name: 'fixture-active-status',
497
- async run({ assert }) {
498
- const result = toUnifiedSubscription(FIXTURE_ACTIVE);
499
- assert.equal(result.status, 'active', 'Active fixture → active');
500
- assert.equal(result.payment.processor, 'chargebee', 'Processor is chargebee');
501
- assert.equal(result.payment.resourceId, FIXTURE_ACTIVE.id, 'resourceId matches fixture');
502
- },
503
- },
504
-
505
- {
506
- name: 'fixture-active-product-resolves',
507
- async run({ assert }) {
508
- const result = toUnifiedSubscription(FIXTURE_ACTIVE);
509
- assert.equal(result.product.id, 'pro', 'somiibo-pro-monthly → pro');
510
- assert.equal(result.payment.frequency, 'monthly', 'Active fixture → monthly');
511
- },
512
- },
513
-
514
- {
515
- name: 'fixture-active-metadata',
516
- async run({ assert }) {
517
- const result = toUnifiedSubscription(FIXTURE_ACTIVE);
518
- assert.equal(result.payment.orderId, '1234-5678-9012', 'Order ID from meta_data');
519
- },
520
- },
521
-
522
- {
523
- name: 'fixture-cancelled-status',
524
- async run({ assert }) {
525
- const result = toUnifiedSubscription(FIXTURE_CANCELLED);
526
- assert.equal(result.status, 'cancelled', 'Cancelled fixture → cancelled');
527
- assert.equal(result.cancellation.pending, false, 'Not pending — already cancelled');
528
- assert.ok(result.cancellation.date.timestampUNIX > 0, 'Should have cancellation date');
529
- },
530
- },
531
-
532
- {
533
- name: 'fixture-trial-status',
534
- async run({ assert }) {
535
- const result = toUnifiedSubscription(FIXTURE_TRIAL);
536
- assert.equal(result.status, 'active', 'Trial fixture → active');
537
- assert.equal(result.trial.claimed, true, 'Trial → claimed');
538
- assert.ok(result.trial.expires.timestampUNIX > 0, 'Trial expiration should be set');
539
- },
540
- },
541
-
542
- {
543
- name: 'fixture-non-renewing-status',
544
- async run({ assert }) {
545
- const result = toUnifiedSubscription(FIXTURE_NON_RENEWING);
546
- assert.equal(result.status, 'active', 'Non-renewing fixture → active');
547
- assert.equal(result.cancellation.pending, true, 'Non-renewing → pending cancellation');
548
- },
549
- },
550
-
551
- {
552
- name: 'fixture-paused-status',
553
- async run({ assert }) {
554
- const result = toUnifiedSubscription(FIXTURE_PAUSED);
555
- assert.equal(result.status, 'suspended', 'Paused fixture → suspended');
556
- },
557
- },
558
-
559
- {
560
- name: 'fixture-legacy-plan-resolves',
561
- async run({ assert }) {
562
- const result = toUnifiedSubscription(FIXTURE_LEGACY);
563
- assert.equal(result.product.id, 'pro', 'Legacy plan → pro via legacyPlanIds');
564
- assert.equal(result.payment.frequency, 'monthly', 'Legacy billing_period_unit month → monthly');
565
- assert.equal(result.payment.orderId, '1678790168794-0784', 'Legacy cf_clientorderid → orderId');
566
- assert.equal(result.status, 'active', 'Legacy active → active');
567
- },
568
- },
569
-
570
- {
571
- name: 'fixture-all-have-unified-shape',
572
- async run({ assert }) {
573
- const fixtures = [FIXTURE_ACTIVE, FIXTURE_CANCELLED, FIXTURE_TRIAL, FIXTURE_NON_RENEWING, FIXTURE_PAUSED, FIXTURE_LEGACY];
574
- const names = ['active', 'cancelled', 'trial', 'non-renewing', 'paused', 'legacy'];
575
-
576
- for (let i = 0; i < fixtures.length; i++) {
577
- const result = toUnifiedSubscription(fixtures[i]);
578
- const label = names[i];
579
-
580
- assert.ok(result.product, `${label}: should have product`);
581
- assert.ok(result.product.id, `${label}: should have product.id`);
582
- assert.ok(result.product.name, `${label}: should have product.name`);
583
- assert.isType(result.status, 'string', `${label}: status should be string`);
584
- assert.ok(result.expires, `${label}: should have expires`);
585
- assert.ok(result.trial, `${label}: should have trial`);
586
- assert.ok(result.cancellation, `${label}: should have cancellation`);
587
- assert.ok(result.payment, `${label}: should have payment`);
588
- assert.equal(result.payment.processor, 'chargebee', `${label}: processor should be chargebee`);
589
- assert.ok(result.payment.updatedBy, `${label}: should have updatedBy`);
590
- assert.ok(result.payment.updatedBy.date, `${label}: should have updatedBy.date`);
591
- }
592
- },
593
- },
594
-
595
- // ─── Combination / edge-case scenarios ───
596
-
597
- {
598
- name: 'combo-trial-with-non-renewing',
599
- async run({ assert }) {
600
- const now = Math.floor(Date.now() / 1000);
601
- const result = toUnifiedSubscription({
602
- id: 'sub_trial_cancel',
603
- status: 'non_renewing',
604
- trial_start: now - 86400 * 3,
605
- trial_end: now + 86400 * 11,
606
- current_term_end: now + 86400 * 11,
607
- started_at: now - 86400 * 3,
608
- subscription_items: [{ item_price_id: 'somiibo-pro-monthly' }],
609
- });
610
-
611
- assert.equal(result.status, 'active', 'Non-renewing + trial → still active');
612
- assert.equal(result.trial.claimed, true, 'Trial should be claimed');
613
- assert.equal(result.cancellation.pending, true, 'Cancel should be pending');
614
- },
615
- },
616
-
617
- {
618
- name: 'combo-meta-data-overrides-cf-fields',
619
- async run({ assert }) {
620
- const result = toUnifiedSubscription({
621
- meta_data: '{"uid":"new-uid","orderId":"new-order"}',
622
- cf_clientorderid: 'old-order',
623
- cf_uid: 'old-uid',
624
- });
625
-
626
- assert.equal(result.payment.orderId, 'new-order', 'meta_data orderId takes priority');
627
- assert.equal(Chargebee.getUid({
628
- meta_data: '{"uid":"new-uid"}',
629
- cf_uid: 'old-uid',
630
- }), 'new-uid', 'meta_data uid takes priority');
631
- },
632
- },
633
-
634
- {
635
- name: 'combo-items-model-overrides-legacy-plan',
636
- async run({ assert }) {
637
- const result = toUnifiedSubscription({
638
- subscription_items: [{ item_price_id: 'somiibo-plus-monthly' }],
639
- plan_id: 'somiibo-premium-monthly-1',
640
- billing_period_unit: 'year',
641
- });
642
-
643
- assert.equal(result.product.id, 'plus', 'Items model product takes priority over legacy');
644
- assert.equal(result.payment.frequency, 'monthly', 'Items model frequency takes priority over legacy billing_period_unit');
645
- },
646
- },
647
- ],
648
- };