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,201 +0,0 @@
1
- const uuid = require('uuid');
2
-
3
- /**
4
- * Test: auth:on-delete race condition
5
- *
6
- * Proves the emulator's async on-delete trigger clobbers freshly-recreated docs
7
- * when you don't wait for it to settle, and that the mitigation strategies work.
8
- *
9
- * The production fix uses the emulator's bulk-clear REST API in deleteTestUsers()
10
- * to avoid triggering on-delete at all during test setup.
11
- */
12
- module.exports = {
13
- description: 'auth:on-delete race condition (create → delete → recreate)',
14
- type: 'group',
15
- timeout: 120000,
16
-
17
- tests: [
18
- {
19
- name: 'baseline-create-and-verify',
20
- async run({ Manager, assert }) {
21
- const admin = Manager.libraries.admin;
22
- const testUid = '_test-race-baseline';
23
- const testEmail = '_test.race-baseline@test.com';
24
- const userRef = admin.firestore().doc(`users/${testUid}`);
25
-
26
- await admin.auth().deleteUser(testUid).catch(() => {});
27
- await pollUntilGone(userRef);
28
-
29
- await admin.auth().createUser({
30
- uid: testUid,
31
- email: testEmail,
32
- password: uuid.v4(),
33
- emailVerified: true,
34
- });
35
-
36
- const ready = await pollUntilReady(userRef);
37
- assert.ok(ready, 'on-create should complete and write api keys');
38
-
39
- const doc = await userRef.get();
40
- assert.ok(doc.data()?.api?.clientId, 'doc should have api.clientId');
41
- assert.ok(doc.data()?.api?.privateKey, 'doc should have api.privateKey');
42
-
43
- await admin.auth().deleteUser(testUid).catch(() => {});
44
- await pollUntilGone(userRef);
45
- },
46
- },
47
-
48
- {
49
- name: 'no-wait-gets-clobbered',
50
- async run({ Manager, assert }) {
51
- const admin = Manager.libraries.admin;
52
- const testUid = '_test-race-no-wait';
53
- const testEmail = '_test.race-no-wait@test.com';
54
- const userRef = admin.firestore().doc(`users/${testUid}`);
55
-
56
- await admin.auth().deleteUser(testUid).catch(() => {});
57
- await pollUntilGone(userRef);
58
-
59
- // Create and wait for doc to be fully ready
60
- await admin.auth().createUser({
61
- uid: testUid, email: testEmail,
62
- password: uuid.v4(), emailVerified: true,
63
- });
64
- assert.ok(await pollUntilReady(userRef), 'First create should produce api keys');
65
-
66
- // Delete auth user — do NOT wait for doc to disappear — then recreate
67
- await admin.auth().deleteUser(testUid);
68
- await admin.auth().createUser({
69
- uid: testUid, email: testEmail,
70
- password: uuid.v4(), emailVerified: true,
71
- });
72
- await pollUntilReady(userRef);
73
-
74
- // The late on-delete clobbers the doc within a few seconds
75
- await sleep(3000);
76
- const doc = await userRef.get();
77
- const survived = doc.exists && !!(doc.data()?.api?.clientId);
78
-
79
- assert.ok(!survived, 'Doc should be clobbered by late on-delete (proves the race exists)');
80
-
81
- await admin.auth().deleteUser(testUid).catch(() => {});
82
- await pollUntilGone(userRef);
83
- },
84
- },
85
-
86
- {
87
- name: 'wait-for-gone-survives',
88
- async run({ Manager, assert }) {
89
- const admin = Manager.libraries.admin;
90
- const testUid = '_test-race-wait-gone';
91
- const testEmail = '_test.race-wait-gone@test.com';
92
- const userRef = admin.firestore().doc(`users/${testUid}`);
93
-
94
- await admin.auth().deleteUser(testUid).catch(() => {});
95
- await pollUntilGone(userRef);
96
-
97
- await admin.auth().createUser({
98
- uid: testUid, email: testEmail,
99
- password: uuid.v4(), emailVerified: true,
100
- });
101
- assert.ok(await pollUntilReady(userRef), 'First create should produce api keys');
102
-
103
- // Delete and WAIT for doc to disappear before recreating
104
- await admin.auth().deleteUser(testUid);
105
- await pollUntilGone(userRef);
106
-
107
- await admin.auth().createUser({
108
- uid: testUid, email: testEmail,
109
- password: uuid.v4(), emailVerified: true,
110
- });
111
- assert.ok(await pollUntilReady(userRef), 'Second create should produce api keys');
112
-
113
- await sleep(3000);
114
- const doc = await userRef.get();
115
- const survived = doc.exists && !!(doc.data()?.api?.clientId);
116
-
117
- assert.ok(survived, 'Doc should survive when we wait for on-delete to settle first');
118
-
119
- await admin.auth().deleteUser(testUid).catch(() => {});
120
- await pollUntilGone(userRef);
121
- },
122
- },
123
-
124
- {
125
- name: 'force-delete-doc-survives',
126
- async run({ Manager, assert }) {
127
- const admin = Manager.libraries.admin;
128
- const testUid = '_test-race-force-del';
129
- const testEmail = '_test.race-force-del@test.com';
130
- const userRef = admin.firestore().doc(`users/${testUid}`);
131
-
132
- await admin.auth().deleteUser(testUid).catch(() => {});
133
- await pollUntilGone(userRef);
134
-
135
- await admin.auth().createUser({
136
- uid: testUid, email: testEmail,
137
- password: uuid.v4(), emailVerified: true,
138
- });
139
- assert.ok(await pollUntilReady(userRef), 'First create should produce api keys');
140
-
141
- // Delete auth user AND force-delete the Firestore doc, then pause
142
- await admin.auth().deleteUser(testUid);
143
- await userRef.delete().catch(() => {});
144
- await sleep(500);
145
-
146
- await admin.auth().createUser({
147
- uid: testUid, email: testEmail,
148
- password: uuid.v4(), emailVerified: true,
149
- });
150
- assert.ok(await pollUntilReady(userRef), 'Second create should produce api keys');
151
-
152
- await sleep(3000);
153
- const doc = await userRef.get();
154
- const survived = doc.exists && !!(doc.data()?.api?.clientId);
155
-
156
- assert.ok(survived, 'Doc should survive when we force-delete the doc before recreating');
157
-
158
- await admin.auth().deleteUser(testUid).catch(() => {});
159
- await pollUntilGone(userRef);
160
- },
161
- },
162
- ],
163
- };
164
-
165
- function sleep(ms) {
166
- return new Promise(resolve => setTimeout(resolve, ms));
167
- }
168
-
169
- async function pollUntilReady(userRef, maxWait = 15000) {
170
- const interval = 300;
171
- let waited = 0;
172
-
173
- while (waited < maxWait) {
174
- const doc = await userRef.get();
175
- const data = doc.exists ? doc.data() : null;
176
- if (data?.metadata?.tag === 'auth:on-create' && data.api?.clientId && data.api?.privateKey) {
177
- return true;
178
- }
179
- await sleep(interval);
180
- waited += interval;
181
- }
182
-
183
- return false;
184
- }
185
-
186
- async function pollUntilGone(userRef, maxWait = 10000) {
187
- const interval = 200;
188
- let waited = 0;
189
-
190
- while (waited < maxWait) {
191
- const doc = await userRef.get();
192
- if (!doc.exists) {
193
- return true;
194
- }
195
- await sleep(interval);
196
- waited += interval;
197
- }
198
-
199
- await userRef.delete().catch(() => {});
200
- return false;
201
- }
@@ -1,100 +0,0 @@
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, skip, payments }) {
18
- const uid = accounts['journey-payments-cancel-route'].uid;
19
- // Resolve first paid product from config. If the brand has none configured,
20
- // skip the entire journey — this is a config-gap, not a code failure.
21
- const paidProduct = config.payment.products.find(p => p.id !== 'basic' && p.prices);
22
- if (!paidProduct) {
23
- skip('No paid product configured in this brand');
24
- }
25
-
26
- state.uid = uid;
27
- state.paidProductId = paidProduct.id;
28
- state.product = payments.products[paidProduct.id];
29
- // Create subscription via test intent — auto-fires webhook pipeline
30
- const response = await http.as('journey-payments-cancel-route').post('backend-manager/payments/intent', {
31
- processor: 'test',
32
- productId: paidProduct.id,
33
- frequency: state.product.frequency,
34
- });
35
- assert.isSuccess(response, 'Intent should succeed');
36
- state.orderId = response.data.orderId;
37
-
38
- // Wait for subscription to activate
39
- await waitFor(async () => {
40
- const userDoc = await firestore.get(`users/${uid}`);
41
- return userDoc?.subscription?.product?.id === paidProduct.id;
42
- }, 15000, 500);
43
-
44
- const userDoc = await firestore.get(`users/${uid}`);
45
- assert.equal(userDoc.subscription?.product?.id, paidProduct.id, `Should be ${paidProduct.id}`);
46
- assert.equal(userDoc.subscription?.status, 'active', 'Should be active');
47
- assert.equal(userDoc.subscription?.cancellation?.pending, false, 'Should not be pending cancellation');
48
- },
49
- },
50
-
51
- {
52
- name: 'call-cancel-endpoint',
53
- async run({ http, assert }) {
54
- // Test processor writes a payments-webhooks doc directly,
55
- // triggering the on-write pipeline automatically — no manual webhook needed.
56
- // skipGuards bypasses the 24-hour subscription-age guard.
57
- const response = await http.as('journey-payments-cancel-route').post('backend-manager/payments/cancel', {
58
- confirmed: true,
59
- reason: 'Too expensive',
60
- feedback: 'Would return at a lower price',
61
- skipGuards: true,
62
- });
63
-
64
- assert.isSuccess(response, 'Cancel endpoint should succeed');
65
- assert.equal(response.data.success, true, 'Should return { success: true }');
66
- },
67
- },
68
-
69
- {
70
- name: 'verify-cancellation-pending',
71
- async run({ firestore, assert, state, waitFor }) {
72
- // Poll user doc until the on-write pipeline updates subscription state
73
- await waitFor(async () => {
74
- const userDoc = await firestore.get(`users/${state.uid}`);
75
- return userDoc?.subscription?.cancellation?.pending === true;
76
- }, 15000, 500);
77
-
78
- const userDoc = await firestore.get(`users/${state.uid}`);
79
- assert.equal(userDoc.subscription.status, 'active', 'Status should still be active');
80
- assert.equal(userDoc.subscription.cancellation.pending, true, 'Cancellation should be pending');
81
- assert.ok(userDoc.subscription.cancellation.date.timestampUNIX > 0, 'Cancellation date should be set');
82
- },
83
- },
84
-
85
- {
86
- name: 'cancellation-request-stored',
87
- async run({ firestore, assert, state }) {
88
- const orderDoc = await firestore.get(`payments-orders/${state.orderId}`);
89
-
90
- assert.ok(orderDoc, 'Order doc should exist');
91
- assert.ok(orderDoc.requests, 'requests field should exist');
92
- assert.ok(orderDoc.requests.cancellation, 'requests.cancellation should be populated');
93
- assert.equal(orderDoc.requests.cancellation.reason, 'Too expensive', 'Cancellation reason should match');
94
- assert.equal(orderDoc.requests.cancellation.feedback, 'Would return at a lower price', 'Cancellation feedback should match');
95
- assert.ok(orderDoc.requests.cancellation.date.timestampUNIX > 0, 'Cancellation date should be set');
96
- assert.equal(orderDoc.requests.refund, null, 'requests.refund should still be null');
97
- },
98
- },
99
- ],
100
- };
@@ -1,182 +0,0 @@
1
- /**
2
- * Test: Payment Journey - Cancel
3
- * Simulates: paid active → pending cancel → cancelled
4
- *
5
- * Uses test intent for initial subscription, then manual webhooks for cancel flow
6
- * Product-agnostic: resolves the first paid product from config.payment.products
7
- */
8
- module.exports = {
9
- description: 'Payment journey: paid → pending cancel → cancelled',
10
- type: 'suite',
11
- timeout: 30000,
12
-
13
- tests: [
14
- {
15
- name: 'setup-paid-subscription',
16
- async run({ accounts, firestore, assert, state, config, http, waitFor, skip, payments }) {
17
- const uid = accounts['journey-payments-cancel'].uid;
18
-
19
- // Resolve first paid product from config. If the brand has none configured,
20
- // skip the entire journey — this is a config-gap, not a code failure.
21
- const paidProduct = config.payment.products.find(p => p.id !== 'basic' && p.prices);
22
- if (!paidProduct) {
23
- skip('No paid product configured in this brand');
24
- }
25
-
26
- state.uid = uid;
27
- state.paidProductId = paidProduct.id;
28
- state.product = payments.products[paidProduct.id];
29
-
30
- state.paidProductName = paidProduct.name;
31
-
32
- // Create subscription via test intent
33
- const response = await http.as('journey-payments-cancel').post('backend-manager/payments/intent', {
34
- processor: 'test',
35
- productId: paidProduct.id,
36
- frequency: state.product.frequency,
37
- });
38
- assert.isSuccess(response, 'Intent should succeed');
39
- state.orderId = response.data.orderId;
40
-
41
- // Wait for subscription to activate
42
- await waitFor(async () => {
43
- const userDoc = await firestore.get(`users/${uid}`);
44
- return userDoc?.subscription?.product?.id === paidProduct.id;
45
- }, 15000, 500);
46
-
47
- const userDoc = await firestore.get(`users/${uid}`);
48
- assert.equal(userDoc.subscription?.product?.id, paidProduct.id, `Should start as ${paidProduct.id}`);
49
- assert.equal(userDoc.subscription?.status, 'active', 'Should be active');
50
- assert.equal(userDoc.subscription?.payment?.orderId, state.orderId, 'Order ID should match intent');
51
-
52
- state.subscriptionId = userDoc.subscription.payment.resourceId;
53
- },
54
- },
55
-
56
- {
57
- name: 'send-pending-cancel-webhook',
58
- async run({ http, assert, state, config, payments }) {
59
- const futureDate = new Date();
60
- futureDate.setFullYear(futureDate.getFullYear() + 1);
61
-
62
- state.eventId1 = `_test-evt-journey-cancel-pending-${Date.now()}`;
63
-
64
- const response = await http.as('none').post(`backend-manager/payments/webhook?processor=test&key=${config.backendManagerWebhookKey}`, {
65
- id: state.eventId1,
66
- type: 'customer.subscription.updated',
67
- data: {
68
- object: {
69
- id: state.subscriptionId,
70
- object: 'subscription',
71
- status: 'active',
72
- metadata: { uid: state.uid, orderId: state.orderId },
73
- cancel_at_period_end: true,
74
- cancel_at: Math.floor(futureDate.getTime() / 1000),
75
- canceled_at: null,
76
- current_period_end: Math.floor(futureDate.getTime() / 1000),
77
- current_period_start: Math.floor(Date.now() / 1000),
78
- start_date: Math.floor(Date.now() / 1000) - 86400 * 30,
79
- trial_start: null,
80
- trial_end: null,
81
- plan: { product: payments.stripeProductIds[state.paidProductId], interval: state.product.interval },
82
- },
83
- },
84
- });
85
-
86
- assert.isSuccess(response, 'Webhook should be accepted');
87
- },
88
- },
89
-
90
- {
91
- name: 'pending-cancel-processed',
92
- async run({ firestore, assert, state, waitFor }) {
93
- await waitFor(async () => {
94
- const doc = await firestore.get(`payments-webhooks/${state.eventId1}`);
95
- return doc?.status === 'completed';
96
- }, 15000, 500);
97
-
98
- const webhookDoc = await firestore.get(`payments-webhooks/${state.eventId1}`);
99
- assert.equal(webhookDoc.transition, 'cancellation-requested', 'Transition should be cancellation-requested');
100
-
101
- const userDoc = await firestore.get(`users/${state.uid}`);
102
-
103
- assert.equal(userDoc.subscription.status, 'active', 'Status should still be active');
104
- assert.equal(userDoc.subscription.cancellation.pending, true, 'Cancellation should be pending');
105
- },
106
- },
107
-
108
- {
109
- name: 'send-cancelled-webhook',
110
- async run({ http, assert, state, config, payments }) {
111
- state.eventId2 = `_test-evt-journey-cancel-final-${Date.now()}`;
112
-
113
- const response = await http.as('none').post(`backend-manager/payments/webhook?processor=test&key=${config.backendManagerWebhookKey}`, {
114
- id: state.eventId2,
115
- type: 'customer.subscription.deleted',
116
- data: {
117
- object: {
118
- id: state.subscriptionId,
119
- object: 'subscription',
120
- status: 'canceled',
121
- metadata: { uid: state.uid, orderId: state.orderId },
122
- cancel_at_period_end: false,
123
- canceled_at: Math.floor(Date.now() / 1000),
124
- current_period_end: Math.floor(Date.now() / 1000),
125
- current_period_start: Math.floor(Date.now() / 1000) - 86400 * 30,
126
- start_date: Math.floor(Date.now() / 1000) - 86400 * 60,
127
- trial_start: null,
128
- trial_end: null,
129
- plan: { product: payments.stripeProductIds[state.paidProductId], interval: state.product.interval },
130
- },
131
- },
132
- });
133
-
134
- assert.isSuccess(response, 'Webhook should be accepted');
135
- },
136
- },
137
-
138
- {
139
- name: 'subscription-cancelled',
140
- async run({ firestore, assert, state, waitFor }) {
141
- await waitFor(async () => {
142
- const doc = await firestore.get(`payments-webhooks/${state.eventId2}`);
143
- return doc?.status === 'completed';
144
- }, 15000, 500);
145
-
146
- const webhookDoc = await firestore.get(`payments-webhooks/${state.eventId2}`);
147
- assert.equal(webhookDoc.transition, 'subscription-cancelled', 'Transition should be subscription-cancelled');
148
-
149
- const userDoc = await firestore.get(`users/${state.uid}`);
150
-
151
- assert.equal(userDoc.subscription.status, 'cancelled', 'Status should be cancelled');
152
- assert.equal(userDoc.subscription.cancellation.pending, false, 'Cancellation should not be pending');
153
- },
154
- },
155
-
156
- {
157
- name: 'order-doc-verified',
158
- async run({ firestore, assert, state }) {
159
- const orderDoc = await firestore.get(`payments-orders/${state.orderId}`);
160
-
161
- assert.ok(orderDoc, 'Order doc should exist');
162
- assert.equal(orderDoc.type, 'subscription', 'Type should be subscription');
163
- assert.equal(orderDoc.owner, state.uid, 'Owner should match');
164
- assert.ok(orderDoc.requests !== undefined, 'requests field should exist');
165
- assert.equal(orderDoc.requests.cancellation, null, 'requests.cancellation should be null (cancel was via webhook, not endpoint)');
166
- assert.equal(orderDoc.requests.refund, null, 'requests.refund should be null');
167
- },
168
- },
169
-
170
- {
171
- name: 'intent-doc-completed',
172
- async run({ firestore, assert, state }) {
173
- const intentDoc = await firestore.get(`payments-intents/${state.orderId}`);
174
-
175
- assert.ok(intentDoc, 'Intent doc should exist');
176
- assert.equal(intentDoc.id, state.orderId, 'ID should match orderId');
177
- assert.equal(intentDoc.status, 'completed', 'Intent status should be completed after webhook processing');
178
- assert.ok(intentDoc.metadata?.completed?.timestampUNIX > 0, 'Completed timestamp should be set');
179
- },
180
- },
181
- ],
182
- };
@@ -1,89 +0,0 @@
1
- /**
2
- * Test: Payment Journey - Subscription with Discount
3
- * Simulates: basic → paid subscription with WELCOME15 promo code → confirmation email with discount
4
- *
5
- * Verifies the discount flows through: intent → order → transition → email template
6
- * Product-agnostic: resolves the first paid product from config.payment.products
7
- */
8
- module.exports = {
9
- description: 'Payment journey: subscription with discount code',
10
- type: 'suite',
11
- timeout: 30000,
12
-
13
- tests: [
14
- {
15
- name: 'setup',
16
- async run({ accounts, firestore, assert, state, config, skip, payments }) {
17
- const uid = accounts['journey-payments-intent-discount'].uid;
18
- const userDoc = await firestore.get(`users/${uid}`);
19
-
20
- assert.ok(userDoc, 'User doc should exist');
21
- assert.equal(userDoc.subscription?.product?.id, 'basic', 'Should start as basic');
22
-
23
- const paidProduct = config.payment.products.find(p => p.id !== 'basic' && p.prices && p.type === 'subscription');
24
- if (!paidProduct) {
25
- skip('No paid subscription product configured');
26
- }
27
-
28
- state.uid = uid;
29
- state.paidProductId = paidProduct.id;
30
- state.product = payments.products[paidProduct.id];
31
- },
32
- },
33
-
34
- {
35
- name: 'create-intent-with-discount',
36
- async run({ http, assert, state }) {
37
- const response = await http.as('journey-payments-intent-discount').post('backend-manager/payments/intent', {
38
- processor: 'test',
39
- productId: state.paidProductId,
40
- frequency: state.product.frequency,
41
- discount: 'WELCOME15',
42
- });
43
-
44
- assert.isSuccess(response, 'Intent with discount should succeed');
45
- assert.ok(response.data.orderId, 'Should return orderId');
46
-
47
- state.orderId = response.data.orderId;
48
- state.eventId = response.data.id.replace('_test-cs-', '_test-evt-');
49
- },
50
- },
51
-
52
- {
53
- name: 'subscription-activated-with-discount',
54
- async run({ firestore, assert, state, waitFor }) {
55
- await waitFor(async () => {
56
- const userDoc = await firestore.get(`users/${state.uid}`);
57
- return userDoc?.subscription?.product?.id === state.paidProductId;
58
- }, 15000, 500);
59
-
60
- const userDoc = await firestore.get(`users/${state.uid}`);
61
-
62
- assert.equal(userDoc.subscription.product.id, state.paidProductId, `Product should be ${state.paidProductId}`);
63
- assert.equal(userDoc.subscription.status, 'active', 'Status should be active');
64
- },
65
- },
66
-
67
- {
68
- name: 'order-has-discount',
69
- async run({ firestore, assert, state }) {
70
- const orderDoc = await firestore.get(`payments-orders/${state.orderId}`);
71
-
72
- assert.ok(orderDoc, 'Order doc should exist');
73
- assert.ok(orderDoc.discount, 'Order should have discount');
74
- assert.equal(orderDoc.discount.code, 'WELCOME15', 'Discount code should be WELCOME15');
75
- assert.equal(orderDoc.discount.percent, 15, 'Discount should be 15%');
76
- },
77
- },
78
-
79
- {
80
- name: 'webhook-transition-new-subscription',
81
- async run({ firestore, assert, state }) {
82
- const webhookDoc = await firestore.get(`payments-webhooks/${state.eventId}`);
83
-
84
- assert.ok(webhookDoc, 'Webhook doc should exist');
85
- assert.equal(webhookDoc.transition, 'new-subscription', 'Transition should be new-subscription');
86
- },
87
- },
88
- ],
89
- };