backend-manager 5.9.4 → 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 (251) hide show
  1. package/CLAUDE.md +6 -0
  2. package/package.json +8 -1
  3. package/src/cli/commands/install.js +4 -3
  4. package/src/cli/commands/setup-tests/backend-manager.js +2 -1
  5. package/src/cli/commands/setup-tests/firebase-admin.js +2 -1
  6. package/src/cli/commands/setup-tests/firebase-functions.js +2 -1
  7. package/src/cli/utils/safe-install.js +13 -0
  8. package/src/manager/routes/payments/cancel/post.js +22 -2
  9. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/metadata.json +14 -0
  10. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/newsletter.html +486 -0
  11. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/newsletter.md +41 -0
  12. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/newsletter.mjml +97 -0
  13. package/{test/email/fixtures/clean.json → src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/structure.json} +16 -4
  14. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/summary.md +1 -0
  15. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/metadata.json +14 -0
  16. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/newsletter.html +486 -0
  17. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/newsletter.md +41 -0
  18. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/newsletter.mjml +97 -0
  19. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/structure.json +42 -0
  20. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/summary.md +1 -0
  21. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/metadata.json +14 -0
  22. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/newsletter.html +486 -0
  23. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/newsletter.md +41 -0
  24. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/newsletter.mjml +97 -0
  25. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/structure.json +42 -0
  26. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/summary.md +1 -0
  27. package/src/test/fixtures/firebase-project/.temp/test-mode.json +6 -0
  28. package/src/test/fixtures/firebase-project/database-debug.log +12 -0
  29. package/src/test/fixtures/firebase-project/firestore-debug.log +136 -0
  30. package/src/test/fixtures/firebase-project/pubsub-debug.log +17 -0
  31. package/src/test/test-accounts.js +9 -0
  32. package/.codeclimate.yml +0 -32
  33. package/.nvmrc +0 -1
  34. package/CHANGELOG.md +0 -1432
  35. package/PROGRESS.md +0 -86
  36. package/TODO-2.md +0 -121
  37. package/TODO-CHARGEBLAST.md +0 -32
  38. package/TODO-WEBHOOK-KEY-LEGACY-REMOVAL.md +0 -15
  39. package/TODO-WEBHOOK-KEY-UPGRADE.md +0 -138
  40. package/TODO-email-auth.md +0 -14
  41. package/TODO.md +0 -187
  42. package/plans/mcp2.md +0 -247
  43. package/scripts/test-helper-providers.js +0 -162
  44. package/scripts/update-disposable-domains.js +0 -44
  45. package/templates/_.env +0 -42
  46. package/templates/_.gitignore +0 -60
  47. package/templates/backend-manager-config.json +0 -249
  48. package/templates/database.rules.json +0 -83
  49. package/templates/firebase.json +0 -66
  50. package/templates/firestore.indexes.json +0 -4
  51. package/templates/firestore.rules +0 -112
  52. package/templates/public/404.html +0 -26
  53. package/templates/public/index.html +0 -24
  54. package/templates/remoteconfig.template.json +0 -1
  55. package/templates/storage-lifecycle-config-1-day.json +0 -9
  56. package/templates/storage-lifecycle-config-30-days.json +0 -9
  57. package/templates/storage.rules +0 -8
  58. package/test/_init/accounts-validation.js +0 -58
  59. package/test/_legacy/ai/index.js +0 -231
  60. package/test/_legacy/ai/test.jpg +0 -0
  61. package/test/_legacy/ai/test.pdf +0 -0
  62. package/test/_legacy/index.js +0 -31
  63. package/test/_legacy/payment-resolver/chargebee/orders/refunded.json +0 -0
  64. package/test/_legacy/payment-resolver/chargebee/orders/unpaid.json +0 -98
  65. package/test/_legacy/payment-resolver/chargebee/subscriptions/active.json +0 -578
  66. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-in-trial.json +0 -38
  67. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-skipped-to-active.json +0 -135
  68. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-active-to-cancelled.json +0 -42
  69. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-active.json +0 -44
  70. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-cancelled.json +0 -39
  71. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-refund.json +0 -143
  72. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-suspended.json +0 -48
  73. package/test/_legacy/payment-resolver/coinbase/orders/regular.json +0 -204
  74. package/test/_legacy/payment-resolver/coinbase/subscriptions/cancelled.json +0 -204
  75. package/test/_legacy/payment-resolver/coinbase/subscriptions/paid-2.json +0 -125
  76. package/test/_legacy/payment-resolver/index.js +0 -1558
  77. package/test/_legacy/payment-resolver/paypal/orders/refunded.json +0 -0
  78. package/test/_legacy/payment-resolver/paypal/orders/regular.json +0 -120
  79. package/test/_legacy/payment-resolver/paypal/subscriptions/active-refund-previous-stmnt.json +0 -323
  80. package/test/_legacy/payment-resolver/paypal/subscriptions/active.json +0 -192
  81. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-in-trial.json +0 -125
  82. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-not-complete.json +0 -76
  83. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-overdue-2.json +0 -114
  84. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-overdue.json +0 -114
  85. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-active-to-cancelled.json +0 -111
  86. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-active.json +0 -132
  87. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-cancelled.json +0 -107
  88. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-expired.json +0 -91
  89. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-refund.json +0 -147
  90. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-suspended.json +0 -120
  91. package/test/_legacy/payment-resolver/stripe/orders/refunded.json +0 -0
  92. package/test/_legacy/payment-resolver/stripe/orders/regular.json +0 -91
  93. package/test/_legacy/payment-resolver/stripe/subscriptions/active.json +0 -421
  94. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-in-trial.json +0 -349
  95. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-active-failed-authorization.json +0 -430
  96. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-active.json +0 -319
  97. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-cancelled.json +0 -319
  98. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-refund.json +0 -414
  99. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-suspended.json +0 -319
  100. package/test/_legacy/payment-resolver/stripe/subscriptions/unsure.json +0 -339
  101. package/test/_legacy/test-new +0 -1178
  102. package/test/_legacy/test.md +0 -89
  103. package/test/_legacy/usage.js +0 -175
  104. package/test/_legacy/user.js +0 -31
  105. package/test/ai/tools-live.js +0 -170
  106. package/test/boot/emulator-boots.js +0 -37
  107. package/test/content/blog-generate.js +0 -160
  108. package/test/email/campaign-send.js +0 -45
  109. package/test/email/consent-lifecycle.js +0 -257
  110. package/test/email/feedback-and-plain-send.js +0 -52
  111. package/test/email/fixtures/editorial.json +0 -30
  112. package/test/email/fixtures/field-report.json +0 -53
  113. package/test/email/marketing-lifecycle.js +0 -132
  114. package/test/email/newsletter-generate.js +0 -819
  115. package/test/email/newsletter-templates.js +0 -491
  116. package/test/email/templates.js +0 -207
  117. package/test/email/transactional-send.js +0 -34
  118. package/test/email/transactional.js +0 -560
  119. package/test/email/validation.js +0 -710
  120. package/test/events/auth-delete-race.js +0 -201
  121. package/test/events/payments/journey-payments-cancel-endpoint.js +0 -100
  122. package/test/events/payments/journey-payments-cancel.js +0 -182
  123. package/test/events/payments/journey-payments-discount.js +0 -89
  124. package/test/events/payments/journey-payments-failure.js +0 -146
  125. package/test/events/payments/journey-payments-legacy-product.js +0 -149
  126. package/test/events/payments/journey-payments-one-time-failure.js +0 -111
  127. package/test/events/payments/journey-payments-one-time.js +0 -136
  128. package/test/events/payments/journey-payments-plan-change.js +0 -144
  129. package/test/events/payments/journey-payments-refund-webhook.js +0 -180
  130. package/test/events/payments/journey-payments-suspend.js +0 -181
  131. package/test/events/payments/journey-payments-trial-cancel.js +0 -130
  132. package/test/events/payments/journey-payments-trial.js +0 -171
  133. package/test/events/payments/journey-payments-uid-resolution.js +0 -132
  134. package/test/events/payments/journey-payments-upgrade.js +0 -135
  135. package/test/fixtures/chargebee/invoice-one-time.json +0 -27
  136. package/test/fixtures/chargebee/subscription-active.json +0 -44
  137. package/test/fixtures/chargebee/subscription-cancelled.json +0 -42
  138. package/test/fixtures/chargebee/subscription-in-trial.json +0 -41
  139. package/test/fixtures/chargebee/subscription-legacy-plan.json +0 -41
  140. package/test/fixtures/chargebee/subscription-non-renewing.json +0 -41
  141. package/test/fixtures/chargebee/subscription-paused.json +0 -42
  142. package/test/fixtures/chargebee/webhook-payment-failed.json +0 -51
  143. package/test/fixtures/chargebee/webhook-subscription-created.json +0 -47
  144. package/test/fixtures/paypal/order-approved.json +0 -62
  145. package/test/fixtures/paypal/order-completed.json +0 -110
  146. package/test/fixtures/paypal/subscription-active.json +0 -76
  147. package/test/fixtures/paypal/subscription-cancelled.json +0 -50
  148. package/test/fixtures/paypal/subscription-suspended.json +0 -65
  149. package/test/fixtures/stripe/checkout-session-completed.json +0 -130
  150. package/test/fixtures/stripe/invoice-payment-failed.json +0 -148
  151. package/test/fixtures/stripe/invoice-subscription-payment-failed.json +0 -28
  152. package/test/fixtures/stripe/subscription-active.json +0 -161
  153. package/test/fixtures/stripe/subscription-canceled.json +0 -161
  154. package/test/fixtures/stripe/subscription-trialing.json +0 -161
  155. package/test/functions/admin/database-read.js +0 -134
  156. package/test/functions/admin/database-write.js +0 -159
  157. package/test/functions/admin/edit-post.js +0 -366
  158. package/test/functions/admin/firestore-query.js +0 -207
  159. package/test/functions/admin/firestore-read.js +0 -129
  160. package/test/functions/admin/firestore-write.js +0 -105
  161. package/test/functions/admin/get-stats.js +0 -115
  162. package/test/functions/admin/send-email.js +0 -119
  163. package/test/functions/admin/send-notification.js +0 -208
  164. package/test/functions/admin/write-repo-content.js +0 -223
  165. package/test/functions/general/add-marketing-contact.js +0 -335
  166. package/test/functions/general/fetch-post.js +0 -54
  167. package/test/functions/general/generate-uuid.js +0 -114
  168. package/test/functions/test/authenticate.js +0 -64
  169. package/test/functions/user/create-custom-token.js +0 -73
  170. package/test/functions/user/delete.js +0 -135
  171. package/test/functions/user/get-active-sessions.js +0 -111
  172. package/test/functions/user/get-subscription-info.js +0 -99
  173. package/test/functions/user/regenerate-api-keys.js +0 -156
  174. package/test/functions/user/resolve.js +0 -52
  175. package/test/functions/user/sign-out-all-sessions.js +0 -94
  176. package/test/functions/user/sign-up.js +0 -252
  177. package/test/functions/user/submit-feedback.js +0 -104
  178. package/test/functions/user/validate-settings.js +0 -82
  179. package/test/helpers/ai-request-payload.js +0 -300
  180. package/test/helpers/ai-test-provider.js +0 -202
  181. package/test/helpers/ai-tools-format.js +0 -383
  182. package/test/helpers/content/blog-auto-publisher.js +0 -484
  183. package/test/helpers/content/feed-parser.js +0 -528
  184. package/test/helpers/content/ghostii-blocks.js +0 -134
  185. package/test/helpers/content/ghostii-feed-integration.js +0 -404
  186. package/test/helpers/content/ghostii-write-article.js +0 -243
  187. package/test/helpers/environment.js +0 -230
  188. package/test/helpers/infer-contact.js +0 -113
  189. package/test/helpers/merge-line-files.js +0 -271
  190. package/test/helpers/payment/chargebee/parse-webhook.js +0 -413
  191. package/test/helpers/payment/chargebee/to-unified-one-time.js +0 -147
  192. package/test/helpers/payment/chargebee/to-unified-subscription.js +0 -648
  193. package/test/helpers/payment/paypal/parse-webhook.js +0 -539
  194. package/test/helpers/payment/paypal/to-unified-one-time.js +0 -382
  195. package/test/helpers/payment/paypal/to-unified-subscription.js +0 -820
  196. package/test/helpers/payment/stripe/parse-webhook.js +0 -447
  197. package/test/helpers/payment/stripe/to-unified-one-time.js +0 -306
  198. package/test/helpers/payment/stripe/to-unified-subscription.js +0 -708
  199. package/test/helpers/sanitize.js +0 -222
  200. package/test/helpers/slugify.js +0 -394
  201. package/test/helpers/storage.js +0 -194
  202. package/test/helpers/user.js +0 -755
  203. package/test/helpers/webhook-forward.js +0 -418
  204. package/test/mcp/discovery.js +0 -53
  205. package/test/mcp/oauth.js +0 -161
  206. package/test/mcp/protocol.js +0 -268
  207. package/test/mcp/roles.js +0 -188
  208. package/test/mcp/utils.js +0 -245
  209. package/test/routes/admin/create-post.js +0 -364
  210. package/test/routes/admin/database.js +0 -131
  211. package/test/routes/admin/deduplicate-image-alts.js +0 -190
  212. package/test/routes/admin/email.js +0 -114
  213. package/test/routes/admin/firestore-query.js +0 -204
  214. package/test/routes/admin/firestore.js +0 -127
  215. package/test/routes/admin/infer-contact.js +0 -218
  216. package/test/routes/admin/notification.js +0 -198
  217. package/test/routes/admin/post-resize-image.js +0 -184
  218. package/test/routes/admin/post.js +0 -368
  219. package/test/routes/admin/repo-content.js +0 -223
  220. package/test/routes/admin/stats.js +0 -112
  221. package/test/routes/content/post.js +0 -54
  222. package/test/routes/general/uuid.js +0 -115
  223. package/test/routes/marketing/campaign.js +0 -125
  224. package/test/routes/marketing/contact.js +0 -370
  225. package/test/routes/marketing/email-preferences.js +0 -292
  226. package/test/routes/marketing/push-send.js +0 -32
  227. package/test/routes/marketing/webhook-forward.js +0 -61
  228. package/test/routes/marketing/webhook.js +0 -639
  229. package/test/routes/payments/cancel.js +0 -140
  230. package/test/routes/payments/discount.js +0 -80
  231. package/test/routes/payments/dispute-alert.js +0 -320
  232. package/test/routes/payments/intent.js +0 -336
  233. package/test/routes/payments/portal.js +0 -92
  234. package/test/routes/payments/refund.js +0 -179
  235. package/test/routes/payments/trial-eligibility.js +0 -71
  236. package/test/routes/payments/webhook.js +0 -107
  237. package/test/routes/test/authenticate.js +0 -59
  238. package/test/routes/test/schema.js +0 -554
  239. package/test/routes/test/usage.js +0 -342
  240. package/test/routes/user/api-keys.js +0 -156
  241. package/test/routes/user/delete.js +0 -136
  242. package/test/routes/user/feedback.js +0 -104
  243. package/test/routes/user/sessions.js +0 -199
  244. package/test/routes/user/settings-validate.js +0 -82
  245. package/test/routes/user/signup.js +0 -542
  246. package/test/routes/user/subscription.js +0 -99
  247. package/test/routes/user/token.js +0 -73
  248. package/test/routes/user/user.js +0 -157
  249. package/test/rules/notifications.js +0 -410
  250. package/test/rules/payments-carts.js +0 -371
  251. package/test/rules/user.js +0 -396
@@ -1,820 +0,0 @@
1
- /**
2
- * Test: PayPal toUnifiedSubscription()
3
- * Unit tests for the PayPal library's raw subscription → unified subscription transformation
4
- *
5
- * Tests the pure function directly — no emulator, no Firestore, no HTTP
6
- * Mirrors stripe/to-unified-subscription.js for consistent coverage
7
- */
8
- const PayPal = require('../../../../src/manager/libraries/payment/processors/paypal.js');
9
-
10
- // Real PayPal sandbox fixtures
11
- const FIXTURE_ACTIVE = require('../../../fixtures/paypal/subscription-active.json');
12
- const FIXTURE_CANCELLED = require('../../../fixtures/paypal/subscription-cancelled.json');
13
- const FIXTURE_SUSPENDED = require('../../../fixtures/paypal/subscription-suspended.json');
14
-
15
- // Mock config matching the BEM template (new flat price structure)
16
- const MOCK_CONFIG = {
17
- payment: {
18
- products: [
19
- { id: 'basic', name: 'Basic', type: 'subscription', limits: { requests: 100 } },
20
- {
21
- id: 'plus', name: 'Plus', type: 'subscription',
22
- prices: { monthly: 9.99, annually: 99.99 },
23
- paypal: { productId: 'PROD-plus' },
24
- },
25
- {
26
- id: 'pro', name: 'Pro', type: 'subscription',
27
- prices: { monthly: 29.99, annually: 299.99 },
28
- paypal: { productId: 'PROD-pro' },
29
- },
30
- ],
31
- },
32
- };
33
-
34
- function toUnifiedSubscription(rawSubscription, options) {
35
- return PayPal.toUnifiedSubscription(rawSubscription, { config: MOCK_CONFIG, ...options });
36
- }
37
-
38
- module.exports = {
39
- description: 'PayPal toUnifiedSubscription() transformation',
40
- type: 'group',
41
-
42
- tests: [
43
- // ─── Status mapping ───
44
-
45
- {
46
- name: 'status-active',
47
- async run({ assert }) {
48
- const result = toUnifiedSubscription({ status: 'ACTIVE' });
49
- assert.equal(result.status, 'active', 'PayPal ACTIVE → unified active');
50
- },
51
- },
52
-
53
- {
54
- name: 'status-approved',
55
- async run({ assert }) {
56
- const result = toUnifiedSubscription({ status: 'APPROVED' });
57
- assert.equal(result.status, 'active', 'PayPal APPROVED → unified active');
58
- },
59
- },
60
-
61
- {
62
- name: 'status-suspended',
63
- async run({ assert }) {
64
- const result = toUnifiedSubscription({ status: 'SUSPENDED' });
65
- assert.equal(result.status, 'suspended', 'PayPal SUSPENDED → unified suspended');
66
- },
67
- },
68
-
69
- {
70
- name: 'status-cancelled',
71
- async run({ assert }) {
72
- const result = toUnifiedSubscription({ status: 'CANCELLED' });
73
- assert.equal(result.status, 'cancelled', 'PayPal CANCELLED → unified cancelled');
74
- },
75
- },
76
-
77
- {
78
- name: 'status-expired',
79
- async run({ assert }) {
80
- const result = toUnifiedSubscription({ status: 'EXPIRED' });
81
- assert.equal(result.status, 'cancelled', 'PayPal EXPIRED → unified cancelled');
82
- },
83
- },
84
-
85
- {
86
- name: 'status-approval-pending',
87
- async run({ assert }) {
88
- const result = toUnifiedSubscription({ status: 'APPROVAL_PENDING' });
89
- assert.equal(result.status, 'cancelled', 'PayPal APPROVAL_PENDING → unified cancelled');
90
- },
91
- },
92
-
93
- {
94
- name: 'status-unknown-defaults-to-cancelled',
95
- async run({ assert }) {
96
- const result = toUnifiedSubscription({ status: 'SOME_FUTURE_STATUS' });
97
- assert.equal(result.status, 'cancelled', 'Unknown status → cancelled');
98
- },
99
- },
100
-
101
- // ─── Product resolution ───
102
-
103
- {
104
- name: 'product-resolves-from-plan-product-id',
105
- async run({ assert }) {
106
- const result = toUnifiedSubscription({
107
- _plan: { product_id: 'PROD-plus' },
108
- });
109
- assert.equal(result.product.id, 'plus', 'Should resolve to plus');
110
- assert.equal(result.product.name, 'Plus', 'Should have correct name');
111
- },
112
- },
113
-
114
- {
115
- name: 'product-resolves-pro-from-plan-product-id',
116
- async run({ assert }) {
117
- const result = toUnifiedSubscription({
118
- _plan: { product_id: 'PROD-pro' },
119
- });
120
- assert.equal(result.product.id, 'pro', 'Should resolve to pro');
121
- assert.equal(result.product.name, 'Pro', 'Should have correct name');
122
- },
123
- },
124
-
125
- {
126
- name: 'product-falls-back-to-basic-on-unknown-product',
127
- async run({ assert }) {
128
- const result = toUnifiedSubscription({
129
- _plan: { product_id: 'PROD-nonexistent' },
130
- });
131
- assert.equal(result.product.id, 'basic', 'Unknown product → basic');
132
- assert.equal(result.product.name, 'Basic', 'Unknown product → Basic name');
133
- },
134
- },
135
-
136
- {
137
- name: 'product-falls-back-to-basic-on-missing-plan',
138
- async run({ assert }) {
139
- const result = toUnifiedSubscription({});
140
- assert.equal(result.product.id, 'basic', 'No _plan → basic');
141
- },
142
- },
143
-
144
- {
145
- name: 'product-falls-back-to-basic-without-config',
146
- async run({ assert }) {
147
- const result = PayPal.toUnifiedSubscription(
148
- { _plan: { product_id: 'PROD-plus' } },
149
- {},
150
- );
151
- assert.equal(result.product.id, 'basic', 'No config → basic');
152
- },
153
- },
154
-
155
- // ─── Frequency resolution ───
156
-
157
- {
158
- name: 'frequency-month-from-plan',
159
- async run({ assert }) {
160
- const result = toUnifiedSubscription({
161
- _plan: {
162
- billing_cycles: [
163
- { tenure_type: 'REGULAR', frequency: { interval_unit: 'MONTH', interval_count: 1 } },
164
- ],
165
- },
166
- });
167
- assert.equal(result.payment.frequency, 'monthly', 'MONTH → monthly');
168
- },
169
- },
170
-
171
- {
172
- name: 'frequency-year-from-plan',
173
- async run({ assert }) {
174
- const result = toUnifiedSubscription({
175
- _plan: {
176
- billing_cycles: [
177
- { tenure_type: 'REGULAR', frequency: { interval_unit: 'YEAR', interval_count: 1 } },
178
- ],
179
- },
180
- });
181
- assert.equal(result.payment.frequency, 'annually', 'YEAR → annually');
182
- },
183
- },
184
-
185
- {
186
- name: 'frequency-week-from-plan',
187
- async run({ assert }) {
188
- const result = toUnifiedSubscription({
189
- _plan: {
190
- billing_cycles: [
191
- { tenure_type: 'REGULAR', frequency: { interval_unit: 'WEEK', interval_count: 1 } },
192
- ],
193
- },
194
- });
195
- assert.equal(result.payment.frequency, 'weekly', 'WEEK → weekly');
196
- },
197
- },
198
-
199
- {
200
- name: 'frequency-day-from-plan',
201
- async run({ assert }) {
202
- const result = toUnifiedSubscription({
203
- _plan: {
204
- billing_cycles: [
205
- { tenure_type: 'REGULAR', frequency: { interval_unit: 'DAY', interval_count: 1 } },
206
- ],
207
- },
208
- });
209
- assert.equal(result.payment.frequency, 'daily', 'DAY → daily');
210
- },
211
- },
212
-
213
- {
214
- name: 'frequency-null-when-missing',
215
- async run({ assert }) {
216
- const result = toUnifiedSubscription({});
217
- assert.equal(result.payment.frequency, null, 'Missing plan → null');
218
- },
219
- },
220
-
221
- {
222
- name: 'frequency-from-inline-plan',
223
- async run({ assert }) {
224
- // PayPal ?fields=plan returns plan inline
225
- const result = toUnifiedSubscription({
226
- plan: {
227
- billing_cycles: [
228
- { tenure_type: 'REGULAR', frequency: { interval_unit: 'YEAR', interval_count: 1 } },
229
- ],
230
- },
231
- });
232
- assert.equal(result.payment.frequency, 'annually', 'Inline plan year → annually');
233
- },
234
- },
235
-
236
- {
237
- name: 'frequency-prefers-plan-over-inline',
238
- async run({ assert }) {
239
- const result = toUnifiedSubscription({
240
- _plan: {
241
- billing_cycles: [
242
- { tenure_type: 'REGULAR', frequency: { interval_unit: 'MONTH', interval_count: 1 } },
243
- ],
244
- },
245
- plan: {
246
- billing_cycles: [
247
- { tenure_type: 'REGULAR', frequency: { interval_unit: 'YEAR', interval_count: 1 } },
248
- ],
249
- },
250
- });
251
- assert.equal(result.payment.frequency, 'monthly', '_plan takes priority over inline plan');
252
- },
253
- },
254
-
255
- // ─── Trial resolution ───
256
-
257
- {
258
- name: 'trial-claimed-when-plan-has-trial-cycle',
259
- async run({ assert }) {
260
- const result = toUnifiedSubscription({
261
- start_time: '2024-01-01T00:00:00Z',
262
- _plan: {
263
- billing_cycles: [
264
- {
265
- tenure_type: 'TRIAL',
266
- frequency: { interval_unit: 'DAY', interval_count: 1 },
267
- total_cycles: 14,
268
- },
269
- {
270
- tenure_type: 'REGULAR',
271
- frequency: { interval_unit: 'MONTH', interval_count: 1 },
272
- },
273
- ],
274
- },
275
- });
276
- assert.equal(result.trial.claimed, true, 'Plan with trial cycle → claimed');
277
- assert.ok(result.trial.expires.timestampUNIX > 0, 'Trial expires should be set');
278
- },
279
- },
280
-
281
- {
282
- name: 'trial-not-claimed-when-no-trial-cycle',
283
- async run({ assert }) {
284
- const result = toUnifiedSubscription({
285
- _plan: {
286
- billing_cycles: [
287
- {
288
- tenure_type: 'REGULAR',
289
- frequency: { interval_unit: 'MONTH', interval_count: 1 },
290
- },
291
- ],
292
- },
293
- });
294
- assert.equal(result.trial.claimed, false, 'No trial cycle → not claimed');
295
- },
296
- },
297
-
298
- {
299
- name: 'trial-not-claimed-when-no-plan',
300
- async run({ assert }) {
301
- const result = toUnifiedSubscription({});
302
- assert.equal(result.trial.claimed, false, 'No plan → not claimed');
303
- },
304
- },
305
-
306
- {
307
- name: 'trial-claimed-with-no-start-time-has-epoch-expiry',
308
- async run({ assert }) {
309
- const result = toUnifiedSubscription({
310
- _plan: {
311
- billing_cycles: [
312
- {
313
- tenure_type: 'TRIAL',
314
- frequency: { interval_unit: 'DAY', interval_count: 1 },
315
- total_cycles: 7,
316
- },
317
- ],
318
- },
319
- });
320
- assert.equal(result.trial.claimed, true, 'Trial cycle exists → claimed');
321
- assert.equal(result.trial.expires.timestampUNIX, 0, 'No start_time → epoch expiry');
322
- },
323
- },
324
-
325
- {
326
- name: 'trial-month-based-cycle',
327
- async run({ assert }) {
328
- const result = toUnifiedSubscription({
329
- start_time: '2024-01-01T00:00:00Z',
330
- _plan: {
331
- billing_cycles: [
332
- {
333
- tenure_type: 'TRIAL',
334
- frequency: { interval_unit: 'MONTH', interval_count: 1 },
335
- total_cycles: 1,
336
- },
337
- ],
338
- },
339
- });
340
- assert.equal(result.trial.claimed, true, 'Monthly trial → claimed');
341
- assert.ok(result.trial.expires.timestampUNIX > 0, 'Should have computed trial end');
342
- },
343
- },
344
-
345
- // ─── Cancellation resolution ───
346
-
347
- {
348
- name: 'cancellation-when-status-cancelled',
349
- async run({ assert }) {
350
- const result = toUnifiedSubscription({
351
- status: 'CANCELLED',
352
- status_update_time: '2024-06-15T12:00:00Z',
353
- });
354
- assert.equal(result.cancellation.pending, false, 'Already cancelled → not pending');
355
- assert.ok(result.cancellation.date.timestampUNIX > 0, 'Should have cancellation date');
356
- },
357
- },
358
-
359
- {
360
- name: 'cancellation-cancelled-no-update-time',
361
- async run({ assert }) {
362
- const result = toUnifiedSubscription({
363
- status: 'CANCELLED',
364
- });
365
- assert.equal(result.cancellation.pending, false, 'Already cancelled → not pending');
366
- assert.equal(result.cancellation.date.timestampUNIX, 0, 'No update time → epoch');
367
- },
368
- },
369
-
370
- {
371
- name: 'cancellation-none-when-active',
372
- async run({ assert }) {
373
- const result = toUnifiedSubscription({
374
- status: 'ACTIVE',
375
- });
376
- assert.equal(result.cancellation.pending, false, 'Active → not pending');
377
- assert.equal(result.cancellation.date.timestampUNIX, 0, 'No cancellation date');
378
- },
379
- },
380
-
381
- // ─── Expiration resolution ───
382
-
383
- {
384
- name: 'expires-from-next-billing-time',
385
- async run({ assert }) {
386
- const result = toUnifiedSubscription({
387
- billing_info: { next_billing_time: '2024-07-01T00:00:00Z' },
388
- });
389
- assert.ok(result.expires.timestampUNIX > 0, 'Should have expiration');
390
- },
391
- },
392
-
393
- {
394
- name: 'expires-defaults-to-epoch-when-missing',
395
- async run({ assert }) {
396
- const result = toUnifiedSubscription({});
397
- assert.equal(result.expires.timestampUNIX, 0, 'Missing billing_info → epoch');
398
- },
399
- },
400
-
401
- // ─── Start date resolution ───
402
-
403
- {
404
- name: 'start-date-from-start-time',
405
- async run({ assert }) {
406
- const result = toUnifiedSubscription({ start_time: '2024-01-15T00:00:00Z' });
407
- assert.ok(result.payment.startDate.timestampUNIX > 0, 'Should have start date from start_time');
408
- },
409
- },
410
-
411
- {
412
- name: 'start-date-from-create-time-fallback',
413
- async run({ assert }) {
414
- const result = toUnifiedSubscription({ create_time: '2024-01-10T00:00:00Z' });
415
- assert.ok(result.payment.startDate.timestampUNIX > 0, 'Should have start date from create_time');
416
- },
417
- },
418
-
419
- {
420
- name: 'start-date-defaults-to-epoch-when-missing',
421
- async run({ assert }) {
422
- const result = toUnifiedSubscription({});
423
- assert.equal(result.payment.startDate.timestampUNIX, 0, 'Missing start_time → epoch');
424
- },
425
- },
426
-
427
- // ─── Payment metadata ───
428
-
429
- {
430
- name: 'payment-processor-always-paypal',
431
- async run({ assert }) {
432
- const result = toUnifiedSubscription({});
433
- assert.equal(result.payment.processor, 'paypal', 'Processor should always be paypal');
434
- },
435
- },
436
-
437
- {
438
- name: 'payment-resource-id-from-subscription-id',
439
- async run({ assert }) {
440
- const result = toUnifiedSubscription({ id: 'I-ABC123' });
441
- assert.equal(result.payment.resourceId, 'I-ABC123', 'resourceId should be subscription ID');
442
- },
443
- },
444
-
445
- {
446
- name: 'payment-resource-id-null-when-missing',
447
- async run({ assert }) {
448
- const result = toUnifiedSubscription({});
449
- assert.equal(result.payment.resourceId, null, 'Missing ID → null resourceId');
450
- },
451
- },
452
-
453
- {
454
- name: 'payment-order-id-from-custom-id',
455
- async run({ assert }) {
456
- const result = toUnifiedSubscription({ custom_id: 'uid:user-abc,orderId:1234-5678' });
457
- assert.equal(result.payment.orderId, '1234-5678', 'orderId should come from custom_id');
458
- },
459
- },
460
-
461
- {
462
- name: 'payment-order-id-null-when-missing',
463
- async run({ assert }) {
464
- const result = toUnifiedSubscription({});
465
- assert.equal(result.payment.orderId, null, 'Missing custom_id → null orderId');
466
- },
467
- },
468
-
469
- {
470
- name: 'payment-event-metadata-passed-through',
471
- async run({ assert }) {
472
- const result = toUnifiedSubscription({}, { eventName: 'BILLING.SUBSCRIPTION.ACTIVATED', eventId: 'WH-123' });
473
- assert.equal(result.payment.updatedBy.event.name, 'BILLING.SUBSCRIPTION.ACTIVATED', 'Event name passed through');
474
- assert.equal(result.payment.updatedBy.event.id, 'WH-123', 'Event ID passed through');
475
- },
476
- },
477
-
478
- {
479
- name: 'payment-event-metadata-null-when-missing',
480
- async run({ assert }) {
481
- const result = toUnifiedSubscription({});
482
- assert.equal(result.payment.updatedBy.event.name, null, 'Missing event name → null');
483
- assert.equal(result.payment.updatedBy.event.id, null, 'Missing event ID → null');
484
- },
485
- },
486
-
487
- // ─── Price resolution ───
488
-
489
- {
490
- name: 'price-resolves-from-config',
491
- async run({ assert }) {
492
- const result = toUnifiedSubscription({
493
- _plan: {
494
- product_id: 'PROD-plus',
495
- billing_cycles: [
496
- { tenure_type: 'REGULAR', frequency: { interval_unit: 'MONTH', interval_count: 1 } },
497
- ],
498
- },
499
- });
500
- assert.equal(result.payment.price, 9.99, 'Price should match config for plus/monthly');
501
- },
502
- },
503
-
504
- {
505
- name: 'price-resolves-annually',
506
- async run({ assert }) {
507
- const result = toUnifiedSubscription({
508
- _plan: {
509
- product_id: 'PROD-pro',
510
- billing_cycles: [
511
- { tenure_type: 'REGULAR', frequency: { interval_unit: 'YEAR', interval_count: 1 } },
512
- ],
513
- },
514
- });
515
- assert.equal(result.payment.price, 299.99, 'Price should match config for pro/annually');
516
- },
517
- },
518
-
519
- {
520
- name: 'price-zero-when-product-unknown',
521
- async run({ assert }) {
522
- const result = toUnifiedSubscription({
523
- _plan: { product_id: 'PROD-nonexistent' },
524
- });
525
- assert.equal(result.payment.price, 0, 'Unknown product → price 0');
526
- },
527
- },
528
-
529
- // ─── Custom ID parsing ───
530
-
531
- {
532
- name: 'custom-id-parses-uid-and-order-id',
533
- async run({ assert }) {
534
- const result = toUnifiedSubscription({
535
- custom_id: 'uid:user-123,orderId:ord-456',
536
- });
537
- assert.equal(result.payment.orderId, 'ord-456', 'orderId from custom_id');
538
- },
539
- },
540
-
541
- {
542
- name: 'custom-id-handles-colons-in-values',
543
- async run({ assert }) {
544
- const result = toUnifiedSubscription({
545
- custom_id: 'uid:user:with:colons,orderId:ord-789',
546
- });
547
- assert.equal(result.payment.orderId, 'ord-789', 'orderId parsed correctly');
548
- },
549
- },
550
-
551
- {
552
- name: 'custom-id-handles-empty-string',
553
- async run({ assert }) {
554
- const result = toUnifiedSubscription({ custom_id: '' });
555
- assert.equal(result.payment.orderId, null, 'Empty custom_id → null');
556
- },
557
- },
558
-
559
- // ─── Full unified shape ───
560
-
561
- {
562
- name: 'full-active-subscription-shape',
563
- async run({ assert }) {
564
- const result = toUnifiedSubscription({
565
- id: 'I-FULL-TEST',
566
- status: 'ACTIVE',
567
- custom_id: 'uid:user-full,orderId:ord-full',
568
- start_time: '2024-01-01T00:00:00Z',
569
- billing_info: { next_billing_time: '2024-02-01T00:00:00Z' },
570
- _plan: {
571
- product_id: 'PROD-pro',
572
- billing_cycles: [
573
- { tenure_type: 'REGULAR', frequency: { interval_unit: 'MONTH', interval_count: 1 } },
574
- ],
575
- },
576
- }, { eventName: 'BILLING.SUBSCRIPTION.ACTIVATED', eventId: 'WH-FULL' });
577
-
578
- // Verify all top-level keys exist
579
- assert.ok(result.product, 'Should have product');
580
- assert.ok(result.status, 'Should have status');
581
- assert.ok(result.expires, 'Should have expires');
582
- assert.ok(result.trial, 'Should have trial');
583
- assert.ok(result.cancellation, 'Should have cancellation');
584
- assert.ok(result.payment, 'Should have payment');
585
-
586
- // Verify values
587
- assert.equal(result.product.id, 'pro', 'Product should be pro');
588
- assert.equal(result.status, 'active', 'Status should be active');
589
- assert.equal(result.trial.claimed, false, 'Trial should not be claimed');
590
- assert.equal(result.cancellation.pending, false, 'Should not be pending cancellation');
591
- assert.equal(result.payment.processor, 'paypal', 'Processor should be paypal');
592
- assert.equal(result.payment.resourceId, 'I-FULL-TEST', 'Resource ID should match');
593
- assert.equal(result.payment.frequency, 'monthly', 'Frequency should be monthly');
594
- assert.equal(result.payment.orderId, 'ord-full', 'Order ID should match');
595
- assert.equal(result.payment.updatedBy.event.name, 'BILLING.SUBSCRIPTION.ACTIVATED', 'Event name should match');
596
- },
597
- },
598
-
599
- {
600
- name: 'empty-subscription-gets-safe-defaults',
601
- async run({ assert }) {
602
- const result = toUnifiedSubscription({});
603
-
604
- assert.equal(result.product.id, 'basic', 'Empty → basic product');
605
- assert.equal(result.status, 'cancelled', 'Empty → cancelled (no status field)');
606
- assert.equal(result.trial.claimed, false, 'Empty → trial not claimed');
607
- assert.equal(result.cancellation.pending, false, 'Empty → not pending');
608
- assert.equal(result.payment.processor, 'paypal', 'Empty → still paypal');
609
- assert.equal(result.payment.orderId, null, 'Empty → null orderId');
610
- assert.equal(result.payment.resourceId, null, 'Empty → null resourceId');
611
- assert.equal(result.payment.frequency, null, 'Empty → null frequency');
612
- },
613
- },
614
-
615
- // ─── Combination / edge-case scenarios ───
616
-
617
- {
618
- name: 'combo-active-with-trial',
619
- async run({ assert }) {
620
- const result = toUnifiedSubscription({
621
- id: 'I-TRIAL-ACTIVE',
622
- status: 'ACTIVE',
623
- start_time: '2024-01-01T00:00:00Z',
624
- _plan: {
625
- product_id: 'PROD-plus',
626
- billing_cycles: [
627
- {
628
- tenure_type: 'TRIAL',
629
- frequency: { interval_unit: 'DAY', interval_count: 1 },
630
- total_cycles: 14,
631
- },
632
- {
633
- tenure_type: 'REGULAR',
634
- frequency: { interval_unit: 'MONTH', interval_count: 1 },
635
- },
636
- ],
637
- },
638
- });
639
-
640
- assert.equal(result.status, 'active', 'Active with trial → active');
641
- assert.equal(result.trial.claimed, true, 'Trial should be claimed');
642
- assert.equal(result.product.id, 'plus', 'Should resolve product');
643
- assert.equal(result.payment.frequency, 'monthly', 'Regular cycle → monthly');
644
- },
645
- },
646
-
647
- {
648
- name: 'combo-suspended-subscription',
649
- async run({ assert }) {
650
- const result = toUnifiedSubscription({
651
- id: 'I-SUSPENDED',
652
- status: 'SUSPENDED',
653
- custom_id: 'uid:user-sus,orderId:ord-sus',
654
- _plan: {
655
- product_id: 'PROD-pro',
656
- billing_cycles: [
657
- { tenure_type: 'REGULAR', frequency: { interval_unit: 'YEAR', interval_count: 1 } },
658
- ],
659
- },
660
- });
661
-
662
- assert.equal(result.status, 'suspended', 'SUSPENDED → suspended');
663
- assert.equal(result.product.id, 'pro', 'Should resolve product');
664
- assert.equal(result.payment.frequency, 'annually', 'Year → annually');
665
- assert.equal(result.cancellation.pending, false, 'Not cancelled, just suspended');
666
- },
667
- },
668
-
669
- {
670
- name: 'combo-cancelled-with-update-time',
671
- async run({ assert }) {
672
- const result = toUnifiedSubscription({
673
- id: 'I-CANCEL',
674
- status: 'CANCELLED',
675
- status_update_time: '2024-06-15T18:30:00Z',
676
- custom_id: 'uid:user-cancel,orderId:ord-cancel',
677
- _plan: {
678
- product_id: 'PROD-plus',
679
- billing_cycles: [
680
- { tenure_type: 'REGULAR', frequency: { interval_unit: 'MONTH', interval_count: 1 } },
681
- ],
682
- },
683
- });
684
-
685
- assert.equal(result.status, 'cancelled', 'CANCELLED → cancelled');
686
- assert.equal(result.cancellation.pending, false, 'Already cancelled → not pending');
687
- assert.ok(result.cancellation.date.timestampUNIX > 0, 'Should have cancellation date');
688
- assert.equal(result.payment.orderId, 'ord-cancel', 'Order ID preserved');
689
- },
690
- },
691
-
692
- {
693
- name: 'combo-expired-subscription',
694
- async run({ assert }) {
695
- const result = toUnifiedSubscription({
696
- id: 'I-EXPIRED',
697
- status: 'EXPIRED',
698
- _plan: {
699
- product_id: 'PROD-pro',
700
- billing_cycles: [
701
- { tenure_type: 'REGULAR', frequency: { interval_unit: 'MONTH', interval_count: 1 } },
702
- ],
703
- },
704
- });
705
-
706
- assert.equal(result.status, 'cancelled', 'EXPIRED → cancelled');
707
- assert.equal(result.product.id, 'pro', 'Should still resolve product');
708
- },
709
- },
710
-
711
- // ─── Unified shape matches Stripe output ───
712
-
713
- {
714
- name: 'shape-matches-stripe-output-keys',
715
- async run({ assert }) {
716
- const result = toUnifiedSubscription({
717
- id: 'I-SHAPE',
718
- status: 'ACTIVE',
719
- custom_id: 'uid:u1,orderId:o1',
720
- start_time: '2024-01-01T00:00:00Z',
721
- billing_info: { next_billing_time: '2024-02-01T00:00:00Z' },
722
- _plan: {
723
- product_id: 'PROD-plus',
724
- billing_cycles: [
725
- { tenure_type: 'REGULAR', frequency: { interval_unit: 'MONTH', interval_count: 1 } },
726
- ],
727
- },
728
- });
729
-
730
- // Top-level keys
731
- const topKeys = Object.keys(result).sort();
732
- assert.deepEqual(topKeys, ['cancellation', 'expires', 'payment', 'product', 'status', 'trial'], 'Should have same top-level keys as Stripe unified');
733
-
734
- // Product shape
735
- assert.ok(result.product.id, 'product.id exists');
736
- assert.ok(result.product.name, 'product.name exists');
737
-
738
- // Expires shape
739
- assert.isType(result.expires.timestamp, 'string', 'expires.timestamp is string');
740
- assert.isType(result.expires.timestampUNIX, 'number', 'expires.timestampUNIX is number');
741
-
742
- // Trial shape
743
- assert.isType(result.trial.claimed, 'boolean', 'trial.claimed is boolean');
744
- assert.ok(result.trial.expires, 'trial.expires exists');
745
-
746
- // Cancellation shape
747
- assert.isType(result.cancellation.pending, 'boolean', 'cancellation.pending is boolean');
748
- assert.ok(result.cancellation.date, 'cancellation.date exists');
749
-
750
- // Payment shape
751
- assert.equal(result.payment.processor, 'paypal', 'payment.processor');
752
- assert.ok('orderId' in result.payment, 'payment.orderId exists');
753
- assert.ok('resourceId' in result.payment, 'payment.resourceId exists');
754
- assert.ok('frequency' in result.payment, 'payment.frequency exists');
755
- assert.ok('price' in result.payment, 'payment.price exists');
756
- assert.ok(result.payment.startDate, 'payment.startDate exists');
757
- assert.ok(result.payment.updatedBy, 'payment.updatedBy exists');
758
- assert.ok(result.payment.updatedBy.event, 'payment.updatedBy.event exists');
759
- assert.ok(result.payment.updatedBy.date, 'payment.updatedBy.date exists');
760
- },
761
- },
762
-
763
- // ─── Real PayPal sandbox fixtures ───
764
-
765
- {
766
- name: 'fixture-active-produces-valid-shape',
767
- async run({ assert }) {
768
- const result = toUnifiedSubscription(FIXTURE_ACTIVE);
769
-
770
- assert.equal(result.status, 'active', 'ACTIVE fixture → active');
771
- assert.equal(result.payment.processor, 'paypal', 'Processor is paypal');
772
- assert.equal(result.payment.resourceId, 'I-MTPRX0B9LV4R', 'Resource ID from fixture');
773
- assert.equal(result.payment.orderId, 'ord-sub-123', 'orderId from custom_id');
774
- assert.isType(result.expires.timestamp, 'string', 'expires.timestamp is string');
775
- assert.isType(result.expires.timestampUNIX, 'number', 'expires.timestampUNIX is number');
776
- assert.equal(result.trial.claimed, false, 'No trial in fixture');
777
- assert.equal(result.cancellation.pending, false, 'Not cancelled');
778
- },
779
- },
780
-
781
- {
782
- name: 'fixture-cancelled-produces-valid-shape',
783
- async run({ assert }) {
784
- const result = toUnifiedSubscription(FIXTURE_CANCELLED);
785
-
786
- assert.equal(result.status, 'cancelled', 'CANCELLED fixture → cancelled');
787
- assert.equal(result.payment.resourceId, 'I-MTPRX0B9LV4R', 'Resource ID from fixture');
788
- assert.equal(result.payment.orderId, 'ord-sub-123', 'orderId from custom_id');
789
- assert.equal(result.cancellation.pending, false, 'Already cancelled');
790
- },
791
- },
792
-
793
- {
794
- name: 'fixture-suspended-produces-valid-shape',
795
- async run({ assert }) {
796
- const result = toUnifiedSubscription(FIXTURE_SUSPENDED);
797
-
798
- assert.equal(result.status, 'suspended', 'SUSPENDED fixture → suspended');
799
- assert.equal(result.payment.resourceId, 'I-MTPRX0B9LV4R', 'Resource ID from fixture');
800
- assert.equal(result.cancellation.pending, false, 'Not cancelled, just suspended');
801
- },
802
- },
803
-
804
- {
805
- name: 'fixture-all-produce-valid-unified-keys',
806
- async run({ assert }) {
807
- const fixtures = [FIXTURE_ACTIVE, FIXTURE_CANCELLED, FIXTURE_SUSPENDED];
808
- const expectedKeys = ['cancellation', 'expires', 'payment', 'product', 'status', 'trial'];
809
-
810
- for (let i = 0; i < fixtures.length; i++) {
811
- const result = toUnifiedSubscription(fixtures[i]);
812
- const keys = Object.keys(result).sort();
813
- assert.deepEqual(keys, expectedKeys, `Fixture ${i} should have correct top-level keys`);
814
- assert.isType(result.payment.updatedBy.date.timestamp, 'string', `Fixture ${i}: updatedBy.date.timestamp is string`);
815
- assert.isType(result.payment.updatedBy.date.timestampUNIX, 'number', `Fixture ${i}: updatedBy.date.timestampUNIX is number`);
816
- }
817
- },
818
- },
819
- ],
820
- };