37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
import { beforeAll, afterAll, describe, expect, it } from 'vitest'
|
|
|
|
let server
|
|
let baseUrl
|
|
|
|
beforeAll(async () => {
|
|
const { app } = await import('./index.js')
|
|
server = app.listen(0)
|
|
await new Promise(resolve => server.once('listening', resolve))
|
|
baseUrl = `http://127.0.0.1:${server.address().port}`
|
|
})
|
|
|
|
afterAll(() => server?.close())
|
|
|
|
describe('backend mail safety', () => {
|
|
it('reports degraded health without SMTP configuration', async () => {
|
|
const response = await fetch(`${baseUrl}/api/health`)
|
|
const body = await response.json()
|
|
|
|
expect(response.status).toBe(200)
|
|
expect(body.status).toBe('degraded')
|
|
expect(body.mailer).toEqual({ ready: false })
|
|
expect(JSON.stringify(body)).not.toContain('SMTP_PASS')
|
|
})
|
|
|
|
it('does not report success when contact mail cannot be sent', async () => {
|
|
const response = await fetch(`${baseUrl}/api/contact`, {
|
|
method: 'POST',
|
|
headers: { 'content-type': 'application/json' },
|
|
body: JSON.stringify({ name: 'Test', email: 'test@example.invalid', message: 'Synthetic test' }),
|
|
})
|
|
|
|
expect(response.status).toBe(503)
|
|
expect((await response.json()).error).toBeTruthy()
|
|
})
|
|
})
|