From e115b992710d0f6ba7a7da56d127926456468d66 Mon Sep 17 00:00:00 2001 From: Bowl42 Date: Thu, 5 Mar 2026 22:09:17 +0800 Subject: [PATCH] test: add E2E test for clearing sent items (#867) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * test: add E2E test for clearing sent items Add clear-sent.spec.ts verifying: - Send a mail → verify it appears in sendbox → clear sent items → verify sendbox is empty Co-Authored-By: Claude Opus 4.6 * test: remove unused address variable Co-Authored-By: Claude Opus 4.6 --------- Co-authored-by: Claude Opus 4.6 --- e2e/tests/api/clear-sent.spec.ts | 69 ++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 e2e/tests/api/clear-sent.spec.ts diff --git a/e2e/tests/api/clear-sent.spec.ts b/e2e/tests/api/clear-sent.spec.ts new file mode 100644 index 00000000..2afc4213 --- /dev/null +++ b/e2e/tests/api/clear-sent.spec.ts @@ -0,0 +1,69 @@ +import { test, expect } from '@playwright/test'; +import { + WORKER_URL, + createTestAddress, + deleteAddress, + deleteAllMailpitMessages, + requestSendAccess, + onMailpitMessage, +} from '../../fixtures/test-helpers'; + +test.describe('Clear Sent Items', () => { + test.beforeEach(async ({ request }) => { + await deleteAllMailpitMessages(request); + }); + + test('send mail then clear sent items', async ({ request }) => { + const { jwt } = await createTestAddress(request, 'clear-sent'); + await requestSendAccess(request, jwt); + + try { + const subject = `Clear Sent Test ${Date.now()}`; + + // Listen before sending + const listener = onMailpitMessage((m) => m.Subject === subject); + await listener.ready; + + // Send a mail + const sendRes = await request.post(`${WORKER_URL}/api/send_mail`, { + headers: { Authorization: `Bearer ${jwt}` }, + data: { + from_name: 'Sender', + to_name: 'Recipient', + to_mail: 'recipient@test.example.com', + subject, + content: '

test

', + is_html: true, + }, + }); + expect(sendRes.ok()).toBe(true); + await listener.message; + + // Verify sendbox has 1 item + const listRes = await request.get(`${WORKER_URL}/api/sendbox?limit=10&offset=0`, { + headers: { Authorization: `Bearer ${jwt}` }, + }); + expect(listRes.ok()).toBe(true); + const { results } = await listRes.json(); + expect(results.length).toBeGreaterThanOrEqual(1); + + // Clear sent items + const clearRes = await request.delete(`${WORKER_URL}/api/clear_sent_items`, { + headers: { Authorization: `Bearer ${jwt}` }, + }); + expect(clearRes.ok()).toBe(true); + const clearBody = await clearRes.json(); + expect(clearBody.success).toBe(true); + + // Verify sendbox is empty + const afterRes = await request.get(`${WORKER_URL}/api/sendbox?limit=10&offset=0`, { + headers: { Authorization: `Bearer ${jwt}` }, + }); + expect(afterRes.ok()).toBe(true); + const after = await afterRes.json(); + expect(after.results).toHaveLength(0); + } finally { + await deleteAddress(request, jwt); + } + }); +});