mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-05-07 05:32:45 +08:00
test: add E2E tests for auto-reply settings (#868)
* test: add E2E tests for auto-reply settings Add auto-reply.spec.ts with two test cases: - GET empty → POST save → GET verify saved fields - POST with too-long subject returns 400 Enable ENABLE_AUTO_REPLY in E2E wrangler config. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * test: add full fields and body assertion for too-long validation per review Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -12,7 +12,7 @@ JWT_SECRET = "e2e-test-secret-key"
|
||||
BLACK_LIST = ""
|
||||
ENABLE_USER_CREATE_EMAIL = true
|
||||
ENABLE_USER_DELETE_EMAIL = true
|
||||
ENABLE_AUTO_REPLY = false
|
||||
ENABLE_AUTO_REPLY = true
|
||||
DEFAULT_SEND_BALANCE = 10
|
||||
ENABLE_ADDRESS_PASSWORD = true
|
||||
DISABLE_ADMIN_PASSWORD_CHECK = true
|
||||
|
||||
73
e2e/tests/api/auto-reply.spec.ts
Normal file
73
e2e/tests/api/auto-reply.spec.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { WORKER_URL, createTestAddress, deleteAddress } from '../../fixtures/test-helpers';
|
||||
|
||||
test.describe('Auto Reply Settings', () => {
|
||||
test('get empty, save, then verify saved settings', async ({ request }) => {
|
||||
const { jwt } = await createTestAddress(request, 'auto-reply');
|
||||
|
||||
try {
|
||||
// GET auto_reply — should return empty object for new address
|
||||
const emptyRes = await request.get(`${WORKER_URL}/api/auto_reply`, {
|
||||
headers: { Authorization: `Bearer ${jwt}` },
|
||||
});
|
||||
expect(emptyRes.ok()).toBe(true);
|
||||
const empty = await emptyRes.json();
|
||||
expect(Object.keys(empty)).toHaveLength(0);
|
||||
|
||||
// POST save auto_reply settings
|
||||
const saveRes = await request.post(`${WORKER_URL}/api/auto_reply`, {
|
||||
headers: { Authorization: `Bearer ${jwt}` },
|
||||
data: {
|
||||
auto_reply: {
|
||||
name: 'Test Bot',
|
||||
subject: 'Auto Reply',
|
||||
source_prefix: 'Re:',
|
||||
message: 'Thanks for your email!',
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(saveRes.ok()).toBe(true);
|
||||
const saveBody = await saveRes.json();
|
||||
expect(saveBody.success).toBe(true);
|
||||
|
||||
// GET auto_reply — should return saved settings
|
||||
const savedRes = await request.get(`${WORKER_URL}/api/auto_reply`, {
|
||||
headers: { Authorization: `Bearer ${jwt}` },
|
||||
});
|
||||
expect(savedRes.ok()).toBe(true);
|
||||
const saved = await savedRes.json();
|
||||
expect(saved.name).toBe('Test Bot');
|
||||
expect(saved.subject).toBe('Auto Reply');
|
||||
expect(saved.source_prefix).toBe('Re:');
|
||||
expect(saved.message).toBe('Thanks for your email!');
|
||||
expect(saved.enabled).toBe(true);
|
||||
} finally {
|
||||
await deleteAddress(request, jwt);
|
||||
}
|
||||
});
|
||||
|
||||
test('save with too long subject returns 400', async ({ request }) => {
|
||||
const { jwt } = await createTestAddress(request, 'auto-reply-long');
|
||||
|
||||
try {
|
||||
const saveRes = await request.post(`${WORKER_URL}/api/auto_reply`, {
|
||||
headers: { Authorization: `Bearer ${jwt}` },
|
||||
data: {
|
||||
auto_reply: {
|
||||
name: 'Bot',
|
||||
subject: 'x'.repeat(256),
|
||||
source_prefix: '',
|
||||
message: 'Hello',
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(saveRes.status()).toBe(400);
|
||||
const body = await saveRes.text();
|
||||
expect(body).toContain('too long');
|
||||
} finally {
|
||||
await deleteAddress(request, jwt);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user