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,335 +0,0 @@
1
- /**
2
- * Test: Add Marketing Contact
3
- * Tests the general:add-marketing-contact command for adding users to SendGrid/Beehiiv
4
- *
5
- * Set TEST_EXTENDED_MODE=true to run tests against real SendGrid/Beehiiv APIs
6
- * (requires SENDGRID_API_KEY and BEEHIIV_API_KEY env vars)
7
- */
8
-
9
- // Test email patterns - look like real emails but +bem suffix identifies them for cleanup.
10
- // Fixed `acme.com` test domain — deterministic across brands. Avoids cross-brand
11
- // state contamination in SendGrid/Beehiiv when the same test runs under different brands.
12
- const TEST_DOMAIN = 'acme.com';
13
- const TEST_EMAILS = {
14
- valid: () => `sarah.martinez+bem@${TEST_DOMAIN}`, // Should infer: Sarah Martinez
15
- invalid: () => `nonexistent.user+bem@${TEST_DOMAIN}`, // No such mailbox — mailbox verification should flag invalid
16
- };
17
-
18
- module.exports = {
19
- description: 'Add marketing contact (SendGrid + Beehiiv)',
20
- type: 'group',
21
- tests: [
22
- // Test 1: Admin can add valid email (with real provider calls if TEST_EXTENDED_MODE is set)
23
- {
24
- name: 'admin-valid-email-succeeds',
25
- auth: 'admin',
26
- timeout: 30000,
27
-
28
- async run({ http, assert, state }) {
29
- const testEmail = TEST_EMAILS.valid();
30
- state.testEmail = testEmail;
31
-
32
- const response = await http.command('general:add-marketing-contact', {
33
- email: testEmail,
34
- source: 'bem-test',
35
- // No firstName/lastName - should be inferred as "Rachel Greene"
36
- });
37
-
38
- assert.isSuccess(response, 'Add marketing contact should succeed for admin');
39
- assert.hasProperty(response, 'data.success', 'Response should contain success');
40
- assert.propertyEquals(response, 'data.success', true, 'success should be true');
41
-
42
- // Admin gets detailed response
43
- assert.hasProperty(response, 'data.providers', 'Admin response should contain providers');
44
-
45
- // If TEST_EXTENDED_MODE is set, verify provider results
46
- if (process.env.TEST_EXTENDED_MODE) {
47
- const providers = response.data.providers || {};
48
-
49
- if (process.env.SENDGRID_API_KEY) {
50
- assert.hasProperty(response, 'data.providers.campaigns', 'Should have SendGrid result');
51
- if (providers.campaigns?.success) {
52
- state.sendgridAdded = true;
53
- } else {
54
- // Log error for debugging but don't fail - could be list matching issue
55
- console.log('SendGrid result:', providers.campaigns);
56
- }
57
- }
58
-
59
- if (process.env.BEEHIIV_API_KEY) {
60
- assert.hasProperty(response, 'data.providers.newsletter', 'Should have Beehiiv result');
61
- if (providers.newsletter?.success) {
62
- state.beehiivAdded = true;
63
- } else {
64
- console.log('Beehiiv result:', providers.newsletter);
65
- }
66
- }
67
- }
68
- },
69
-
70
- async cleanup({ state, http }) {
71
- // Only cleanup if TEST_EXTENDED_MODE is set and contacts were added
72
- if (!process.env.TEST_EXTENDED_MODE || !state.testEmail) {
73
- return;
74
- }
75
-
76
- console.log(`Cleaning up test contact: ${state.testEmail}`);
77
-
78
- const result = await http.command('general:remove-marketing-contact', {
79
- email: state.testEmail,
80
- });
81
- console.log('Cleanup result:', result.data);
82
- },
83
- },
84
-
85
- // Test 2: Invalid email format rejected
86
- {
87
- name: 'invalid-email-format-rejected',
88
- auth: 'admin',
89
- timeout: 15000,
90
-
91
- async run({ http, assert }) {
92
- const response = await http.command('general:add-marketing-contact', {
93
- email: 'not-a-valid-email',
94
- source: 'bem-test',
95
- });
96
-
97
- assert.isError(response, 400, 'Invalid email format should return 400');
98
- },
99
- },
100
-
101
- // Test 3: Missing email rejected
102
- {
103
- name: 'missing-email-rejected',
104
- auth: 'admin',
105
- timeout: 15000,
106
-
107
- async run({ http, assert }) {
108
- const response = await http.command('general:add-marketing-contact', {
109
- firstName: 'Test',
110
- source: 'bem-test',
111
- });
112
-
113
- assert.isError(response, 400, 'Missing email should return 400');
114
- },
115
- },
116
-
117
- // Test 4: Disposable email rejected
118
- {
119
- name: 'disposable-email-rejected',
120
- auth: 'admin',
121
- timeout: 15000,
122
-
123
- async run({ http, assert }) {
124
- const response = await http.command('general:add-marketing-contact', {
125
- email: 'test@mailinator.com',
126
- source: 'bem-test',
127
- });
128
-
129
- assert.isError(response, 400, 'Disposable email should return 400');
130
- },
131
- },
132
-
133
- // Test 5: Name inferred from email (AI only — requires extended mode)
134
- {
135
- name: 'name-inferred-from-email',
136
- skip: !process.env.TEST_EXTENDED_MODE ? 'TEST_EXTENDED_MODE not set (AI inference requires OPENAI_API_KEY)' : false,
137
- auth: 'admin',
138
- timeout: 30000,
139
-
140
- async run({ http, assert, state }) {
141
- // Use valid email without providing name - should infer "Rachel Greene"
142
- const testEmail = TEST_EMAILS.valid();
143
- state.testEmail = testEmail;
144
-
145
- const response = await http.command('general:add-marketing-contact', {
146
- email: testEmail,
147
- source: 'bem-test',
148
- // No firstName/lastName - should be inferred
149
- });
150
-
151
- assert.isSuccess(response, 'Add marketing contact should succeed');
152
-
153
- // Check name was inferred
154
- assert.hasProperty(response, 'data.nameInferred', 'Should have nameInferred');
155
- assert.ok(
156
- response.data.nameInferred.firstName || response.data.nameInferred.lastName,
157
- 'Name should be inferred from email'
158
- );
159
- assert.hasProperty(response.data.nameInferred, 'method', 'Should include inference method');
160
-
161
- // Track if providers were called
162
- if (process.env.TEST_EXTENDED_MODE) {
163
- state.sendgridAdded = response.data?.providers?.campaigns?.success;
164
- state.beehiivAdded = response.data?.providers?.newsletter?.success;
165
- }
166
- },
167
-
168
- async cleanup({ state, http }) {
169
- if (!process.env.TEST_EXTENDED_MODE || !state.testEmail) {
170
- return;
171
- }
172
-
173
- await http.command('general:remove-marketing-contact', { email: state.testEmail });
174
- },
175
- },
176
-
177
- // Test 6: Admin can skip validation (use disposable domain but skip check)
178
- {
179
- name: 'admin-skip-validation',
180
- auth: 'admin',
181
- timeout: 30000,
182
-
183
- async run({ http, assert, state }) {
184
- // Use disposable domain - normally blocked, but skipValidation bypasses
185
- const testEmail = 'rachel.greene+bem@mailinator.com';
186
- state.testEmail = testEmail;
187
-
188
- const response = await http.command('general:add-marketing-contact', {
189
- email: testEmail,
190
- source: 'bem-test',
191
- skipValidation: true,
192
- });
193
-
194
- // Should succeed because validation was skipped
195
- assert.isSuccess(response, 'Add marketing contact with skipValidation should succeed');
196
-
197
- if (process.env.TEST_EXTENDED_MODE) {
198
- state.sendgridAdded = response.data?.providers?.campaigns?.success;
199
- state.beehiivAdded = response.data?.providers?.newsletter?.success;
200
- }
201
- },
202
-
203
- async cleanup({ state, http }) {
204
- if (!process.env.TEST_EXTENDED_MODE || !state.testEmail) {
205
- return;
206
- }
207
-
208
- await http.command('general:remove-marketing-contact', { email: state.testEmail });
209
- },
210
- },
211
-
212
- // Test 7: Mailbox verification (only runs if TEST_EXTENDED_MODE and a mailbox API key are set)
213
- {
214
- name: 'mailbox-validation',
215
- auth: 'admin',
216
- timeout: 30000,
217
- skip: !process.env.TEST_EXTENDED_MODE || !(process.env.NEVERBOUNCE_API_KEY || process.env.ZEROBOUNCE_API_KEY)
218
- ? 'TEST_EXTENDED_MODE or mailbox API key not set'
219
- : false,
220
-
221
- async run({ http, assert, state, skip }) {
222
- const testEmail = TEST_EMAILS.valid();
223
- state.testEmail = testEmail;
224
-
225
- const response = await http.command('general:add-marketing-contact', {
226
- email: testEmail,
227
- source: 'bem-test',
228
- });
229
-
230
- assert.isSuccess(response, 'Add marketing contact should succeed');
231
-
232
- // Check that validation info is included
233
- assert.hasProperty(response, 'data.validation', 'Response should contain validation');
234
- assert.hasProperty(response, 'data.validation.checks', 'Validation should contain checks');
235
-
236
- // Mailbox check should be in checks when key is set
237
- assert.hasProperty(response, 'data.validation.checks.mailbox', 'Should have mailbox check');
238
-
239
- const mbResult = response.data.validation.checks.mailbox;
240
-
241
- // If out of credits, skip test - not a failure
242
- if (mbResult.error?.includes('out of credits')) {
243
- skip('Mailbox verification out of credits');
244
- }
245
-
246
- assert.hasProperty(mbResult, 'status', 'Mailbox check should return status');
247
-
248
- state.sendgridAdded = response.data?.providers?.campaigns?.success;
249
- state.beehiivAdded = response.data?.providers?.newsletter?.success;
250
- },
251
-
252
- async cleanup({ state, http }) {
253
- if (!state.testEmail) {
254
- return;
255
- }
256
-
257
- await http.command('general:remove-marketing-contact', { email: state.testEmail });
258
- },
259
- },
260
-
261
- // Test 9: Mailbox verification rejects invalid email (only runs if TEST_EXTENDED_MODE and a mailbox API key are set)
262
- {
263
- name: 'mailbox-rejects-invalid',
264
- auth: 'admin',
265
- timeout: 30000,
266
- skip: !process.env.TEST_EXTENDED_MODE || !(process.env.NEVERBOUNCE_API_KEY || process.env.ZEROBOUNCE_API_KEY)
267
- ? 'TEST_EXTENDED_MODE or mailbox API key not set'
268
- : false,
269
-
270
- async run({ http, assert, skip }) {
271
- // Use fake email that mailbox verification should flag as invalid
272
- const testEmail = TEST_EMAILS.invalid();
273
-
274
- const response = await http.command('general:add-marketing-contact', {
275
- email: testEmail,
276
- source: 'bem-test',
277
- });
278
-
279
- // Should still succeed (we fail open) but mailbox should report invalid
280
- assert.isSuccess(response, 'Request should succeed even with invalid email');
281
-
282
- const mbResult = response.data?.validation?.checks?.mailbox;
283
-
284
- // If out of credits, skip test - not a failure
285
- if (mbResult?.error?.includes('out of credits')) {
286
- skip('Mailbox verification out of credits');
287
- }
288
-
289
- // Mailbox should return a status indicating the email is not valid
290
- if (mbResult) {
291
- assert.hasProperty(mbResult, 'status', 'Should have status');
292
- // Status should NOT be 'valid' for this fake email
293
- assert.notEqual(mbResult.status, 'valid', 'Fake email should not be marked valid');
294
- }
295
- },
296
- },
297
-
298
- // --- Auth rejection tests (at end per convention) ---
299
- {
300
- name: 'unauthenticated-requires-recaptcha',
301
- auth: 'none',
302
- timeout: 15000,
303
-
304
- async run({ http, assert }) {
305
- // Public request without reCAPTCHA should fail
306
- const response = await http.command('general:add-marketing-contact', {
307
- email: TEST_EMAILS.valid(),
308
- source: 'bem-test',
309
- });
310
-
311
- // Should fail with 400 because no reCAPTCHA token
312
- assert.isError(response, 400, 'Public request without reCAPTCHA should fail');
313
- },
314
- },
315
-
316
- // --- Final cleanup test (runs last to clean up test contacts from providers) ---
317
- {
318
- name: 'cleanup-test-contacts',
319
- auth: 'admin',
320
- timeout: 30000,
321
- skip: !process.env.TEST_EXTENDED_MODE ? 'TEST_EXTENDED_MODE not set' : false,
322
-
323
- async run({ http, assert }) {
324
- // Clean up the rachel.greene+bem test contact from marketing providers
325
- const testEmail = TEST_EMAILS.valid();
326
-
327
- const response = await http.command('general:remove-marketing-contact', {
328
- email: testEmail,
329
- });
330
-
331
- assert.isSuccess(response, 'Remove marketing contact should succeed');
332
- },
333
- },
334
- ],
335
- };
@@ -1,54 +0,0 @@
1
- /**
2
- * Test: general:fetch-post
3
- * Tests the general fetch post command
4
- * Fetches blog post content from GitHub
5
- * Requires GitHub API key and repo_website config
6
- */
7
- module.exports = {
8
- description: 'General fetch post from GitHub',
9
- type: 'group',
10
- tests: [
11
- // Test 1: Missing URL returns 400 error
12
- {
13
- name: 'missing-url-rejected',
14
- auth: 'none',
15
- timeout: 15000,
16
-
17
- async run({ http, assert }) {
18
- const response = await http.command('general:fetch-post', {});
19
-
20
- assert.isError(response, 400, 'Missing URL should return 400');
21
- },
22
- },
23
-
24
- // Test 2: Non-existent post returns 404
25
- {
26
- name: 'nonexistent-post-returns-404',
27
- auth: 'none',
28
- timeout: 30000,
29
-
30
- async run({ http, assert }) {
31
- const response = await http.command('general:fetch-post', {
32
- url: 'https://example.com/blog/this-post-definitely-does-not-exist-12345',
33
- });
34
-
35
- assert.isError(response, 404, 'Non-existent post should return 404');
36
- },
37
- },
38
-
39
- // Test 3: Authenticated user fetching non-existent post returns 404
40
- {
41
- name: 'authenticated-nonexistent-returns-404',
42
- auth: 'basic',
43
- timeout: 30000,
44
-
45
- async run({ http, assert }) {
46
- const response = await http.command('general:fetch-post', {
47
- url: 'https://example.com/blog/nonexistent-test-post-12345',
48
- });
49
-
50
- assert.isError(response, 404, 'Non-existent post should return 404');
51
- },
52
- },
53
- ],
54
- };
@@ -1,114 +0,0 @@
1
- /**
2
- * Test: UUID Generation (Legacy Command)
3
- * Tests the legacy command-style API for backwards compatibility
4
- */
5
- module.exports = {
6
- description: 'UUID generation (legacy)',
7
- type: 'group',
8
- tests: [
9
- {
10
- name: 'v4-random-uuid',
11
- auth: 'none',
12
- timeout: 10000,
13
-
14
- async run({ http, assert }) {
15
- const response = await http.command('general:generate-uuid', {
16
- version: '4',
17
- });
18
-
19
- assert.isSuccess(response, 'UUID v4 generation should succeed');
20
- assert.hasProperty(response, 'data.uuid', 'Response should contain uuid');
21
- assert.match(
22
- response.data.uuid,
23
- /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,
24
- 'UUID v4 should have correct format'
25
- );
26
-
27
- return { success: true };
28
- },
29
- },
30
-
31
- {
32
- name: 'v5-namespaced-uuid',
33
- auth: 'none',
34
- timeout: 10000,
35
-
36
- async run({ http, assert }) {
37
- const response = await http.command('general:generate-uuid', {
38
- version: '5',
39
- name: 'test-name-for-uuid',
40
- });
41
-
42
- assert.isSuccess(response, 'UUID v5 generation should succeed');
43
- assert.hasProperty(response, 'data.uuid', 'Response should contain uuid');
44
- assert.match(
45
- response.data.uuid,
46
- /^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,
47
- 'UUID v5 should have correct format'
48
- );
49
-
50
- return { success: true };
51
- },
52
- },
53
-
54
- {
55
- name: 'v5-deterministic',
56
- auth: 'none',
57
- timeout: 10000,
58
-
59
- async run({ http, assert }) {
60
- const response1 = await http.command('general:generate-uuid', {
61
- version: '5',
62
- name: 'test-name-for-uuid',
63
- });
64
-
65
- const response2 = await http.command('general:generate-uuid', {
66
- version: '5',
67
- name: 'test-name-for-uuid',
68
- });
69
-
70
- assert.isSuccess(response1, 'First UUID v5 generation should succeed');
71
- assert.isSuccess(response2, 'Second UUID v5 generation should succeed');
72
- assert.equal(
73
- response1.data.uuid,
74
- response2.data.uuid,
75
- 'UUID v5 should be deterministic - same input should produce same output'
76
- );
77
-
78
- return { success: true };
79
- },
80
- },
81
-
82
- {
83
- name: 'v5-requires-name',
84
- auth: 'none',
85
- timeout: 10000,
86
-
87
- async run({ http, assert }) {
88
- const response = await http.command('general:generate-uuid', {
89
- version: '5',
90
- });
91
-
92
- assert.isError(response, 400, 'UUID v5 without name should return 400');
93
-
94
- return { success: true };
95
- },
96
- },
97
-
98
- {
99
- name: 'invalid-version-rejected',
100
- auth: 'none',
101
- timeout: 10000,
102
-
103
- async run({ http, assert }) {
104
- const response = await http.command('general:generate-uuid', {
105
- version: '99',
106
- });
107
-
108
- assert.isError(response, 400, 'Invalid version should return 400');
109
-
110
- return { success: true };
111
- },
112
- },
113
- ],
114
- };
@@ -1,64 +0,0 @@
1
- /**
2
- * Test: test:authenticate
3
- * Tests different authentication methods
4
- */
5
- module.exports = {
6
- description: 'Authentication methods',
7
- type: 'group',
8
- tests: [
9
- // Test 1: Unauthenticated request
10
- {
11
- name: 'no-auth',
12
- auth: 'none',
13
- async run({ http, assert }) {
14
- const response = await http.command('test:authenticate', {});
15
-
16
- assert.isSuccess(response, 'Should succeed without auth');
17
- assert.equal(response.data.user.authenticated, false, 'User should not be authenticated');
18
- },
19
- },
20
-
21
- // Test 2: Private key authentication
22
- {
23
- name: 'private-key',
24
- auth: 'basic',
25
- async run({ http, assert, accounts }) {
26
- const response = await http.command('test:authenticate', {});
27
-
28
- assert.isSuccess(response, 'Should succeed with privateKey');
29
- assert.equal(response.data.user.authenticated, true, 'User should be authenticated');
30
- assert.equal(response.data.user.auth.uid, accounts.basic.uid, 'UID should match');
31
- },
32
- },
33
-
34
- // Test 3: Invalid private key
35
- {
36
- name: 'invalid-private-key',
37
- auth: 'none',
38
- async run({ http, assert }) {
39
- const response = await http.post('/bm_api', {
40
- command: 'test:authenticate',
41
- payload: {},
42
- }, {
43
- headers: { 'Authorization': 'Bearer invalid-key-12345' },
44
- });
45
-
46
- assert.isSuccess(response, 'Should succeed but not authenticate');
47
- assert.equal(response.data.user.authenticated, false, 'Invalid key should not authenticate');
48
- },
49
- },
50
-
51
- // Test 4: Admin (backendManagerKey) authentication
52
- {
53
- name: 'backend-manager-key',
54
- auth: 'admin',
55
- async run({ http, assert }) {
56
- const response = await http.command('test:authenticate', {});
57
-
58
- assert.isSuccess(response, 'Should succeed with backendManagerKey');
59
- assert.equal(response.data.user.authenticated, true, 'User should be authenticated');
60
- assert.equal(response.data.user.roles?.admin, true, 'Should have admin role');
61
- },
62
- },
63
- ],
64
- };
@@ -1,73 +0,0 @@
1
- /**
2
- * Test: user:create-custom-token
3
- * Tests the user create custom token command
4
- * Requires user authentication (uses Api.resolveUser with adminRequired: true which means user must be authenticated)
5
- */
6
- module.exports = {
7
- description: 'User create custom token',
8
- type: 'group',
9
- tests: [
10
- // Test 1: Authenticated user can create custom token
11
- {
12
- name: 'authenticated-user-succeeds',
13
- auth: 'basic',
14
- timeout: 15000,
15
-
16
- async run({ http, assert }) {
17
- const response = await http.command('user:create-custom-token', {});
18
-
19
- assert.isSuccess(response, 'Create custom token should succeed for authenticated user');
20
- assert.hasProperty(response, 'data.token', 'Response should contain token');
21
- assert.ok(
22
- typeof response.data.token === 'string' && response.data.token.length > 0,
23
- 'Token should be a non-empty string'
24
- );
25
- },
26
- },
27
-
28
- // Test 2: Token has valid JWT format
29
- {
30
- name: 'token-is-valid-jwt',
31
- auth: 'basic',
32
- timeout: 15000,
33
-
34
- async run({ http, assert }) {
35
- const response = await http.command('user:create-custom-token', {});
36
-
37
- assert.isSuccess(response, 'Create custom token should succeed');
38
-
39
- // JWT tokens have 3 parts separated by dots
40
- const parts = response.data.token.split('.');
41
- assert.equal(parts.length, 3, 'Token should be a valid JWT with 3 parts');
42
- },
43
- },
44
-
45
- // Test 3: Premium user can create custom token
46
- // Note: Admin via backendManagerKey can't create tokens without a UID since it's not a real user
47
- {
48
- name: 'premium-user-succeeds',
49
- auth: 'premium-active',
50
- timeout: 15000,
51
-
52
- async run({ http, assert }) {
53
- const response = await http.command('user:create-custom-token', {});
54
-
55
- assert.isSuccess(response, 'Create custom token should succeed for premium user');
56
- assert.hasProperty(response, 'data.token', 'Response should contain token');
57
- },
58
- },
59
-
60
- // Test 4: Unauthenticated request fails
61
- {
62
- name: 'unauthenticated-rejected',
63
- auth: 'none',
64
- timeout: 15000,
65
-
66
- async run({ http, assert }) {
67
- const response = await http.command('user:create-custom-token', {});
68
-
69
- assert.isError(response, 401, 'Create custom token should fail without authentication');
70
- },
71
- },
72
- ],
73
- };