backend-manager 5.9.7 → 5.9.9
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.
- package/package.json +5 -3
- package/src/cli/commands/setup-tests/bem-config.js +3 -2
- package/src/cli/commands/setup-tests/helpers.js +5 -0
- package/src/cli/commands/setup-tests/project-id-consistency.js +2 -1
- package/src/test/fixtures/firebase-project/.temp/test-mode.json +1 -1
- package/src/test/fixtures/firebase-project/database-debug.log +8 -8
- package/src/test/fixtures/firebase-project/firestore-debug.log +57 -55
- package/src/test/fixtures/firebase-project/pubsub-debug.log +3 -3
- package/templates/_.env +42 -0
- package/templates/_.gitignore +60 -0
- package/templates/backend-manager-config.json +249 -0
- package/templates/database.rules.json +83 -0
- package/templates/firebase.json +66 -0
- package/templates/firestore.indexes.json +4 -0
- package/templates/firestore.rules +112 -0
- package/templates/public/404.html +26 -0
- package/templates/public/index.html +24 -0
- package/templates/remoteconfig.template.json +1 -0
- package/templates/storage-lifecycle-config-1-day.json +9 -0
- package/templates/storage-lifecycle-config-30-days.json +9 -0
- package/templates/storage.rules +8 -0
- package/test/_init/accounts-validation.js +58 -0
- package/test/_legacy/ai/index.js +231 -0
- package/test/_legacy/ai/test.jpg +0 -0
- package/test/_legacy/ai/test.pdf +0 -0
- package/test/_legacy/index.js +31 -0
- package/test/_legacy/payment-resolver/chargebee/orders/refunded.json +0 -0
- package/test/_legacy/payment-resolver/chargebee/orders/unpaid.json +98 -0
- package/test/_legacy/payment-resolver/chargebee/subscriptions/active.json +578 -0
- package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-in-trial.json +38 -0
- package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-skipped-to-active.json +135 -0
- package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-active-to-cancelled.json +42 -0
- package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-active.json +44 -0
- package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-cancelled.json +39 -0
- package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-refund.json +143 -0
- package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-suspended.json +48 -0
- package/test/_legacy/payment-resolver/coinbase/orders/regular.json +204 -0
- package/test/_legacy/payment-resolver/coinbase/subscriptions/cancelled.json +204 -0
- package/test/_legacy/payment-resolver/coinbase/subscriptions/paid-2.json +125 -0
- package/test/_legacy/payment-resolver/index.js +1558 -0
- package/test/_legacy/payment-resolver/paypal/orders/refunded.json +0 -0
- package/test/_legacy/payment-resolver/paypal/orders/regular.json +120 -0
- package/test/_legacy/payment-resolver/paypal/subscriptions/active-refund-previous-stmnt.json +323 -0
- package/test/_legacy/payment-resolver/paypal/subscriptions/active.json +192 -0
- package/test/_legacy/payment-resolver/paypal/subscriptions/trial-in-trial.json +125 -0
- package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-not-complete.json +76 -0
- package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-overdue-2.json +114 -0
- package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-overdue.json +114 -0
- package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-active-to-cancelled.json +111 -0
- package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-active.json +132 -0
- package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-cancelled.json +107 -0
- package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-expired.json +91 -0
- package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-refund.json +147 -0
- package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-suspended.json +120 -0
- package/test/_legacy/payment-resolver/stripe/orders/refunded.json +0 -0
- package/test/_legacy/payment-resolver/stripe/orders/regular.json +91 -0
- package/test/_legacy/payment-resolver/stripe/subscriptions/active.json +421 -0
- package/test/_legacy/payment-resolver/stripe/subscriptions/trial-in-trial.json +349 -0
- package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-active-failed-authorization.json +430 -0
- package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-active.json +319 -0
- package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-cancelled.json +319 -0
- package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-refund.json +414 -0
- package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-suspended.json +319 -0
- package/test/_legacy/payment-resolver/stripe/subscriptions/unsure.json +339 -0
- package/test/_legacy/test-new +1178 -0
- package/test/_legacy/test.md +89 -0
- package/test/_legacy/usage.js +175 -0
- package/test/_legacy/user.js +31 -0
- package/test/ai/tools-live.js +170 -0
- package/test/boot/emulator-boots.js +37 -0
- package/test/content/blog-generate.js +160 -0
- package/test/email/campaign-send.js +45 -0
- package/test/email/consent-lifecycle.js +257 -0
- package/test/email/feedback-and-plain-send.js +52 -0
- package/test/email/fixtures/clean.json +30 -0
- package/test/email/fixtures/editorial.json +30 -0
- package/test/email/fixtures/field-report.json +53 -0
- package/test/email/marketing-lifecycle.js +132 -0
- package/test/email/newsletter-generate.js +819 -0
- package/test/email/newsletter-templates.js +491 -0
- package/test/email/templates.js +207 -0
- package/test/email/transactional-send.js +34 -0
- package/test/email/transactional.js +560 -0
- package/test/email/validation.js +710 -0
- package/test/events/auth-delete-race.js +201 -0
- package/test/events/payments/journey-payments-cancel-endpoint.js +100 -0
- package/test/events/payments/journey-payments-cancel.js +182 -0
- package/test/events/payments/journey-payments-discount.js +89 -0
- package/test/events/payments/journey-payments-failure.js +146 -0
- package/test/events/payments/journey-payments-legacy-product.js +149 -0
- package/test/events/payments/journey-payments-one-time-failure.js +111 -0
- package/test/events/payments/journey-payments-one-time.js +136 -0
- package/test/events/payments/journey-payments-plan-change.js +144 -0
- package/test/events/payments/journey-payments-refund-webhook.js +180 -0
- package/test/events/payments/journey-payments-suspend.js +181 -0
- package/test/events/payments/journey-payments-trial-cancel.js +130 -0
- package/test/events/payments/journey-payments-trial.js +171 -0
- package/test/events/payments/journey-payments-uid-resolution.js +132 -0
- package/test/events/payments/journey-payments-upgrade.js +135 -0
- package/test/fixtures/chargebee/invoice-one-time.json +27 -0
- package/test/fixtures/chargebee/subscription-active.json +44 -0
- package/test/fixtures/chargebee/subscription-cancelled.json +42 -0
- package/test/fixtures/chargebee/subscription-in-trial.json +41 -0
- package/test/fixtures/chargebee/subscription-legacy-plan.json +41 -0
- package/test/fixtures/chargebee/subscription-non-renewing.json +41 -0
- package/test/fixtures/chargebee/subscription-paused.json +42 -0
- package/test/fixtures/chargebee/webhook-payment-failed.json +51 -0
- package/test/fixtures/chargebee/webhook-subscription-created.json +47 -0
- package/test/fixtures/paypal/order-approved.json +62 -0
- package/test/fixtures/paypal/order-completed.json +110 -0
- package/test/fixtures/paypal/subscription-active.json +76 -0
- package/test/fixtures/paypal/subscription-cancelled.json +50 -0
- package/test/fixtures/paypal/subscription-suspended.json +65 -0
- package/test/fixtures/stripe/checkout-session-completed.json +130 -0
- package/test/fixtures/stripe/invoice-payment-failed.json +148 -0
- package/test/fixtures/stripe/invoice-subscription-payment-failed.json +28 -0
- package/test/fixtures/stripe/subscription-active.json +161 -0
- package/test/fixtures/stripe/subscription-canceled.json +161 -0
- package/test/fixtures/stripe/subscription-trialing.json +161 -0
- package/test/functions/admin/database-read.js +134 -0
- package/test/functions/admin/database-write.js +159 -0
- package/test/functions/admin/edit-post.js +366 -0
- package/test/functions/admin/firestore-query.js +207 -0
- package/test/functions/admin/firestore-read.js +129 -0
- package/test/functions/admin/firestore-write.js +105 -0
- package/test/functions/admin/get-stats.js +115 -0
- package/test/functions/admin/send-email.js +119 -0
- package/test/functions/admin/send-notification.js +208 -0
- package/test/functions/admin/write-repo-content.js +223 -0
- package/test/functions/general/add-marketing-contact.js +335 -0
- package/test/functions/general/fetch-post.js +54 -0
- package/test/functions/general/generate-uuid.js +114 -0
- package/test/functions/test/authenticate.js +64 -0
- package/test/functions/user/create-custom-token.js +73 -0
- package/test/functions/user/delete.js +135 -0
- package/test/functions/user/get-active-sessions.js +111 -0
- package/test/functions/user/get-subscription-info.js +99 -0
- package/test/functions/user/regenerate-api-keys.js +156 -0
- package/test/functions/user/resolve.js +52 -0
- package/test/functions/user/sign-out-all-sessions.js +94 -0
- package/test/functions/user/sign-up.js +252 -0
- package/test/functions/user/submit-feedback.js +104 -0
- package/test/functions/user/validate-settings.js +82 -0
- package/test/helpers/ai-request-payload.js +300 -0
- package/test/helpers/ai-test-provider.js +202 -0
- package/test/helpers/ai-tools-format.js +383 -0
- package/test/helpers/content/blog-auto-publisher.js +484 -0
- package/test/helpers/content/feed-parser.js +528 -0
- package/test/helpers/content/ghostii-blocks.js +134 -0
- package/test/helpers/content/ghostii-feed-integration.js +404 -0
- package/test/helpers/content/ghostii-write-article.js +243 -0
- package/test/helpers/environment.js +230 -0
- package/test/helpers/infer-contact.js +113 -0
- package/test/helpers/merge-line-files.js +271 -0
- package/test/helpers/payment/chargebee/parse-webhook.js +413 -0
- package/test/helpers/payment/chargebee/to-unified-one-time.js +147 -0
- package/test/helpers/payment/chargebee/to-unified-subscription.js +648 -0
- package/test/helpers/payment/paypal/parse-webhook.js +539 -0
- package/test/helpers/payment/paypal/to-unified-one-time.js +382 -0
- package/test/helpers/payment/paypal/to-unified-subscription.js +820 -0
- package/test/helpers/payment/stripe/parse-webhook.js +447 -0
- package/test/helpers/payment/stripe/to-unified-one-time.js +306 -0
- package/test/helpers/payment/stripe/to-unified-subscription.js +708 -0
- package/test/helpers/sanitize.js +222 -0
- package/test/helpers/slugify.js +394 -0
- package/test/helpers/storage.js +194 -0
- package/test/helpers/user.js +755 -0
- package/test/helpers/webhook-forward.js +418 -0
- package/test/mcp/discovery.js +53 -0
- package/test/mcp/oauth.js +161 -0
- package/test/mcp/protocol.js +268 -0
- package/test/mcp/roles.js +188 -0
- package/test/mcp/utils.js +245 -0
- package/test/routes/admin/create-post.js +364 -0
- package/test/routes/admin/database.js +131 -0
- package/test/routes/admin/deduplicate-image-alts.js +190 -0
- package/test/routes/admin/email.js +114 -0
- package/test/routes/admin/firestore-query.js +204 -0
- package/test/routes/admin/firestore.js +127 -0
- package/test/routes/admin/infer-contact.js +218 -0
- package/test/routes/admin/notification.js +198 -0
- package/test/routes/admin/post-resize-image.js +184 -0
- package/test/routes/admin/post.js +368 -0
- package/test/routes/admin/repo-content.js +223 -0
- package/test/routes/admin/stats.js +112 -0
- package/test/routes/content/post.js +54 -0
- package/test/routes/general/uuid.js +115 -0
- package/test/routes/marketing/campaign.js +125 -0
- package/test/routes/marketing/contact.js +370 -0
- package/test/routes/marketing/email-preferences.js +292 -0
- package/test/routes/marketing/push-send.js +32 -0
- package/test/routes/marketing/webhook-forward.js +61 -0
- package/test/routes/marketing/webhook.js +639 -0
- package/test/routes/payments/cancel.js +163 -0
- package/test/routes/payments/discount.js +80 -0
- package/test/routes/payments/dispute-alert.js +320 -0
- package/test/routes/payments/intent.js +336 -0
- package/test/routes/payments/portal.js +92 -0
- package/test/routes/payments/refund.js +179 -0
- package/test/routes/payments/trial-eligibility.js +71 -0
- package/test/routes/payments/webhook.js +107 -0
- package/test/routes/test/authenticate.js +59 -0
- package/test/routes/test/schema.js +554 -0
- package/test/routes/test/usage.js +342 -0
- package/test/routes/user/api-keys.js +156 -0
- package/test/routes/user/delete.js +136 -0
- package/test/routes/user/feedback.js +104 -0
- package/test/routes/user/sessions.js +199 -0
- package/test/routes/user/settings-validate.js +82 -0
- package/test/routes/user/signup.js +542 -0
- package/test/routes/user/subscription.js +99 -0
- package/test/routes/user/token.js +73 -0
- package/test/routes/user/user.js +157 -0
- package/test/rules/notifications.js +410 -0
- package/test/rules/payments-carts.js +371 -0
- package/test/rules/user.js +396 -0
|
@@ -0,0 +1,114 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,204 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,218 @@
|
|
|
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
|
+
};
|