test(e2e): Playwright harness parameterized by BASE_URL + Mailpit mail sink

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Ben Stull
2026-06-03 22:45:13 -07:00
parent 49b741243e
commit 7d05125381
4 changed files with 125 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
const MAILSINK = process.env.MAILSINK_URL || 'http://localhost:8025'
export async function waitForLatestOtc(toAddress, { attempts = 20, delayMs = 500 } = {}) {
for (let i = 0; i < attempts; i++) {
const res = await fetch(`${MAILSINK}/api/v1/messages`)
if (res.ok) {
const data = await res.json()
const msg = (data.messages || []).find(
(m) => (m.To || []).some((t) => t.Address === toAddress),
)
if (msg) {
const full = await fetch(`${MAILSINK}/api/v1/message/${msg.ID}`)
const body = await full.json()
const text = `${body.Text || ''} ${body.HTML || ''}`
const code = text.match(/\b(\d{6})\b/)
if (code) return code[1]
}
}
await new Promise((r) => setTimeout(r, delayMs))
}
throw new Error(`no OTC email for ${toAddress} arrived in Mailpit`)
}
export async function clearMailpit() {
await fetch(`${MAILSINK}/api/v1/messages`, { method: 'DELETE' })
}