WIP: reference site — File field on the quote form, mail sink smoke test
Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
b7fb1b0e31
commit
387debc88c
@@ -1,5 +1,6 @@
|
||||
import { expect, type Page, test } from '@playwright/test'
|
||||
|
||||
import { attachmentOf, startSmtpSink } from './smtp-sink'
|
||||
import { totp } from './totp'
|
||||
|
||||
/**
|
||||
@@ -66,6 +67,72 @@ for (const l of LOCALES) {
|
||||
})
|
||||
}
|
||||
|
||||
// Files on forms (forms: { attachments: true }): e-mailed to the studio, never stored. A real browser, the real
|
||||
// endpoint and a local mail sink — the file must arrive as an attachment of the staff e-mail only.
|
||||
test.describe('the quote form sends a file by e-mail', () => {
|
||||
const PDF = Buffer.concat([Buffer.from('%PDF-1.7\n1 0 obj\n<<>>\nendobj\n%%EOF\n'), Buffer.alloc(200_000, 0x20)])
|
||||
let sink: Awaited<ReturnType<typeof startSmtpSink>>
|
||||
test.beforeAll(async () => {
|
||||
sink = await startSmtpSink(Number(process.env.E2E_SMTP_PORT ?? 2526))
|
||||
})
|
||||
test.afterAll(async () => {
|
||||
await sink.close()
|
||||
})
|
||||
|
||||
async function fillQuote(page: Page) {
|
||||
await page.goto('/en/quote')
|
||||
await rejectCookies(page)
|
||||
const form = page.locator('form[data-ipal="form"]').first()
|
||||
await form.locator('input[name="name"]').fill('Test Smoke')
|
||||
await form.locator('input[name="email"]').fill('[email protected]')
|
||||
await form.locator('button[type="submit"]').click() // Next
|
||||
await form.locator('input[name="scope"][value="building"]').check()
|
||||
await form.locator('input[name="area"][value="s"]').check()
|
||||
await form.locator('input[name="consent"]').check()
|
||||
return form
|
||||
}
|
||||
|
||||
test('a wrong file is refused at the field; a PDF arrives attached to the staff e-mail, not the customer one', async ({ page }) => {
|
||||
const form = await fillQuote(page)
|
||||
const input = form.locator('input[type="file"][name="attachment"]')
|
||||
await expect(input).toHaveAttribute('accept', /\.pdf/)
|
||||
|
||||
// a type the field does not accept: the message shows at once, by the field
|
||||
await input.setInputFiles({ buffer: Buffer.from('MZ'), mimeType: 'application/octet-stream', name: 'plan.exe' })
|
||||
await expect(form.locator('[id$="attachment-error"]')).toContainText('plan.exe')
|
||||
// keyboard: the Remove button is a real button — focus it and press Enter
|
||||
await form.getByRole('button', { name: /Remove plan\.exe/ }).focus()
|
||||
await page.keyboard.press('Enter')
|
||||
await expect(form.locator('[data-ipal="form-files"] li')).toHaveCount(0)
|
||||
|
||||
// a program renamed to .pdf passes the browser check and is stopped by the server (content, not name)
|
||||
await input.setInputFiles({ buffer: Buffer.concat([Buffer.from('MZ\x90\x00'), Buffer.alloc(2000)]), mimeType: 'application/pdf', name: 'plan.pdf' })
|
||||
await expect(form.locator('input[name="cf-turnstile-response"]')).not.toHaveValue('', { timeout: 15_000 })
|
||||
await form.locator('button[type="submit"]').click()
|
||||
await expect(form.locator('[id$="attachment-error"]')).toContainText('not an accepted file type', { timeout: 15_000 })
|
||||
expect(sink.messages).toHaveLength(0)
|
||||
|
||||
// the real file
|
||||
await input.setInputFiles({ buffer: PDF, mimeType: 'application/pdf', name: 'Floor plan (ground).pdf' })
|
||||
await expect(form.locator('[data-ipal="form-files"] li')).toContainText('Floor plan (ground).pdf')
|
||||
await expect(form.locator('input[name="cf-turnstile-response"]')).not.toHaveValue('', { timeout: 15_000 })
|
||||
const posted = page.waitForResponse((r) => r.url().includes('/api/ipal/forms/submit') && r.request().method() === 'POST')
|
||||
await form.locator('button[type="submit"]').click()
|
||||
expect((await posted).status()).toBe(200)
|
||||
await expect(page.locator('[data-ipal="form-success"]')).toBeVisible({ timeout: 15_000 })
|
||||
|
||||
await expect.poll(() => sink.messages.length, { timeout: 15_000 }).toBe(2)
|
||||
const staff = sink.messages.find((m) => !m.to.join().includes('[email protected]'))!
|
||||
const customer = sink.messages.find((m) => m.to.join().includes('[email protected]'))!
|
||||
const attached = attachmentOf(staff.data, 'Floor plan (ground).pdf')
|
||||
expect(attached && Buffer.compare(attached, PDF)).toBe(0)
|
||||
const text = (raw: string) => raw.replace(/=\n/g, '') // undo quoted-printable soft line breaks
|
||||
expect(text(staff.data)).toContain('not checked for viruses')
|
||||
expect(customer.data).not.toContain('Content-Disposition: attachment')
|
||||
expect(text(customer.data)).toContain('Floor plan (ground).pdf') // the name in the summary, never the file
|
||||
})
|
||||
})
|
||||
|
||||
test('every sitemap URL answers 200 with a title, canonical, hreflang and JSON-LD', async ({ page, request }) => {
|
||||
const xml = await (await request.get('/sitemap.xml')).text()
|
||||
const urls = [...xml.matchAll(/<loc>([^<]+)<\/loc>/g)].map((m) => new URL(m[1]).pathname)
|
||||
|
||||
Reference in New Issue
Block a user