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,114 +0,0 @@
1
- /**
2
- * Test: POST /admin/email
3
- * Route-level tests: auth, permissions, HTTP status codes, basic send/queue
4
- *
5
- * Library-level tests (validation, dedup, recipients, features) are in test/helpers/email.js
6
- */
7
- module.exports = {
8
- description: 'Admin send email (route)',
9
- type: 'group',
10
- skip: !process.env.TEST_EXTENDED_MODE ? 'TEST_EXTENDED_MODE env var not set (skipping email tests)' : false,
11
- tests: [
12
- // --- Auth / Permissions ---
13
-
14
- {
15
- name: 'unauthenticated-rejected',
16
- auth: 'none',
17
- timeout: 15000,
18
-
19
- async run({ http, assert, config }) {
20
- const response = await http.post('backend-manager/admin/email', {
21
- subject: 'Test Email',
22
- to: [{ email: `_test-receiver@${config.domain}` }],
23
- });
24
-
25
- assert.isError(response, 401, 'Send email should fail without authentication');
26
- },
27
- },
28
-
29
- {
30
- name: 'non-admin-rejected',
31
- auth: 'basic',
32
- timeout: 15000,
33
-
34
- async run({ http, assert, config }) {
35
- const response = await http.post('backend-manager/admin/email', {
36
- subject: 'Test Email',
37
- to: [{ email: `_test-receiver@${config.domain}` }],
38
- });
39
-
40
- assert.isError(response, 403, 'Send email should fail for non-admin user');
41
- },
42
- },
43
-
44
- // --- Basic Validation ---
45
-
46
- {
47
- name: 'missing-subject-rejected',
48
- auth: 'admin',
49
- timeout: 15000,
50
-
51
- async run({ http, assert, config }) {
52
- const response = await http.post('backend-manager/admin/email', {
53
- to: [{ email: `_test-receiver@${config.domain}` }],
54
- copy: false,
55
- });
56
-
57
- assert.isError(response, 400, 'Missing subject should return 400');
58
- },
59
- },
60
-
61
- // --- Happy Path ---
62
-
63
- {
64
- name: 'status-sent',
65
- auth: 'admin',
66
- timeout: 30000,
67
-
68
- async run({ http, assert, config }) {
69
- const response = await http.post('backend-manager/admin/email', {
70
- subject: 'BEM Test Email - Status Sent',
71
- to: [{ email: `_test-receiver@${config.domain}`, name: 'Test Receiver' }],
72
- copy: false,
73
- data: {
74
- email: {
75
- subject: 'BEM Test Email - Status Sent',
76
- body: 'This is a test email from BEM tests (status: sent).',
77
- },
78
- },
79
- });
80
-
81
- assert.isSuccess(response, 'Admin should be able to send email');
82
- assert.hasProperty(response, 'data.status', 'Response should have status');
83
- assert.equal(response.data.status, 'sent', 'Status should be sent');
84
- },
85
- },
86
-
87
- {
88
- name: 'status-queued',
89
- auth: 'admin',
90
- timeout: 30000,
91
-
92
- async run({ http, assert, config }) {
93
- const sendAt = Math.floor(Date.now() / 1000) + (72 * 60 * 60);
94
-
95
- const response = await http.post('backend-manager/admin/email', {
96
- subject: 'BEM Test Email - Status Queued',
97
- to: [{ email: `_test-receiver@${config.domain}`, name: 'Test Receiver' }],
98
- copy: false,
99
- sendAt: sendAt,
100
- data: {
101
- email: {
102
- subject: 'BEM Test Email - Status Queued',
103
- body: 'This is a test email scheduled for later (status: queued).',
104
- },
105
- },
106
- });
107
-
108
- assert.isSuccess(response, 'Admin should be able to queue email');
109
- assert.hasProperty(response, 'data.status', 'Response should have status');
110
- assert.equal(response.data.status, 'queued', 'Status should be queued when sendAt is beyond 71 hours');
111
- },
112
- },
113
- ],
114
- };
@@ -1,204 +0,0 @@
1
- /**
2
- * Test: POST /admin/firestore/query
3
- * Tests the admin Firestore query endpoint
4
- * Requires admin authentication
5
- */
6
- const TEST_COLLECTION = '_test_query';
7
-
8
- module.exports = {
9
- description: 'Admin Firestore query operation',
10
- type: 'suite',
11
- timeout: 30000,
12
-
13
- tests: [
14
- // Test 1: Setup - write test documents
15
- {
16
- name: 'setup-test-documents',
17
- async run({ http, assert, state }) {
18
- state.testDocs = [
19
- { name: 'doc1', category: 'alpha', value: 10 },
20
- { name: 'doc2', category: 'alpha', value: 20 },
21
- { name: 'doc3', category: 'beta', value: 30 },
22
- ];
23
-
24
- for (let i = 0; i < state.testDocs.length; i++) {
25
- const doc = state.testDocs[i];
26
- const response = await http.as('admin').post('backend-manager/admin/firestore', {
27
- path: `${TEST_COLLECTION}/doc${i + 1}`,
28
- document: doc,
29
- });
30
- assert.isSuccess(response, `Setup: Writing doc${i + 1} should succeed`);
31
- }
32
- },
33
- },
34
-
35
- // Test 2: Query all documents in collection
36
- {
37
- name: 'query-all-documents',
38
- async run({ http, assert, state }) {
39
- const queryResponse = await http.as('admin').post('backend-manager/admin/firestore/query', {
40
- queries: [
41
- { collection: TEST_COLLECTION },
42
- ],
43
- });
44
-
45
- assert.isSuccess(queryResponse, 'Query should succeed');
46
- assert.ok(
47
- Array.isArray(queryResponse.data),
48
- 'Response should be an array'
49
- );
50
- assert.ok(
51
- queryResponse.data.length >= 3,
52
- `Should find at least 3 documents, found ${queryResponse.data.length}`
53
- );
54
- },
55
- },
56
-
57
- // Test 3: Query with where clause
58
- {
59
- name: 'query-with-where',
60
- async run({ http, assert }) {
61
- const queryResponse = await http.as('admin').post('backend-manager/admin/firestore/query', {
62
- queries: [
63
- {
64
- collection: TEST_COLLECTION,
65
- where: [
66
- { field: 'category', operator: '==', value: 'alpha' },
67
- ],
68
- },
69
- ],
70
- });
71
-
72
- assert.isSuccess(queryResponse, 'Query with where should succeed');
73
- assert.ok(
74
- Array.isArray(queryResponse.data),
75
- 'Response should be an array'
76
- );
77
- assert.equal(
78
- queryResponse.data.length,
79
- 2,
80
- 'Should find exactly 2 alpha documents'
81
- );
82
-
83
- queryResponse.data.forEach(doc => {
84
- assert.equal(doc.data.category, 'alpha', 'All results should be category alpha');
85
- });
86
- },
87
- },
88
-
89
- // Test 4: Query with limit
90
- {
91
- name: 'query-with-limit',
92
- async run({ http, assert }) {
93
- const queryResponse = await http.as('admin').post('backend-manager/admin/firestore/query', {
94
- queries: [
95
- {
96
- collection: TEST_COLLECTION,
97
- limit: 2,
98
- },
99
- ],
100
- });
101
-
102
- assert.isSuccess(queryResponse, 'Query with limit should succeed');
103
- assert.ok(
104
- queryResponse.data.length <= 2,
105
- `Should return at most 2 documents, got ${queryResponse.data.length}`
106
- );
107
- },
108
- },
109
-
110
- // Test 5: Query with orderBy
111
- {
112
- name: 'query-with-orderBy',
113
- async run({ http, assert }) {
114
- const queryResponse = await http.as('admin').post('backend-manager/admin/firestore/query', {
115
- queries: [
116
- {
117
- collection: TEST_COLLECTION,
118
- orderBy: [
119
- { field: 'value', order: 'desc' },
120
- ],
121
- },
122
- ],
123
- });
124
-
125
- assert.isSuccess(queryResponse, 'Query with orderBy should succeed');
126
- assert.ok(
127
- Array.isArray(queryResponse.data) && queryResponse.data.length >= 2,
128
- 'Should have at least 2 results to verify order'
129
- );
130
-
131
- for (let i = 0; i < queryResponse.data.length - 1; i++) {
132
- assert.ok(
133
- queryResponse.data[i].data.value >= queryResponse.data[i + 1].data.value,
134
- 'Results should be in descending order by value'
135
- );
136
- }
137
- },
138
- },
139
-
140
- // Test 6: Query with empty collection returns empty array
141
- {
142
- name: 'query-empty-collection',
143
- async run({ http, assert }) {
144
- const queryResponse = await http.as('admin').post('backend-manager/admin/firestore/query', {
145
- queries: [
146
- { collection: '_test_nonexistent_collection_12345' },
147
- ],
148
- });
149
-
150
- assert.isSuccess(queryResponse, 'Query on empty collection should succeed');
151
- assert.ok(
152
- Array.isArray(queryResponse.data),
153
- 'Response should be an array'
154
- );
155
- assert.equal(
156
- queryResponse.data.length,
157
- 0,
158
- 'Empty collection should return empty array'
159
- );
160
- },
161
- },
162
-
163
- // Test 7: Query with no collection specified returns empty
164
- {
165
- name: 'query-no-collection',
166
- async run({ http, assert }) {
167
- const queryResponse = await http.as('admin').post('backend-manager/admin/firestore/query', {
168
- queries: [{}],
169
- });
170
-
171
- assert.isSuccess(queryResponse, 'Query with no collection should succeed (returns empty)');
172
- assert.ok(
173
- Array.isArray(queryResponse.data),
174
- 'Response should be an array'
175
- );
176
- },
177
- },
178
-
179
- // Test 8: Unauthenticated request fails
180
- {
181
- name: 'unauthenticated-rejected',
182
- async run({ http, assert }) {
183
- const queryResponse = await http.as('none').post('backend-manager/admin/firestore/query', {
184
- queries: [{ collection: TEST_COLLECTION }],
185
- });
186
-
187
- assert.isError(queryResponse, 401, 'Query should fail without authentication');
188
- },
189
- },
190
-
191
- // Test 9: Non-admin user fails
192
- {
193
- name: 'non-admin-rejected',
194
- async run({ http, assert }) {
195
- const queryResponse = await http.as('basic').post('backend-manager/admin/firestore/query', {
196
- queries: [{ collection: TEST_COLLECTION }],
197
- });
198
-
199
- assert.isError(queryResponse, 403, 'Query should fail for non-admin user');
200
- },
201
- },
202
-
203
- ],
204
- };
@@ -1,127 +0,0 @@
1
- /**
2
- * Test: GET/POST /admin/firestore
3
- * Tests the admin Firestore read/write endpoints
4
- * Requires admin authentication
5
- */
6
- const TEST_PATH = '_test/firestore-test-doc';
7
-
8
- module.exports = {
9
- description: 'Admin Firestore read/write operations',
10
- type: 'group',
11
- tests: [
12
- // Test 1: Setup - write a test document first
13
- {
14
- name: 'setup-test-document',
15
- auth: 'admin',
16
- timeout: 15000,
17
-
18
- async run({ http, assert }) {
19
- const testData = {
20
- testField: 'read-test-value',
21
- timestamp: new Date().toISOString(),
22
- nested: {
23
- field1: 'nested-value',
24
- field2: 42,
25
- },
26
- };
27
-
28
- const writeResponse = await http.post('backend-manager/admin/firestore', {
29
- path: TEST_PATH,
30
- document: testData,
31
- });
32
-
33
- assert.isSuccess(writeResponse, 'Setup: Firestore write should succeed');
34
- },
35
- },
36
-
37
- // Test 2: Admin can read document
38
- {
39
- name: 'admin-read-succeeds',
40
- auth: 'admin',
41
- timeout: 15000,
42
-
43
- async run({ http, assert }) {
44
- const readResponse = await http.get('backend-manager/admin/firestore', {
45
- path: TEST_PATH,
46
- });
47
-
48
- assert.isSuccess(readResponse, 'Firestore read should succeed with admin auth');
49
- assert.hasProperty(readResponse, 'data.testField', 'Response should contain test data');
50
- assert.equal(
51
- readResponse.data.testField,
52
- 'read-test-value',
53
- 'Read data should match written data'
54
- );
55
- assert.hasProperty(readResponse, 'data.nested.field1', 'Response should contain nested data');
56
- assert.equal(
57
- readResponse.data.nested.field2,
58
- 42,
59
- 'Nested field should match written data'
60
- );
61
- },
62
- },
63
-
64
- // Test 3: Reading non-existent document returns empty/undefined/null
65
- {
66
- name: 'read-nonexistent-returns-empty',
67
- auth: 'admin',
68
- timeout: 15000,
69
-
70
- async run({ http, assert }) {
71
- const readResponse = await http.get('backend-manager/admin/firestore', {
72
- path: '_test/nonexistent-document-12345',
73
- });
74
-
75
- assert.isSuccess(readResponse, 'Reading non-existent document should succeed');
76
- const isEmpty = readResponse.data === undefined
77
- || readResponse.data === null
78
- || (typeof readResponse.data === 'object' && Object.keys(readResponse.data).length === 0);
79
- assert.ok(isEmpty, 'Non-existent document should return undefined, null, or empty object');
80
- },
81
- },
82
-
83
- // Test 4: Missing path returns 400 error
84
- {
85
- name: 'missing-path-rejected',
86
- auth: 'admin',
87
- timeout: 15000,
88
-
89
- async run({ http, assert }) {
90
- const readResponse = await http.get('backend-manager/admin/firestore', {});
91
-
92
- assert.isError(readResponse, 400, 'Missing path should return 400');
93
- },
94
- },
95
-
96
- // Test 5: Unauthenticated request fails
97
- {
98
- name: 'unauthenticated-rejected',
99
- auth: 'none',
100
- timeout: 15000,
101
-
102
- async run({ http, assert }) {
103
- const readResponse = await http.get('backend-manager/admin/firestore', {
104
- path: TEST_PATH,
105
- });
106
-
107
- assert.isError(readResponse, 401, 'Firestore read should fail without authentication');
108
- },
109
- },
110
-
111
- // Test 6: Non-admin user fails
112
- {
113
- name: 'non-admin-rejected',
114
- auth: 'user',
115
- timeout: 15000,
116
-
117
- async run({ http, assert }) {
118
- const readResponse = await http.get('backend-manager/admin/firestore', {
119
- path: TEST_PATH,
120
- });
121
-
122
- assert.isError(readResponse, 403, 'Firestore read should fail for non-admin user');
123
- },
124
- },
125
-
126
- ],
127
- };
@@ -1,218 +0,0 @@
1
- /**
2
- * Test: POST /admin/infer-contact
3
- * Tests the admin infer-contact endpoint for inferring names from email addresses
4
- *
5
- * AI inference tests only run when TEST_EXTENDED_MODE is set (requires BACKEND_MANAGER_OPENAI_API_KEY)
6
- */
7
- module.exports = {
8
- description: 'Admin infer contact',
9
- type: 'group',
10
- tests: [
11
- // ─── Auth rejection ───
12
-
13
- {
14
- name: 'unauthenticated-rejected',
15
- auth: 'none',
16
- timeout: 15000,
17
-
18
- async run({ http, assert }) {
19
- const response = await http.post('backend-manager/admin/infer-contact', {
20
- email: 'john.smith@gmail.com',
21
- });
22
-
23
- assert.isError(response, 401, 'Should reject unauthenticated requests');
24
- },
25
- },
26
-
27
- {
28
- name: 'non-admin-rejected',
29
- auth: 'user',
30
- timeout: 15000,
31
-
32
- async run({ http, assert }) {
33
- const response = await http.post('backend-manager/admin/infer-contact', {
34
- email: 'john.smith@gmail.com',
35
- });
36
-
37
- assert.isError(response, 403, 'Should reject non-admin users');
38
- },
39
- },
40
-
41
- // ─── Single email ───
42
-
43
- {
44
- name: 'single-email-returns-result',
45
- auth: 'admin',
46
- timeout: 30000,
47
- skip: !process.env.TEST_EXTENDED_MODE
48
- ? 'TEST_EXTENDED_MODE not set (skipping inference test)'
49
- : false,
50
-
51
- async run({ http, assert }) {
52
- const response = await http.post('backend-manager/admin/infer-contact', {
53
- email: 'john.smith@gmail.com',
54
- });
55
-
56
- assert.isSuccess(response, 'Should succeed for admin');
57
- assert.hasProperty(response, 'data.results', 'Should have results array');
58
- assert.equal(response.data.results.length, 1, 'Should have 1 result');
59
-
60
- const result = response.data.results[0];
61
- assert.equal(result.email, 'john.smith@gmail.com', 'Should include email');
62
- assert.hasProperty(result, 'firstName', 'Should have firstName field');
63
- assert.hasProperty(result, 'lastName', 'Should have lastName field');
64
- assert.hasProperty(result, 'method', 'Should include method');
65
- assert.hasProperty(result, 'confidence', 'Should include confidence');
66
- assert.equal(result.method, 'ai', 'Should use AI method');
67
- },
68
- },
69
-
70
- // ─── Batch emails ───
71
-
72
- {
73
- name: 'batch-emails-returns-all-results',
74
- auth: 'admin',
75
- timeout: 60000,
76
-
77
- async run({ http, assert }) {
78
- const emails = [
79
- 'sarah.connor@skynet.io',
80
- 'bob-jones@hotmail.com',
81
- 'admin@acme.com',
82
- ];
83
-
84
- const response = await http.post('backend-manager/admin/infer-contact', { emails });
85
-
86
- assert.isSuccess(response, 'Should succeed for batch');
87
- assert.equal(response.data.results.length, 3, 'Should have 3 results');
88
-
89
- // Verify each email is in results
90
- for (let i = 0; i < emails.length; i++) {
91
- assert.equal(response.data.results[i].email, emails[i], `Result ${i} should match input email`);
92
- }
93
- },
94
- },
95
-
96
- // ─── Name parsing (requires AI) ───
97
-
98
- {
99
- name: 'regex-parses-dot-separated-names',
100
- auth: 'admin',
101
- timeout: 30000,
102
- skip: !process.env.TEST_EXTENDED_MODE
103
- ? 'TEST_EXTENDED_MODE not set (skipping inference test)'
104
- : false,
105
-
106
- async run({ http, assert }) {
107
- // Use a name unlikely to trigger the "fictional/brand" rejection in the AI prompt.
108
- // The infer-contact prompt rejects placeholder + fictional names (e.g. alice.wonderland,
109
- // john.doe). Use a generic-but-realistic name to exercise dot-separated parsing.
110
- const response = await http.post('backend-manager/admin/infer-contact', {
111
- email: 'sarah.martinez@example.com',
112
- });
113
-
114
- assert.isSuccess(response);
115
- const result = response.data.results[0];
116
-
117
- assert.equal(result.firstName, 'Sarah', 'Should parse first name');
118
- assert.equal(result.lastName, 'Martinez', 'Should parse last name');
119
- },
120
- },
121
-
122
- {
123
- name: 'infers-company-from-custom-domain',
124
- auth: 'admin',
125
- timeout: 30000,
126
- skip: !process.env.TEST_EXTENDED_MODE
127
- ? 'TEST_EXTENDED_MODE not set (skipping inference test)'
128
- : false,
129
-
130
- async run({ http, assert }) {
131
- const response = await http.post('backend-manager/admin/infer-contact', {
132
- email: 'ceo@my-startup.com',
133
- });
134
-
135
- assert.isSuccess(response);
136
- const result = response.data.results[0];
137
- assert.ok(result.company, 'Should infer company from custom domain');
138
- },
139
- },
140
-
141
- {
142
- name: 'no-company-from-generic-domain',
143
- auth: 'admin',
144
- timeout: 30000,
145
- skip: !process.env.TEST_EXTENDED_MODE
146
- ? 'TEST_EXTENDED_MODE not set (skipping inference test)'
147
- : false,
148
-
149
- async run({ http, assert }) {
150
- const response = await http.post('backend-manager/admin/infer-contact', {
151
- email: 'someone@gmail.com',
152
- });
153
-
154
- assert.isSuccess(response);
155
- const result = response.data.results[0];
156
- assert.equal(result.company, '', 'Should not infer company from gmail');
157
- },
158
- },
159
-
160
- // ─── AI inference (requires TEST_EXTENDED_MODE) ───
161
-
162
- {
163
- name: 'ai-inference',
164
- auth: 'admin',
165
- timeout: 60000,
166
- skip: !process.env.TEST_EXTENDED_MODE
167
- ? 'TEST_EXTENDED_MODE not set (skipping AI inference test)'
168
- : false,
169
-
170
- async run({ http, assert }) {
171
- const response = await http.post('backend-manager/admin/infer-contact', {
172
- emails: [
173
- 'john.smith@microsoft.com',
174
- 'xkcd42@gmail.com',
175
- 'bobs.burgers@example.com',
176
- ],
177
- });
178
-
179
- assert.isSuccess(response, 'AI inference should succeed');
180
-
181
- const results = response.data.results;
182
- assert.equal(results.length, 3, 'Should have 3 results');
183
-
184
- // Verify structure — AI may return empty names but shape must be correct
185
- for (const r of results) {
186
- assert.hasProperty(r, 'firstName', `${r.email}: should have firstName`);
187
- assert.hasProperty(r, 'lastName', `${r.email}: should have lastName`);
188
- assert.hasProperty(r, 'method', `${r.email}: should have method`);
189
- assert.hasProperty(r, 'confidence', `${r.email}: should have confidence`);
190
- }
191
-
192
- // john.smith@microsoft.com — AI should parse this but may flake
193
- const john = results.find(r => r.email === 'john.smith@microsoft.com');
194
- assert.equal(john.method, 'ai', 'Should use AI method');
195
- if (!john.firstName) {
196
- console.warn('AI flake: john.smith@microsoft.com returned empty firstName (non-fatal)');
197
- }
198
- },
199
- },
200
-
201
- // ─── Edge cases ───
202
-
203
- {
204
- name: 'empty-emails-array-returns-empty',
205
- auth: 'admin',
206
- timeout: 15000,
207
-
208
- async run({ http, assert }) {
209
- const response = await http.post('backend-manager/admin/infer-contact', {
210
- emails: [],
211
- });
212
-
213
- assert.isSuccess(response);
214
- assert.equal(response.data.results.length, 0, 'Empty input should return empty results');
215
- },
216
- },
217
- ],
218
- };