backend-manager 5.9.5 → 5.9.7

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 (246) hide show
  1. package/package.json +8 -1
  2. package/src/manager/events/cron/runner.js +0 -1
  3. package/src/manager/libraries/email/data/disposable-domains.json +21 -0
  4. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/metadata.json +14 -0
  5. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/newsletter.html +486 -0
  6. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/newsletter.md +41 -0
  7. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/newsletter.mjml +97 -0
  8. package/{test/email/fixtures/clean.json → src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/structure.json} +16 -4
  9. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/summary.md +1 -0
  10. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/metadata.json +14 -0
  11. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/newsletter.html +486 -0
  12. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/newsletter.md +41 -0
  13. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/newsletter.mjml +97 -0
  14. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/structure.json +42 -0
  15. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/summary.md +1 -0
  16. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/metadata.json +14 -0
  17. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/newsletter.html +486 -0
  18. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/newsletter.md +41 -0
  19. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/newsletter.mjml +97 -0
  20. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/structure.json +42 -0
  21. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/summary.md +1 -0
  22. package/src/test/fixtures/firebase-project/.temp/test-mode.json +6 -0
  23. package/src/test/fixtures/firebase-project/database-debug.log +12 -0
  24. package/src/test/fixtures/firebase-project/firestore-debug.log +132 -0
  25. package/src/test/fixtures/firebase-project/pubsub-debug.log +17 -0
  26. package/.codeclimate.yml +0 -32
  27. package/.nvmrc +0 -1
  28. package/CHANGELOG.md +0 -1440
  29. package/PROGRESS.md +0 -93
  30. package/TODO-2.md +0 -121
  31. package/TODO-CHARGEBLAST.md +0 -32
  32. package/TODO-WEBHOOK-KEY-LEGACY-REMOVAL.md +0 -15
  33. package/TODO-WEBHOOK-KEY-UPGRADE.md +0 -138
  34. package/TODO-email-auth.md +0 -14
  35. package/TODO.md +0 -187
  36. package/plans/mcp2.md +0 -247
  37. package/plans/suspended-subscription-dead-zone.md +0 -97
  38. package/scripts/test-helper-providers.js +0 -162
  39. package/scripts/update-disposable-domains.js +0 -44
  40. package/templates/_.env +0 -42
  41. package/templates/_.gitignore +0 -60
  42. package/templates/backend-manager-config.json +0 -249
  43. package/templates/database.rules.json +0 -83
  44. package/templates/firebase.json +0 -66
  45. package/templates/firestore.indexes.json +0 -4
  46. package/templates/firestore.rules +0 -112
  47. package/templates/public/404.html +0 -26
  48. package/templates/public/index.html +0 -24
  49. package/templates/remoteconfig.template.json +0 -1
  50. package/templates/storage-lifecycle-config-1-day.json +0 -9
  51. package/templates/storage-lifecycle-config-30-days.json +0 -9
  52. package/templates/storage.rules +0 -8
  53. package/test/_init/accounts-validation.js +0 -58
  54. package/test/_legacy/ai/index.js +0 -231
  55. package/test/_legacy/ai/test.jpg +0 -0
  56. package/test/_legacy/ai/test.pdf +0 -0
  57. package/test/_legacy/index.js +0 -31
  58. package/test/_legacy/payment-resolver/chargebee/orders/refunded.json +0 -0
  59. package/test/_legacy/payment-resolver/chargebee/orders/unpaid.json +0 -98
  60. package/test/_legacy/payment-resolver/chargebee/subscriptions/active.json +0 -578
  61. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-in-trial.json +0 -38
  62. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-skipped-to-active.json +0 -135
  63. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-active-to-cancelled.json +0 -42
  64. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-active.json +0 -44
  65. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-cancelled.json +0 -39
  66. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-refund.json +0 -143
  67. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-suspended.json +0 -48
  68. package/test/_legacy/payment-resolver/coinbase/orders/regular.json +0 -204
  69. package/test/_legacy/payment-resolver/coinbase/subscriptions/cancelled.json +0 -204
  70. package/test/_legacy/payment-resolver/coinbase/subscriptions/paid-2.json +0 -125
  71. package/test/_legacy/payment-resolver/index.js +0 -1558
  72. package/test/_legacy/payment-resolver/paypal/orders/refunded.json +0 -0
  73. package/test/_legacy/payment-resolver/paypal/orders/regular.json +0 -120
  74. package/test/_legacy/payment-resolver/paypal/subscriptions/active-refund-previous-stmnt.json +0 -323
  75. package/test/_legacy/payment-resolver/paypal/subscriptions/active.json +0 -192
  76. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-in-trial.json +0 -125
  77. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-not-complete.json +0 -76
  78. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-overdue-2.json +0 -114
  79. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-overdue.json +0 -114
  80. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-active-to-cancelled.json +0 -111
  81. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-active.json +0 -132
  82. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-cancelled.json +0 -107
  83. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-expired.json +0 -91
  84. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-refund.json +0 -147
  85. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-suspended.json +0 -120
  86. package/test/_legacy/payment-resolver/stripe/orders/refunded.json +0 -0
  87. package/test/_legacy/payment-resolver/stripe/orders/regular.json +0 -91
  88. package/test/_legacy/payment-resolver/stripe/subscriptions/active.json +0 -421
  89. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-in-trial.json +0 -349
  90. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-active-failed-authorization.json +0 -430
  91. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-active.json +0 -319
  92. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-cancelled.json +0 -319
  93. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-refund.json +0 -414
  94. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-suspended.json +0 -319
  95. package/test/_legacy/payment-resolver/stripe/subscriptions/unsure.json +0 -339
  96. package/test/_legacy/test-new +0 -1178
  97. package/test/_legacy/test.md +0 -89
  98. package/test/_legacy/usage.js +0 -175
  99. package/test/_legacy/user.js +0 -31
  100. package/test/ai/tools-live.js +0 -170
  101. package/test/boot/emulator-boots.js +0 -37
  102. package/test/content/blog-generate.js +0 -160
  103. package/test/email/campaign-send.js +0 -45
  104. package/test/email/consent-lifecycle.js +0 -257
  105. package/test/email/feedback-and-plain-send.js +0 -52
  106. package/test/email/fixtures/editorial.json +0 -30
  107. package/test/email/fixtures/field-report.json +0 -53
  108. package/test/email/marketing-lifecycle.js +0 -132
  109. package/test/email/newsletter-generate.js +0 -819
  110. package/test/email/newsletter-templates.js +0 -491
  111. package/test/email/templates.js +0 -207
  112. package/test/email/transactional-send.js +0 -34
  113. package/test/email/transactional.js +0 -560
  114. package/test/email/validation.js +0 -710
  115. package/test/events/auth-delete-race.js +0 -201
  116. package/test/events/payments/journey-payments-cancel-endpoint.js +0 -100
  117. package/test/events/payments/journey-payments-cancel.js +0 -182
  118. package/test/events/payments/journey-payments-discount.js +0 -89
  119. package/test/events/payments/journey-payments-failure.js +0 -146
  120. package/test/events/payments/journey-payments-legacy-product.js +0 -149
  121. package/test/events/payments/journey-payments-one-time-failure.js +0 -111
  122. package/test/events/payments/journey-payments-one-time.js +0 -136
  123. package/test/events/payments/journey-payments-plan-change.js +0 -144
  124. package/test/events/payments/journey-payments-refund-webhook.js +0 -180
  125. package/test/events/payments/journey-payments-suspend.js +0 -181
  126. package/test/events/payments/journey-payments-trial-cancel.js +0 -130
  127. package/test/events/payments/journey-payments-trial.js +0 -171
  128. package/test/events/payments/journey-payments-uid-resolution.js +0 -132
  129. package/test/events/payments/journey-payments-upgrade.js +0 -135
  130. package/test/fixtures/chargebee/invoice-one-time.json +0 -27
  131. package/test/fixtures/chargebee/subscription-active.json +0 -44
  132. package/test/fixtures/chargebee/subscription-cancelled.json +0 -42
  133. package/test/fixtures/chargebee/subscription-in-trial.json +0 -41
  134. package/test/fixtures/chargebee/subscription-legacy-plan.json +0 -41
  135. package/test/fixtures/chargebee/subscription-non-renewing.json +0 -41
  136. package/test/fixtures/chargebee/subscription-paused.json +0 -42
  137. package/test/fixtures/chargebee/webhook-payment-failed.json +0 -51
  138. package/test/fixtures/chargebee/webhook-subscription-created.json +0 -47
  139. package/test/fixtures/paypal/order-approved.json +0 -62
  140. package/test/fixtures/paypal/order-completed.json +0 -110
  141. package/test/fixtures/paypal/subscription-active.json +0 -76
  142. package/test/fixtures/paypal/subscription-cancelled.json +0 -50
  143. package/test/fixtures/paypal/subscription-suspended.json +0 -65
  144. package/test/fixtures/stripe/checkout-session-completed.json +0 -130
  145. package/test/fixtures/stripe/invoice-payment-failed.json +0 -148
  146. package/test/fixtures/stripe/invoice-subscription-payment-failed.json +0 -28
  147. package/test/fixtures/stripe/subscription-active.json +0 -161
  148. package/test/fixtures/stripe/subscription-canceled.json +0 -161
  149. package/test/fixtures/stripe/subscription-trialing.json +0 -161
  150. package/test/functions/admin/database-read.js +0 -134
  151. package/test/functions/admin/database-write.js +0 -159
  152. package/test/functions/admin/edit-post.js +0 -366
  153. package/test/functions/admin/firestore-query.js +0 -207
  154. package/test/functions/admin/firestore-read.js +0 -129
  155. package/test/functions/admin/firestore-write.js +0 -105
  156. package/test/functions/admin/get-stats.js +0 -115
  157. package/test/functions/admin/send-email.js +0 -119
  158. package/test/functions/admin/send-notification.js +0 -208
  159. package/test/functions/admin/write-repo-content.js +0 -223
  160. package/test/functions/general/add-marketing-contact.js +0 -335
  161. package/test/functions/general/fetch-post.js +0 -54
  162. package/test/functions/general/generate-uuid.js +0 -114
  163. package/test/functions/test/authenticate.js +0 -64
  164. package/test/functions/user/create-custom-token.js +0 -73
  165. package/test/functions/user/delete.js +0 -135
  166. package/test/functions/user/get-active-sessions.js +0 -111
  167. package/test/functions/user/get-subscription-info.js +0 -99
  168. package/test/functions/user/regenerate-api-keys.js +0 -156
  169. package/test/functions/user/resolve.js +0 -52
  170. package/test/functions/user/sign-out-all-sessions.js +0 -94
  171. package/test/functions/user/sign-up.js +0 -252
  172. package/test/functions/user/submit-feedback.js +0 -104
  173. package/test/functions/user/validate-settings.js +0 -82
  174. package/test/helpers/ai-request-payload.js +0 -300
  175. package/test/helpers/ai-test-provider.js +0 -202
  176. package/test/helpers/ai-tools-format.js +0 -383
  177. package/test/helpers/content/blog-auto-publisher.js +0 -484
  178. package/test/helpers/content/feed-parser.js +0 -528
  179. package/test/helpers/content/ghostii-blocks.js +0 -134
  180. package/test/helpers/content/ghostii-feed-integration.js +0 -404
  181. package/test/helpers/content/ghostii-write-article.js +0 -243
  182. package/test/helpers/environment.js +0 -230
  183. package/test/helpers/infer-contact.js +0 -113
  184. package/test/helpers/merge-line-files.js +0 -271
  185. package/test/helpers/payment/chargebee/parse-webhook.js +0 -413
  186. package/test/helpers/payment/chargebee/to-unified-one-time.js +0 -147
  187. package/test/helpers/payment/chargebee/to-unified-subscription.js +0 -648
  188. package/test/helpers/payment/paypal/parse-webhook.js +0 -539
  189. package/test/helpers/payment/paypal/to-unified-one-time.js +0 -382
  190. package/test/helpers/payment/paypal/to-unified-subscription.js +0 -820
  191. package/test/helpers/payment/stripe/parse-webhook.js +0 -447
  192. package/test/helpers/payment/stripe/to-unified-one-time.js +0 -306
  193. package/test/helpers/payment/stripe/to-unified-subscription.js +0 -708
  194. package/test/helpers/sanitize.js +0 -222
  195. package/test/helpers/slugify.js +0 -394
  196. package/test/helpers/storage.js +0 -194
  197. package/test/helpers/user.js +0 -755
  198. package/test/helpers/webhook-forward.js +0 -418
  199. package/test/mcp/discovery.js +0 -53
  200. package/test/mcp/oauth.js +0 -161
  201. package/test/mcp/protocol.js +0 -268
  202. package/test/mcp/roles.js +0 -188
  203. package/test/mcp/utils.js +0 -245
  204. package/test/routes/admin/create-post.js +0 -364
  205. package/test/routes/admin/database.js +0 -131
  206. package/test/routes/admin/deduplicate-image-alts.js +0 -190
  207. package/test/routes/admin/email.js +0 -114
  208. package/test/routes/admin/firestore-query.js +0 -204
  209. package/test/routes/admin/firestore.js +0 -127
  210. package/test/routes/admin/infer-contact.js +0 -218
  211. package/test/routes/admin/notification.js +0 -198
  212. package/test/routes/admin/post-resize-image.js +0 -184
  213. package/test/routes/admin/post.js +0 -368
  214. package/test/routes/admin/repo-content.js +0 -223
  215. package/test/routes/admin/stats.js +0 -112
  216. package/test/routes/content/post.js +0 -54
  217. package/test/routes/general/uuid.js +0 -115
  218. package/test/routes/marketing/campaign.js +0 -125
  219. package/test/routes/marketing/contact.js +0 -370
  220. package/test/routes/marketing/email-preferences.js +0 -292
  221. package/test/routes/marketing/push-send.js +0 -32
  222. package/test/routes/marketing/webhook-forward.js +0 -61
  223. package/test/routes/marketing/webhook.js +0 -639
  224. package/test/routes/payments/cancel.js +0 -163
  225. package/test/routes/payments/discount.js +0 -80
  226. package/test/routes/payments/dispute-alert.js +0 -320
  227. package/test/routes/payments/intent.js +0 -336
  228. package/test/routes/payments/portal.js +0 -92
  229. package/test/routes/payments/refund.js +0 -179
  230. package/test/routes/payments/trial-eligibility.js +0 -71
  231. package/test/routes/payments/webhook.js +0 -107
  232. package/test/routes/test/authenticate.js +0 -59
  233. package/test/routes/test/schema.js +0 -554
  234. package/test/routes/test/usage.js +0 -342
  235. package/test/routes/user/api-keys.js +0 -156
  236. package/test/routes/user/delete.js +0 -136
  237. package/test/routes/user/feedback.js +0 -104
  238. package/test/routes/user/sessions.js +0 -199
  239. package/test/routes/user/settings-validate.js +0 -82
  240. package/test/routes/user/signup.js +0 -542
  241. package/test/routes/user/subscription.js +0 -99
  242. package/test/routes/user/token.js +0 -73
  243. package/test/routes/user/user.js +0 -157
  244. package/test/rules/notifications.js +0 -410
  245. package/test/rules/payments-carts.js +0 -371
  246. package/test/rules/user.js +0 -396
@@ -1,54 +0,0 @@
1
- /**
2
- * Test: GET /content/post
3
- * Tests the content fetch post endpoint
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.get('backend-manager/content/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.get('backend-manager/content/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.get('backend-manager/content/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,115 +0,0 @@
1
- /**
2
- * Test: UUID Route
3
- * Tests the new RESTful UUID endpoint using proper HTTP verbs
4
- */
5
- module.exports = {
6
- description: 'UUID route',
7
- type: 'group',
8
- tests: [
9
- {
10
- name: 'v4-random-uuid',
11
- auth: 'none',
12
- timeout: 10000,
13
-
14
- async run({ http, assert }) {
15
- // POST /backend-manager/general/uuid
16
- const response = await http.post('backend-manager/general/uuid', {
17
- version: '4',
18
- });
19
-
20
- assert.isSuccess(response, 'UUID v4 generation should succeed');
21
- assert.hasProperty(response, 'data.uuid', 'Response should contain uuid');
22
- assert.match(
23
- response.data.uuid,
24
- /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,
25
- 'UUID v4 should have correct format'
26
- );
27
-
28
- return { success: true };
29
- },
30
- },
31
-
32
- {
33
- name: 'v5-namespaced-uuid',
34
- auth: 'none',
35
- timeout: 10000,
36
-
37
- async run({ http, assert }) {
38
- const response = await http.post('backend-manager/general/uuid', {
39
- version: '5',
40
- name: 'test-name-for-uuid',
41
- });
42
-
43
- assert.isSuccess(response, 'UUID v5 generation should succeed');
44
- assert.hasProperty(response, 'data.uuid', 'Response should contain uuid');
45
- assert.match(
46
- response.data.uuid,
47
- /^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,
48
- 'UUID v5 should have correct format'
49
- );
50
-
51
- return { success: true };
52
- },
53
- },
54
-
55
- {
56
- name: 'v5-deterministic',
57
- auth: 'none',
58
- timeout: 10000,
59
-
60
- async run({ http, assert }) {
61
- const response1 = await http.post('backend-manager/general/uuid', {
62
- version: '5',
63
- name: 'test-name-for-uuid',
64
- });
65
-
66
- const response2 = await http.post('backend-manager/general/uuid', {
67
- version: '5',
68
- name: 'test-name-for-uuid',
69
- });
70
-
71
- assert.isSuccess(response1, 'First UUID v5 generation should succeed');
72
- assert.isSuccess(response2, 'Second UUID v5 generation should succeed');
73
- assert.equal(
74
- response1.data.uuid,
75
- response2.data.uuid,
76
- 'UUID v5 should be deterministic - same input should produce same output'
77
- );
78
-
79
- return { success: true };
80
- },
81
- },
82
-
83
- {
84
- name: 'v5-requires-name',
85
- auth: 'none',
86
- timeout: 10000,
87
-
88
- async run({ http, assert }) {
89
- const response = await http.post('backend-manager/general/uuid', {
90
- version: '5',
91
- });
92
-
93
- assert.isError(response, 400, 'UUID v5 without name should return 400');
94
-
95
- return { success: true };
96
- },
97
- },
98
-
99
- {
100
- name: 'invalid-version-rejected',
101
- auth: 'none',
102
- timeout: 10000,
103
-
104
- async run({ http, assert }) {
105
- const response = await http.post('backend-manager/general/uuid', {
106
- version: '99',
107
- });
108
-
109
- assert.isError(response, 400, 'Invalid version should return 400');
110
-
111
- return { success: true };
112
- },
113
- },
114
- ],
115
- };
@@ -1,125 +0,0 @@
1
- /**
2
- * Test: POST /marketing/campaign — Send a marketing campaign (Single Send)
3
- *
4
- * Normal mode: creates campaign doc in Firestore, verifies structure
5
- * Extended mode (TEST_EXTENDED_MODE=true): sends a real test campaign via SendGrid/Beehiiv
6
- * targeting the test_admin segment (hello@itwcreativeworks.com only)
7
- */
8
-
9
- module.exports = {
10
- description: 'Marketing campaign (POST create + send)',
11
- type: 'group',
12
- tests: [
13
- {
14
- name: 'send-test-campaign',
15
- auth: 'admin',
16
- timeout: 60000,
17
- skip: !process.env.TEST_EXTENDED_MODE
18
- ? 'TEST_EXTENDED_MODE not set (real provider send)'
19
- : false,
20
-
21
- async run({ http, assert, state }) {
22
- const response = await http.post('backend-manager/marketing/campaign', {
23
- name: 'BEM Test Campaign',
24
- subject: 'Test Marketing Email',
25
- content: '# Hello\n\nThis is a **test marketing email** sent from the BEM test suite.\n\nIf you received this, the SendGrid Single Send pipeline is working.',
26
- test: true,
27
- sendAt: 'now',
28
- });
29
-
30
- assert.isSuccess(response, 'Campaign creation should succeed');
31
- assert.hasProperty(response, 'data.id', 'Response should contain campaign ID');
32
- assert.hasProperty(response, 'data.providers', 'Response should contain provider results');
33
-
34
- const providers = response.data.providers || {};
35
-
36
- console.log('Campaign results:', JSON.stringify(providers, null, 2));
37
-
38
- if (providers.campaigns) {
39
- state.sendgridId = providers.campaigns.id;
40
-
41
- assert.propertyEquals(
42
- response, 'data.providers.campaigns.success', true,
43
- `SendGrid should succeed. Error: ${providers.campaigns.error || 'none'}`,
44
- );
45
- }
46
-
47
- if (providers.newsletter) {
48
- assert.hasProperty(response, 'data.providers.newsletter', 'Should have Beehiiv result');
49
- }
50
-
51
- state.campaignId = response.data.id;
52
- },
53
-
54
- async cleanup({ state }) {
55
- if (state.campaignId) {
56
- console.log(`Campaign ID: ${state.campaignId}`);
57
- }
58
- if (state.sendgridId) {
59
- console.log(`SendGrid Single Send ID: ${state.sendgridId}`);
60
- }
61
- },
62
- },
63
-
64
- {
65
- name: 'create-future-campaign-is-pending',
66
- auth: 'admin',
67
- timeout: 30000,
68
-
69
- async run({ http, assert, firestore }) {
70
- // Future sendAt → campaign is saved as 'pending' for cron pickup, not sent immediately
71
- const futureDate = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000).toISOString();
72
-
73
- const response = await http.post('backend-manager/marketing/campaign', {
74
- name: 'Future Campaign',
75
- subject: 'Future Subject',
76
- content: 'Future content',
77
- test: true,
78
- sendAt: futureDate,
79
- });
80
-
81
- assert.isSuccess(response, 'Future campaign creation should succeed');
82
- assert.hasProperty(response, 'data.id', 'Response should contain campaign ID');
83
- assert.propertyEquals(response, 'data.status', 'pending', 'Future campaign should be pending');
84
-
85
- const doc = await firestore.get(`marketing-campaigns/${response.data.id}`);
86
- assert.ok(doc, 'Campaign doc should exist in Firestore');
87
- assert.equal(doc.status, 'pending', 'Firestore doc status should be pending');
88
- assert.equal(doc.settings.name, 'Future Campaign', 'Name should match input');
89
- assert.propertyEquals(response, 'data.providers', null, 'Future campaign should not have provider results');
90
- },
91
- },
92
-
93
- {
94
- name: 'campaign-requires-admin',
95
- auth: 'user',
96
- timeout: 15000,
97
-
98
- async run({ http, assert }) {
99
- const response = await http.post('backend-manager/marketing/campaign', {
100
- name: 'Unauthorized Campaign',
101
- subject: 'Should fail',
102
- content: 'Should fail',
103
- });
104
-
105
- assert.isError(response, 403, 'Non-admin should get 403');
106
- },
107
- },
108
-
109
- {
110
- name: 'campaign-requires-auth',
111
- auth: 'none',
112
- timeout: 15000,
113
-
114
- async run({ http, assert }) {
115
- const response = await http.post('backend-manager/marketing/campaign', {
116
- name: 'Unauthenticated Campaign',
117
- subject: 'Should fail',
118
- content: 'Should fail',
119
- });
120
-
121
- assert.isError(response, 401, 'Unauthenticated should get 401');
122
- },
123
- },
124
- ],
125
- };
@@ -1,370 +0,0 @@
1
- /**
2
- * Test: POST /marketing/contact and DELETE /marketing/contact
3
- * Tests the marketing contact endpoints for adding/removing 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
- // Names should be inferred by AI from the email local part.
11
- //
12
- // Fixed test domain (`acme.com`) — deterministic across brands. Using the running brand's
13
- // domain caused cross-brand state divergence in SendGrid/Beehiiv and non-deterministic
14
- // company inference (different domain → different inferred company name).
15
- //
16
- // `valid`: use a name that won't be flagged as fictional/placeholder by the AI prompt.
17
- // (The infer-contact prompt rejects fictional names — e.g. "rachel.greene" sometimes
18
- // matches the Friends character and returns empty. Use a more anonymous name.)
19
- //
20
- // `invalid`: must reach the mailbox verification check (so previous checks all pass — must
21
- // NOT start with "test"/"example" which are in BLOCKED_LOCAL_PATTERNS, NOT be on
22
- // a corporate/disposable domain). Real-looking name on a real domain with no actual
23
- // mailbox there is the safest pick.
24
- const TEST_DOMAIN = 'acme.com';
25
- const TEST_EMAILS = {
26
- valid: () => `sarah.martinez+bem@${TEST_DOMAIN}`, // Should infer: Sarah Martinez
27
- invalid: () => `nonexistent.user+bem@${TEST_DOMAIN}`, // No such mailbox — mailbox verification should flag as invalid
28
- };
29
-
30
- module.exports = {
31
- description: 'Marketing contact (POST add + DELETE remove)',
32
- type: 'group',
33
- tests: [
34
- // --- POST /marketing/contact tests ---
35
-
36
- // Test 1: Admin can add valid email (with real provider calls if TEST_EXTENDED_MODE is set)
37
- {
38
- name: 'add-admin-valid-email-succeeds',
39
- auth: 'admin',
40
- timeout: 30000,
41
-
42
- async run({ http, assert, state, config }) {
43
- const testEmail = TEST_EMAILS.valid();
44
- state.testEmail = testEmail;
45
-
46
- const response = await http.post('backend-manager/marketing/contact', {
47
- email: testEmail,
48
- source: 'bem-test',
49
- // skipValidation bypasses the mailbox verification check — the test email
50
- // doesn't have a real mailbox so the provider (correctly) marks it as not
51
- // deliverable. We're testing the route flow, not the deliverability check itself.
52
- skipValidation: true,
53
- // No firstName/lastName - should be inferred as "Rachel Greene"
54
- });
55
-
56
- assert.isSuccess(response, 'Add marketing contact should succeed for admin');
57
- assert.hasProperty(response, 'data.success', 'Response should contain success');
58
- assert.propertyEquals(response, 'data.success', true, 'success should be true');
59
-
60
- // Admin gets detailed response
61
- assert.hasProperty(response, 'data.providers', 'Admin response should contain providers');
62
-
63
- // If TEST_EXTENDED_MODE is set, verify provider results
64
- if (process.env.TEST_EXTENDED_MODE) {
65
- const providers = response.data.providers || {};
66
-
67
- if (process.env.SENDGRID_API_KEY) {
68
- assert.hasProperty(response, 'data.providers.campaigns', 'Should have SendGrid result');
69
- if (providers.campaigns?.success) {
70
- state.sendgridAdded = true;
71
- } else {
72
- // Log error for debugging but don't fail - could be list matching issue
73
- console.log('SendGrid result:', providers.campaigns);
74
- }
75
- }
76
-
77
- if (process.env.BEEHIIV_API_KEY && config.marketing?.newsletter?.publicationId) {
78
- assert.hasProperty(response, 'data.providers.newsletter', 'Should have Beehiiv result');
79
- if (providers.newsletter?.success) {
80
- state.beehiivAdded = true;
81
- } else {
82
- console.log('Beehiiv result:', providers.newsletter);
83
- }
84
- }
85
- }
86
- },
87
-
88
- async cleanup({ state, http }) {
89
- // Only cleanup if TEST_EXTENDED_MODE is set and contacts were added
90
- if (!process.env.TEST_EXTENDED_MODE || !state.testEmail) {
91
- return;
92
- }
93
-
94
- console.log(`Cleaning up test contact: ${state.testEmail}`);
95
-
96
- const result = await http.delete('backend-manager/marketing/contact', {
97
- email: state.testEmail,
98
- });
99
- console.log('Cleanup result:', result.data);
100
- },
101
- },
102
-
103
- // Test 2: Invalid email format rejected
104
- {
105
- name: 'add-invalid-email-format-rejected',
106
- auth: 'admin',
107
- timeout: 15000,
108
-
109
- async run({ http, assert }) {
110
- const response = await http.post('backend-manager/marketing/contact', {
111
- email: 'not-a-valid-email',
112
- source: 'bem-test',
113
- });
114
-
115
- assert.isError(response, 400, 'Invalid email format should return 400');
116
- },
117
- },
118
-
119
- // Test 3: Missing email rejected
120
- {
121
- name: 'add-missing-email-rejected',
122
- auth: 'admin',
123
- timeout: 15000,
124
-
125
- async run({ http, assert }) {
126
- const response = await http.post('backend-manager/marketing/contact', {
127
- firstName: 'Test',
128
- source: 'bem-test',
129
- });
130
-
131
- assert.isError(response, 400, 'Missing email should return 400');
132
- },
133
- },
134
-
135
- // Test 4: Disposable email rejected
136
- {
137
- name: 'add-disposable-email-rejected',
138
- auth: 'admin',
139
- timeout: 15000,
140
-
141
- async run({ http, assert }) {
142
- const response = await http.post('backend-manager/marketing/contact', {
143
- email: 'test@mailinator.com',
144
- source: 'bem-test',
145
- });
146
-
147
- assert.isError(response, 400, 'Disposable email should return 400');
148
- },
149
- },
150
-
151
- // Test 5: Name inferred from email (AI only — requires extended mode)
152
- {
153
- name: 'add-name-inferred-from-email',
154
- skip: !process.env.TEST_EXTENDED_MODE ? 'TEST_EXTENDED_MODE not set (AI inference requires OPENAI_API_KEY)' : false,
155
- auth: 'admin',
156
- timeout: 30000,
157
-
158
- async run({ http, assert, state }) {
159
- // Use valid email without providing name - should infer "Rachel Greene"
160
- const testEmail = TEST_EMAILS.valid();
161
- state.testEmail = testEmail;
162
-
163
- const response = await http.post('backend-manager/marketing/contact', {
164
- email: testEmail,
165
- source: 'bem-test',
166
- // No firstName/lastName - should be inferred
167
- });
168
-
169
- assert.isSuccess(response, 'Add marketing contact should succeed');
170
-
171
- // Check name was inferred
172
- assert.hasProperty(response, 'data.nameInferred', 'Should have nameInferred');
173
- assert.ok(
174
- response.data.nameInferred.firstName || response.data.nameInferred.lastName,
175
- 'Name should be inferred from email'
176
- );
177
- assert.hasProperty(response.data.nameInferred, 'method', 'Should include inference method');
178
-
179
- // Track if providers were called
180
- if (process.env.TEST_EXTENDED_MODE) {
181
- state.sendgridAdded = response.data?.providers?.campaigns?.success;
182
- state.beehiivAdded = response.data?.providers?.newsletter?.success;
183
- }
184
- },
185
-
186
- async cleanup({ state, http }) {
187
- if (!process.env.TEST_EXTENDED_MODE || !state.testEmail) {
188
- return;
189
- }
190
-
191
- await http.delete('backend-manager/marketing/contact', { email: state.testEmail });
192
- },
193
- },
194
-
195
- // Test 6: Admin can skip validation (use disposable domain but skip check)
196
- {
197
- name: 'add-admin-skip-validation',
198
- auth: 'admin',
199
- timeout: 30000,
200
-
201
- async run({ http, assert, state }) {
202
- // Use disposable domain - normally blocked, but skipValidation bypasses
203
- const testEmail = 'rachel.greene+bem@mailinator.com';
204
- state.testEmail = testEmail;
205
-
206
- const response = await http.post('backend-manager/marketing/contact', {
207
- email: testEmail,
208
- source: 'bem-test',
209
- skipValidation: true,
210
- });
211
-
212
- // Should succeed because validation was skipped
213
- assert.isSuccess(response, 'Add marketing contact with skipValidation should succeed');
214
-
215
- if (process.env.TEST_EXTENDED_MODE) {
216
- state.sendgridAdded = response.data?.providers?.campaigns?.success;
217
- state.beehiivAdded = response.data?.providers?.newsletter?.success;
218
- }
219
- },
220
-
221
- async cleanup({ state, http }) {
222
- if (!process.env.TEST_EXTENDED_MODE || !state.testEmail) {
223
- return;
224
- }
225
-
226
- await http.delete('backend-manager/marketing/contact', { email: state.testEmail });
227
- },
228
- },
229
-
230
- // Test 7: Mailbox verification (only runs if TEST_EXTENDED_MODE and a mailbox API key are set)
231
- {
232
- name: 'add-mailbox-validation',
233
- auth: 'admin',
234
- timeout: 30000,
235
- skip: !process.env.TEST_EXTENDED_MODE || !(process.env.NEVERBOUNCE_API_KEY || process.env.ZEROBOUNCE_API_KEY)
236
- ? 'TEST_EXTENDED_MODE or mailbox API key not set'
237
- : false,
238
-
239
- async run({ http, assert, state, skip }) {
240
- const testEmail = TEST_EMAILS.valid();
241
- state.testEmail = testEmail;
242
-
243
- const response = await http.post('backend-manager/marketing/contact', {
244
- email: testEmail,
245
- source: 'bem-test',
246
- });
247
-
248
- assert.isSuccess(response, 'Add marketing contact should succeed');
249
-
250
- // Check that validation info is included
251
- assert.hasProperty(response, 'data.validation', 'Response should contain validation');
252
- assert.hasProperty(response, 'data.validation.checks', 'Validation should contain checks');
253
-
254
- // Mailbox check should be in checks when key is set
255
- assert.hasProperty(response, 'data.validation.checks.mailbox', 'Should have mailbox check');
256
-
257
- const mbResult = response.data.validation.checks.mailbox;
258
-
259
- // If out of credits, skip test - not a failure
260
- if (mbResult.error?.includes('out of credits')) {
261
- skip('Mailbox verification out of credits');
262
- }
263
-
264
- assert.hasProperty(mbResult, 'status', 'Mailbox check should return status');
265
-
266
- state.sendgridAdded = response.data?.providers?.campaigns?.success;
267
- state.beehiivAdded = response.data?.providers?.newsletter?.success;
268
- },
269
-
270
- async cleanup({ state, http }) {
271
- if (!state.testEmail) {
272
- return;
273
- }
274
-
275
- await http.delete('backend-manager/marketing/contact', { email: state.testEmail });
276
- },
277
- },
278
-
279
- // Test 9: Mailbox verification rejects invalid email (only runs if TEST_EXTENDED_MODE and a mailbox API key are set)
280
- {
281
- name: 'add-mailbox-rejects-invalid',
282
- auth: 'admin',
283
- timeout: 30000,
284
- skip: !process.env.TEST_EXTENDED_MODE || !(process.env.NEVERBOUNCE_API_KEY || process.env.ZEROBOUNCE_API_KEY)
285
- ? 'TEST_EXTENDED_MODE or mailbox API key not set'
286
- : false,
287
-
288
- async run({ http, assert, skip }) {
289
- // Email that should reach the mailbox provider and be flagged as undeliverable.
290
- // Must NOT trip earlier checks (localPart blocklist, disposable, corporate).
291
- const testEmail = TEST_EMAILS.invalid();
292
-
293
- const response = await http.post('backend-manager/marketing/contact', {
294
- email: testEmail,
295
- source: 'bem-test',
296
- });
297
-
298
- // With no ZeroBounce credits the route fails-open and returns 200; with credits
299
- // the route should EITHER succeed (200) and report invalid in checks, OR error
300
- // (400) with "Email validation failed". Either is correct behavior — what we
301
- // verify here is that mailbox check ran and didn't mark the email as `valid`.
302
- const mbResult = response.data?.validation?.checks?.mailbox;
303
-
304
- // If credits are out, the test can't actually exercise rejection — skip.
305
- if (mbResult?.error?.includes('out of credits') || mbResult?.error?.includes('Invalid API key')) {
306
- skip('Mailbox verification out of credits');
307
- }
308
-
309
- // If the response was a 400, that's the legitimate rejection path — done.
310
- if (response.status === 400) {
311
- return;
312
- }
313
-
314
- // Otherwise expect a 200 with a non-"valid" mailbox status.
315
- assert.isSuccess(response, 'Request should succeed (fail-open) or error 400');
316
- if (mbResult) {
317
- assert.hasProperty(mbResult, 'status', 'Should have status');
318
- assert.notEqual(mbResult.status, 'valid', 'Fake email should not be marked valid');
319
- }
320
- },
321
- },
322
-
323
- // --- Auth rejection tests ---
324
- {
325
- name: 'add-unauthenticated-rejected',
326
- auth: 'none',
327
- timeout: 15000,
328
-
329
- async run({ http, assert }) {
330
- // Public request without auth must be rejected. The exact rejection mechanism
331
- // depends on environment:
332
- // - Production: missing reCAPTCHA token → 403
333
- // - Local emulator (BEM_TESTING=true): reCAPTCHA is bypassed, but unauthenticated
334
- // users hit the marketing-subscribe rate limit (quota 0/0) → 429
335
- // Both are correct: the route protects itself from anonymous abuse. Accept either.
336
- const response = await http.post('backend-manager/marketing/contact', {
337
- email: TEST_EMAILS.valid(),
338
- source: 'bem-test',
339
- });
340
-
341
- assert.ok(!response.success, 'Public request should be rejected');
342
- assert.ok(
343
- response.status === 403 || response.status === 429,
344
- `Expected 403 or 429 but got ${response.status}`
345
- );
346
- },
347
- },
348
-
349
- // --- DELETE /marketing/contact tests ---
350
-
351
- // Test: Final cleanup (runs last to clean up test contacts from providers)
352
- {
353
- name: 'delete-cleanup-test-contacts',
354
- auth: 'admin',
355
- timeout: 30000,
356
- skip: !process.env.TEST_EXTENDED_MODE ? 'TEST_EXTENDED_MODE not set' : false,
357
-
358
- async run({ http, assert }) {
359
- // Clean up the rachel.greene+bem test contact from marketing providers
360
- const testEmail = TEST_EMAILS.valid();
361
-
362
- const response = await http.delete('backend-manager/marketing/contact', {
363
- email: testEmail,
364
- });
365
-
366
- assert.isSuccess(response, 'Remove marketing contact should succeed');
367
- },
368
- },
369
- ],
370
- };