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