backend-manager 5.0.102 → 5.0.104

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 (38) hide show
  1. package/CLAUDE.md +59 -0
  2. package/README.md +10 -0
  3. package/TODO-MARKETING.md +53 -0
  4. package/package.json +1 -1
  5. package/src/cli/commands/auth.js +226 -0
  6. package/src/cli/commands/firebase-init.js +121 -0
  7. package/src/cli/commands/firestore.js +261 -0
  8. package/src/cli/commands/index.js +2 -0
  9. package/src/cli/index.js +16 -0
  10. package/src/manager/libraries/payment-processors/stripe.js +37 -0
  11. package/src/manager/routes/payments/cancel/post.js +66 -0
  12. package/src/manager/routes/payments/cancel/processors/stripe.js +22 -0
  13. package/src/manager/routes/payments/cancel/processors/test.js +93 -0
  14. package/src/manager/routes/payments/intent/processors/stripe.js +1 -30
  15. package/src/manager/routes/payments/portal/post.js +54 -0
  16. package/src/manager/routes/payments/portal/processors/stripe.js +62 -0
  17. package/src/manager/routes/payments/portal/processors/test.js +18 -0
  18. package/src/manager/routes/user/delete.js +2 -1
  19. package/src/manager/schemas/payments/cancel/post.js +18 -0
  20. package/src/manager/schemas/payments/portal/post.js +10 -0
  21. package/src/test/runner.js +18 -1
  22. package/src/test/test-accounts.js +92 -0
  23. package/templates/firestore.rules +1 -0
  24. package/test/events/payments/journey-payments-cancel-endpoint.js +79 -0
  25. package/test/helpers/stripe-to-unified-one-time.js +304 -0
  26. package/test/routes/payments/cancel.js +124 -0
  27. package/test/routes/payments/intent.js +7 -14
  28. package/test/routes/payments/portal.js +89 -0
  29. package/src/manager/routes/forms/delete.js +0 -37
  30. package/src/manager/routes/forms/get.js +0 -46
  31. package/src/manager/routes/forms/post.js +0 -45
  32. package/src/manager/routes/forms/public/get.js +0 -37
  33. package/src/manager/routes/forms/put.js +0 -52
  34. package/src/manager/schemas/forms/delete.js +0 -6
  35. package/src/manager/schemas/forms/get.js +0 -6
  36. package/src/manager/schemas/forms/post.js +0 -9
  37. package/src/manager/schemas/forms/public/get.js +0 -6
  38. package/src/manager/schemas/forms/put.js +0 -10
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Test portal processor
3
+ * Returns a fake portal URL — no external API calls.
4
+ * Only available in non-production environments.
5
+ */
6
+ module.exports = {
7
+ async createPortalSession({ uid, returnUrl, assistant }) {
8
+ if (assistant.isProduction()) {
9
+ throw new Error('Test processor is not available in production');
10
+ }
11
+
12
+ const url = returnUrl || 'https://example.com/account';
13
+
14
+ assistant.log(`Test portal session: uid=${uid}, url=${url}`);
15
+
16
+ return { url };
17
+ },
18
+ };
@@ -79,7 +79,8 @@ module.exports = async ({ assistant, Manager, user, settings, libraries }) => {
79
79
  assistant.log(`Account deleted: ${uid}${reason ? `, reason: ${reason}` : ''}`);
80
80
 
81
81
  // Send confirmation email (fire-and-forget)
82
- if (email) {
82
+ const shouldSend = !assistant.isTesting() || process.env.TEST_EXTENDED_MODE;
83
+ if (email && shouldSend) {
83
84
  sendConfirmationEmail(assistant, email, reason);
84
85
  }
85
86
 
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Schema: POST /payments/cancel
3
+ * Validates subscription cancellation parameters
4
+ */
5
+ module.exports = () => ({
6
+ reason: {
7
+ types: ['string'],
8
+ default: null,
9
+ },
10
+ feedback: {
11
+ types: ['string'],
12
+ default: null,
13
+ },
14
+ confirmed: {
15
+ types: ['boolean'],
16
+ required: true,
17
+ },
18
+ });
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Schema: POST /payments/portal
3
+ * Validates billing portal session parameters
4
+ */
5
+ module.exports = () => ({
6
+ returnUrl: {
7
+ types: ['string'],
8
+ default: null,
9
+ },
10
+ });
@@ -1,5 +1,6 @@
1
1
  const os = require('os');
2
2
  const path = require('path');
3
+ const Module = require('module');
3
4
  const jetpack = require('fs-jetpack');
4
5
  const chalk = require('chalk');
5
6
 
@@ -369,7 +370,23 @@ class TestRunner {
369
370
  let testModule;
370
371
 
371
372
  try {
372
- testModule = require(testFile);
373
+ const searchPaths = [
374
+ path.join(this.options.projectDir, 'functions'),
375
+ path.resolve(__dirname, '../../'),
376
+ ];
377
+ const origResolve = Module._resolveFilename.bind(Module);
378
+ Module._resolveFilename = function (request, parent, isMain, options) {
379
+ if (!request.startsWith('.') && !path.isAbsolute(request)) {
380
+ const extra = (options && options.paths) ? options.paths : [];
381
+ options = { ...options, paths: [...extra, ...searchPaths] };
382
+ }
383
+ return origResolve(request, parent, isMain, options);
384
+ };
385
+ try {
386
+ testModule = require(testFile);
387
+ } finally {
388
+ Module._resolveFilename = origResolve;
389
+ }
373
390
  } catch (error) {
374
391
  console.log(chalk.red(` ✗ ${relativePath}`));
375
392
  console.log(chalk.red(` Failed to load: ${error.message}`));
@@ -193,6 +193,98 @@ const JOURNEY_ACCOUNTS = {
193
193
  subscription: { product: { id: 'basic' }, status: 'active' },
194
194
  },
195
195
  },
196
+ 'journey-payments-intent': {
197
+ id: 'journey-payments-intent',
198
+ uid: '_test-journey-payments-intent',
199
+ email: '_test.journey-payments-intent@{domain}',
200
+ properties: {
201
+ roles: {},
202
+ subscription: { product: { id: 'basic' }, status: 'active' },
203
+ },
204
+ },
205
+ 'journey-payments-cancel-route': {
206
+ id: 'journey-payments-cancel-route',
207
+ uid: '_test-journey-payments-cancel-route',
208
+ email: '_test.journey-payments-cancel-route@{domain}',
209
+ properties: {
210
+ roles: {},
211
+ subscription: { product: { id: 'basic' }, status: 'active' },
212
+ },
213
+ },
214
+ 'route-cancel-success': {
215
+ id: 'route-cancel-success',
216
+ uid: '_test-route-cancel-success',
217
+ email: '_test.route-cancel-success@{domain}',
218
+ properties: {
219
+ roles: {},
220
+ subscription: { product: { id: 'basic' }, status: 'active' },
221
+ },
222
+ },
223
+ 'journey-payments-portal-route': {
224
+ id: 'journey-payments-portal-route',
225
+ uid: '_test-journey-payments-portal-route',
226
+ email: '_test.journey-payments-portal-route@{domain}',
227
+ properties: {
228
+ roles: {},
229
+ subscription: { product: { id: 'basic' }, status: 'active' },
230
+ },
231
+ },
232
+ 'journey-payments-intent-trial': {
233
+ id: 'journey-payments-intent-trial',
234
+ uid: '_test-journey-payments-intent-trial',
235
+ email: '_test.journey-payments-intent-trial@{domain}',
236
+ properties: {
237
+ roles: {},
238
+ subscription: { product: { id: 'basic' }, status: 'active' },
239
+ },
240
+ },
241
+ // Dedicated accounts for cancel validation tests — each needs a distinct, non-conflicting subscription state
242
+ 'cancel-no-processor': {
243
+ id: 'cancel-no-processor',
244
+ uid: '_test-cancel-no-processor',
245
+ email: '_test.cancel-no-processor@{domain}',
246
+ properties: {
247
+ roles: {},
248
+ subscription: { product: { id: 'premium', name: 'Premium' }, status: 'active', expires: getFutureExpires(), cancellation: { pending: false }, payment: { processor: null, resourceId: null } },
249
+ },
250
+ },
251
+ 'cancel-already-pending': {
252
+ id: 'cancel-already-pending',
253
+ uid: '_test-cancel-already-pending',
254
+ email: '_test.cancel-already-pending@{domain}',
255
+ properties: {
256
+ roles: {},
257
+ subscription: { product: { id: 'premium', name: 'Premium' }, status: 'active', expires: getFutureExpires(), cancellation: { pending: true }, payment: { processor: 'stripe', resourceId: 'sub_test_fake' } },
258
+ },
259
+ },
260
+ 'cancel-unknown-processor': {
261
+ id: 'cancel-unknown-processor',
262
+ uid: '_test-cancel-unknown-processor',
263
+ email: '_test.cancel-unknown-processor@{domain}',
264
+ properties: {
265
+ roles: {},
266
+ subscription: { product: { id: 'premium', name: 'Premium' }, status: 'active', expires: getFutureExpires(), cancellation: { pending: false }, payment: { processor: 'unknown-processor', resourceId: 'sub_test_fake' } },
267
+ },
268
+ },
269
+ // Dedicated accounts for portal validation tests
270
+ 'portal-no-processor': {
271
+ id: 'portal-no-processor',
272
+ uid: '_test-portal-no-processor',
273
+ email: '_test.portal-no-processor@{domain}',
274
+ properties: {
275
+ roles: {},
276
+ subscription: { product: { id: 'premium', name: 'Premium' }, status: 'active', expires: getFutureExpires(), payment: { processor: null, resourceId: null } },
277
+ },
278
+ },
279
+ 'portal-unknown-processor': {
280
+ id: 'portal-unknown-processor',
281
+ uid: '_test-portal-unknown-processor',
282
+ email: '_test.portal-unknown-processor@{domain}',
283
+ properties: {
284
+ roles: {},
285
+ subscription: { product: { id: 'premium', name: 'Premium' }, status: 'active', expires: getFutureExpires(), payment: { processor: 'unknown-processor', resourceId: 'sub_test_fake' } },
286
+ },
287
+ },
196
288
  };
197
289
 
198
290
  /**
@@ -58,6 +58,7 @@ service cloud.firestore {
58
58
  return isWritingField('auth')
59
59
  || isWritingField('roles')
60
60
  || isWritingField('flags')
61
+ || isWritingField('plan') // REMOVE THIS WHEN ALL PROJECTS UPDATED
61
62
  || isWritingField('subscription')
62
63
  || isWritingField('affiliate')
63
64
  || isWritingField('api')
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Test: Payment Journey - Cancel via endpoint
3
+ * Simulates: paid active → POST /payments/cancel → cancellation pending
4
+ *
5
+ * The test processor's cancelAtPeriodEnd writes a Stripe-shaped webhook doc directly
6
+ * to payments-webhooks/{eventId}, triggering the full on-write pipeline automatically.
7
+ * Product-agnostic: resolves the first paid product from config.payment.products
8
+ */
9
+ module.exports = {
10
+ description: 'Payment journey: cancel endpoint → cancellation pending',
11
+ type: 'suite',
12
+ timeout: 30000,
13
+
14
+ tests: [
15
+ {
16
+ name: 'setup-paid-subscription',
17
+ async run({ accounts, firestore, assert, state, config, http, waitFor }) {
18
+ const uid = accounts['journey-payments-cancel-route'].uid;
19
+ const paidProduct = config.payment.products.find(p => p.id !== 'basic' && p.prices);
20
+ assert.ok(paidProduct, 'Config should have at least one paid product');
21
+
22
+ state.uid = uid;
23
+ state.paidProductId = paidProduct.id;
24
+
25
+ // Create subscription via test intent — auto-fires webhook pipeline
26
+ const response = await http.as('journey-payments-cancel-route').post('payments/intent', {
27
+ processor: 'test',
28
+ productId: paidProduct.id,
29
+ frequency: 'monthly',
30
+ });
31
+ assert.isSuccess(response, 'Intent should succeed');
32
+ state.orderId = response.data.orderId;
33
+
34
+ // Wait for subscription to activate
35
+ await waitFor(async () => {
36
+ const userDoc = await firestore.get(`users/${uid}`);
37
+ return userDoc?.subscription?.product?.id === paidProduct.id;
38
+ }, 15000, 500);
39
+
40
+ const userDoc = await firestore.get(`users/${uid}`);
41
+ assert.equal(userDoc.subscription?.product?.id, paidProduct.id, `Should be ${paidProduct.id}`);
42
+ assert.equal(userDoc.subscription?.status, 'active', 'Should be active');
43
+ assert.equal(userDoc.subscription?.cancellation?.pending, false, 'Should not be pending cancellation');
44
+ },
45
+ },
46
+
47
+ {
48
+ name: 'call-cancel-endpoint',
49
+ async run({ http, assert }) {
50
+ // Test processor writes a payments-webhooks doc directly,
51
+ // triggering the on-write pipeline automatically — no manual webhook needed
52
+ const response = await http.as('journey-payments-cancel-route').post('payments/cancel', {
53
+ confirmed: true,
54
+ reason: 'Too expensive',
55
+ feedback: 'Would return at a lower price',
56
+ });
57
+
58
+ assert.isSuccess(response, 'Cancel endpoint should succeed');
59
+ assert.equal(response.data.success, true, 'Should return { success: true }');
60
+ },
61
+ },
62
+
63
+ {
64
+ name: 'verify-cancellation-pending',
65
+ async run({ firestore, assert, state, waitFor }) {
66
+ // Poll user doc until the on-write pipeline updates subscription state
67
+ await waitFor(async () => {
68
+ const userDoc = await firestore.get(`users/${state.uid}`);
69
+ return userDoc?.subscription?.cancellation?.pending === true;
70
+ }, 15000, 500);
71
+
72
+ const userDoc = await firestore.get(`users/${state.uid}`);
73
+ assert.equal(userDoc.subscription.status, 'active', 'Status should still be active');
74
+ assert.equal(userDoc.subscription.cancellation.pending, true, 'Cancellation should be pending');
75
+ assert.ok(userDoc.subscription.cancellation.date.timestampUNIX > 0, 'Cancellation date should be set');
76
+ },
77
+ },
78
+ ],
79
+ };
@@ -0,0 +1,304 @@
1
+ /**
2
+ * Test: Stripe toUnifiedOneTime()
3
+ * Unit tests for the Stripe library's raw resource → unified one-time payment 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_SESSION = require('../fixtures/stripe/checkout-session-completed.json');
11
+ const FIXTURE_INVOICE_FAILED = require('../fixtures/stripe/invoice-payment-failed.json');
12
+
13
+ // Mock config matching the BEM template
14
+ const MOCK_CONFIG = {
15
+ payment: {
16
+ products: [
17
+ { id: 'basic', name: 'Basic', type: 'subscription', limits: { requests: 100 } },
18
+ {
19
+ id: 'credits-100', name: '100 Credits', type: 'one-time',
20
+ prices: { once: { amount: 9.99, stripe: 'price_credits_100' } },
21
+ },
22
+ {
23
+ id: 'credits-500', name: '500 Credits', type: 'one-time',
24
+ prices: { once: { amount: 39.99, stripe: 'price_credits_500' } },
25
+ },
26
+ ],
27
+ },
28
+ };
29
+
30
+ function toUnifiedOneTime(rawResource, options) {
31
+ return Stripe.toUnifiedOneTime(rawResource, { config: MOCK_CONFIG, ...options });
32
+ }
33
+
34
+ module.exports = {
35
+ description: 'Stripe toUnifiedOneTime() transformation',
36
+ type: 'group',
37
+
38
+ tests: [
39
+ // ─── Status passthrough ───
40
+
41
+ {
42
+ name: 'status-complete',
43
+ async run({ assert }) {
44
+ const result = toUnifiedOneTime({ status: 'complete' });
45
+ assert.equal(result.status, 'complete', 'Status passes through as-is');
46
+ },
47
+ },
48
+
49
+ {
50
+ name: 'status-open',
51
+ async run({ assert }) {
52
+ const result = toUnifiedOneTime({ status: 'open' });
53
+ assert.equal(result.status, 'open', 'Status passes through as-is');
54
+ },
55
+ },
56
+
57
+ {
58
+ name: 'status-unknown-when-missing',
59
+ async run({ assert }) {
60
+ const result = toUnifiedOneTime({});
61
+ assert.equal(result.status, 'unknown', 'Missing status → unknown');
62
+ },
63
+ },
64
+
65
+ // ─── Product resolution ───
66
+
67
+ {
68
+ name: 'product-resolves-from-metadata-product-id',
69
+ async run({ assert }) {
70
+ const result = toUnifiedOneTime({ metadata: { productId: 'credits-100' } });
71
+ assert.equal(result.product.id, 'credits-100', 'Should resolve from metadata.productId');
72
+ assert.equal(result.product.name, '100 Credits', 'Should have correct name');
73
+ },
74
+ },
75
+
76
+ {
77
+ name: 'product-resolves-second-product',
78
+ async run({ assert }) {
79
+ const result = toUnifiedOneTime({ metadata: { productId: 'credits-500' } });
80
+ assert.equal(result.product.id, 'credits-500', 'Should resolve credits-500');
81
+ assert.equal(result.product.name, '500 Credits', 'Should have correct name');
82
+ },
83
+ },
84
+
85
+ {
86
+ name: 'product-falls-back-to-unknown-on-missing-metadata',
87
+ async run({ assert }) {
88
+ const result = toUnifiedOneTime({});
89
+ assert.equal(result.product.id, 'unknown', 'No metadata → unknown');
90
+ assert.equal(result.product.name, 'Unknown', 'No metadata → Unknown name');
91
+ },
92
+ },
93
+
94
+ {
95
+ name: 'product-falls-back-to-product-id-on-unknown-product',
96
+ async run({ assert }) {
97
+ const result = toUnifiedOneTime({ metadata: { productId: 'nonexistent-product' } });
98
+ assert.equal(result.product.id, 'nonexistent-product', 'Unknown product → uses ID as-is');
99
+ },
100
+ },
101
+
102
+ {
103
+ name: 'product-without-config',
104
+ async run({ assert }) {
105
+ const result = Stripe.toUnifiedOneTime({ metadata: { productId: 'credits-100' } }, {});
106
+ assert.equal(result.product.id, 'credits-100', 'Without config → uses metadata ID');
107
+ // resolveProductOneTime returns { name: 'Unknown' } when config has no products array
108
+ assert.equal(result.product.name, 'Unknown', 'Without config → Unknown name');
109
+ },
110
+ },
111
+
112
+ // ─── Payment metadata ───
113
+
114
+ {
115
+ name: 'payment-processor-always-stripe',
116
+ async run({ assert }) {
117
+ const result = toUnifiedOneTime({});
118
+ assert.equal(result.payment.processor, 'stripe', 'Processor should always be stripe');
119
+ },
120
+ },
121
+
122
+ {
123
+ name: 'payment-resource-id-from-session-id',
124
+ async run({ assert }) {
125
+ const result = toUnifiedOneTime({ id: 'cs_test_abc123' });
126
+ assert.equal(result.payment.resourceId, 'cs_test_abc123', 'resourceId should be session/invoice ID');
127
+ },
128
+ },
129
+
130
+ {
131
+ name: 'payment-resource-id-null-when-missing',
132
+ async run({ assert }) {
133
+ const result = toUnifiedOneTime({});
134
+ assert.equal(result.payment.resourceId, null, 'Missing ID → null resourceId');
135
+ },
136
+ },
137
+
138
+ {
139
+ name: 'payment-order-id-from-metadata',
140
+ async run({ assert }) {
141
+ const result = toUnifiedOneTime({ metadata: { orderId: '1234-5678-9012' } });
142
+ assert.equal(result.payment.orderId, '1234-5678-9012', 'orderId should come from metadata');
143
+ },
144
+ },
145
+
146
+ {
147
+ name: 'payment-order-id-null-when-missing',
148
+ async run({ assert }) {
149
+ const result = toUnifiedOneTime({});
150
+ assert.equal(result.payment.orderId, null, 'Missing metadata → null orderId');
151
+ },
152
+ },
153
+
154
+ {
155
+ name: 'payment-price-resolves-from-config',
156
+ async run({ assert }) {
157
+ const result = toUnifiedOneTime({ metadata: { productId: 'credits-100' } });
158
+ assert.equal(result.payment.price, 9.99, 'Should resolve price from config');
159
+ },
160
+ },
161
+
162
+ {
163
+ name: 'payment-price-zero-on-unknown-product',
164
+ async run({ assert }) {
165
+ const result = toUnifiedOneTime({ metadata: { productId: 'nonexistent' } });
166
+ assert.equal(result.payment.price, 0, 'Unknown product → price 0');
167
+ },
168
+ },
169
+
170
+ {
171
+ name: 'payment-price-zero-when-no-metadata',
172
+ async run({ assert }) {
173
+ const result = toUnifiedOneTime({});
174
+ assert.equal(result.payment.price, 0, 'No metadata → price 0');
175
+ },
176
+ },
177
+
178
+ {
179
+ name: 'payment-event-metadata-passed-through',
180
+ async run({ assert }) {
181
+ const result = toUnifiedOneTime({}, { eventName: 'checkout.session.completed', eventId: 'evt_123' });
182
+ assert.equal(result.payment.updatedBy.event.name, 'checkout.session.completed', 'Event name passed through');
183
+ assert.equal(result.payment.updatedBy.event.id, 'evt_123', 'Event ID passed through');
184
+ },
185
+ },
186
+
187
+ {
188
+ name: 'payment-event-metadata-null-when-missing',
189
+ async run({ assert }) {
190
+ const result = toUnifiedOneTime({});
191
+ assert.equal(result.payment.updatedBy.event.name, null, 'Missing event name → null');
192
+ assert.equal(result.payment.updatedBy.event.id, null, 'Missing event ID → null');
193
+ },
194
+ },
195
+
196
+ // ─── Full unified shape ───
197
+
198
+ {
199
+ name: 'full-session-shape',
200
+ async run({ assert }) {
201
+ const result = toUnifiedOneTime({
202
+ id: 'cs_test_full',
203
+ status: 'complete',
204
+ metadata: { orderId: '1234-5678-9012', productId: 'credits-100' },
205
+ }, { eventName: 'checkout.session.completed', eventId: 'evt_full' });
206
+
207
+ assert.ok(result.product, 'Should have product');
208
+ assert.ok(result.status, 'Should have status');
209
+ assert.ok(result.payment, 'Should have payment');
210
+
211
+ assert.equal(result.product.id, 'credits-100', 'Product should be credits-100');
212
+ assert.equal(result.status, 'complete', 'Status should be complete');
213
+ assert.equal(result.payment.processor, 'stripe', 'Processor should be stripe');
214
+ assert.equal(result.payment.resourceId, 'cs_test_full', 'Resource ID should match');
215
+ assert.equal(result.payment.orderId, '1234-5678-9012', 'orderId should match');
216
+ assert.equal(result.payment.price, 9.99, 'Price should be resolved');
217
+ assert.equal(result.payment.updatedBy.event.name, 'checkout.session.completed', 'Event name should match');
218
+ },
219
+ },
220
+
221
+ {
222
+ name: 'empty-input-gets-safe-defaults',
223
+ async run({ assert }) {
224
+ const result = toUnifiedOneTime({});
225
+
226
+ assert.equal(result.product.id, 'unknown', 'Empty → unknown product');
227
+ assert.equal(result.status, 'unknown', 'Empty → unknown status');
228
+ assert.equal(result.payment.processor, 'stripe', 'Empty → still stripe');
229
+ assert.equal(result.payment.orderId, null, 'Empty → null orderId');
230
+ assert.equal(result.payment.resourceId, null, 'Empty → null resourceId');
231
+ assert.equal(result.payment.price, 0, 'Empty → price 0');
232
+ },
233
+ },
234
+
235
+ {
236
+ name: 'no-expires-or-trial-on-one-time',
237
+ async run({ assert }) {
238
+ const result = toUnifiedOneTime({ id: 'cs_test_shape' });
239
+ // One-time payments do not have subscription-specific fields
240
+ assert.equal(result.expires, undefined, 'No expires on one-time');
241
+ assert.equal(result.trial, undefined, 'No trial on one-time');
242
+ assert.equal(result.cancellation, undefined, 'No cancellation on one-time');
243
+ },
244
+ },
245
+
246
+ // ─── Real Stripe fixtures ───
247
+
248
+ {
249
+ name: 'fixture-session-completed-shape',
250
+ async run({ assert }) {
251
+ const result = toUnifiedOneTime(FIXTURE_SESSION);
252
+
253
+ assert.ok(result.product, 'Should have product');
254
+ assert.equal(result.status, 'complete', 'Real session fixture → complete');
255
+ assert.equal(result.payment.processor, 'stripe', 'Processor is stripe');
256
+ assert.equal(result.payment.resourceId, FIXTURE_SESSION.id, 'resourceId matches fixture ID');
257
+ },
258
+ },
259
+
260
+ {
261
+ name: 'fixture-session-completed-no-subscription-fields',
262
+ async run({ assert }) {
263
+ const result = toUnifiedOneTime(FIXTURE_SESSION);
264
+ assert.equal(result.expires, undefined, 'Session fixture has no expires');
265
+ assert.equal(result.trial, undefined, 'Session fixture has no trial');
266
+ assert.equal(result.cancellation, undefined, 'Session fixture has no cancellation');
267
+ },
268
+ },
269
+
270
+ {
271
+ name: 'fixture-invoice-failed-shape',
272
+ async run({ assert }) {
273
+ const result = toUnifiedOneTime(FIXTURE_INVOICE_FAILED);
274
+
275
+ assert.ok(result.product, 'Should have product');
276
+ assert.equal(result.status, 'open', 'Failed invoice fixture → open');
277
+ assert.equal(result.payment.processor, 'stripe', 'Processor is stripe');
278
+ assert.equal(result.payment.resourceId, FIXTURE_INVOICE_FAILED.id, 'resourceId matches fixture ID');
279
+ },
280
+ },
281
+
282
+ {
283
+ name: 'fixture-all-have-unified-shape',
284
+ async run({ assert }) {
285
+ const fixtures = [FIXTURE_SESSION, FIXTURE_INVOICE_FAILED];
286
+ const names = ['session-completed', 'invoice-failed'];
287
+
288
+ for (let i = 0; i < fixtures.length; i++) {
289
+ const result = toUnifiedOneTime(fixtures[i]);
290
+ const label = names[i];
291
+
292
+ assert.ok(result.product, `${label}: should have product`);
293
+ assert.ok(result.product.id, `${label}: should have product.id`);
294
+ assert.ok(result.product.name, `${label}: should have product.name`);
295
+ assert.isType(result.status, 'string', `${label}: status should be string`);
296
+ assert.ok(result.payment, `${label}: should have payment`);
297
+ assert.equal(result.payment.processor, 'stripe', `${label}: processor should be stripe`);
298
+ assert.ok(result.payment.updatedBy, `${label}: should have updatedBy`);
299
+ assert.ok(result.payment.updatedBy.date, `${label}: should have updatedBy.date`);
300
+ }
301
+ },
302
+ },
303
+ ],
304
+ };