77 lines
2.7 KiB
TypeScript
77 lines
2.7 KiB
TypeScript
import { renderToStaticMarkup } from 'react-dom/server'
|
|
import { describe, expect, it } from 'vitest'
|
|
import { parseWeeklyMailConfirmation, parseWeeklyMailSends, parseWeeklyMailSettings } from './qaWeeklyMail'
|
|
import { QAWeeklyMail } from './QAWeeklyMail'
|
|
|
|
const settings = {
|
|
host: 'smtp.example.com',
|
|
port: 465,
|
|
username: 'kb@example.com',
|
|
from: 'kb@example.com',
|
|
recipients: ['a@example.com'],
|
|
cc_recipients: [],
|
|
review_address: 'me@example.com',
|
|
weekday: 1,
|
|
hour: 9,
|
|
enabled: true,
|
|
has_password: true,
|
|
revision: 3,
|
|
updated_by: 'admin',
|
|
updated_at: '2026-10-25T07:00:00Z',
|
|
}
|
|
|
|
describe('weekly mail settings contract', () => {
|
|
it('accepts a complete settings payload and rejects impossible slots', () => {
|
|
expect(parseWeeklyMailSettings(settings)).toMatchObject({ port: 465, weekday: 1, hour: 9, enabled: true })
|
|
expect(() => parseWeeklyMailSettings({ ...settings, weekday: 0 })).toThrow()
|
|
expect(() => parseWeeklyMailSettings({ ...settings, weekday: 8 })).toThrow()
|
|
expect(() => parseWeeklyMailSettings({ ...settings, hour: 24 })).toThrow()
|
|
expect(() => parseWeeklyMailSettings({ ...settings, port: 0 })).toThrow()
|
|
expect(() => parseWeeklyMailSettings({ ...settings, recipients: [42] })).toThrow()
|
|
})
|
|
it('distinguishes a missing confirmation from an expired one', () => {
|
|
expect(parseWeeklyMailConfirmation(null, '2026-W43')).toBeNull()
|
|
const live = parseWeeklyMailConfirmation(
|
|
{
|
|
week: '2026-W43',
|
|
draft_revision: 2,
|
|
body_sha256: 'a',
|
|
confirmed_by: 'admin',
|
|
confirmed_at: '2026-10-25T07:00:00Z',
|
|
current: false,
|
|
},
|
|
'2026-W43'
|
|
)
|
|
expect(live?.current).toBe(false)
|
|
expect(() => parseWeeklyMailConfirmation({ week: '2026-W42', current: true }, '2026-W43')).toThrow()
|
|
})
|
|
it('rejects unknown delivery states instead of mislabelling them as sent', () => {
|
|
expect(
|
|
parseWeeklyMailSends([
|
|
{
|
|
week: '2026-W43',
|
|
draft_revision: 1,
|
|
status: 'sent',
|
|
attempts: 1,
|
|
last_error: '',
|
|
updated_at: '2026-10-25T07:00:00Z',
|
|
},
|
|
])
|
|
).toHaveLength(1)
|
|
expect(() =>
|
|
parseWeeklyMailSends([
|
|
{ week: '2026-W43', draft_revision: 1, status: 'delivered', attempts: 1, last_error: '', updated_at: '' },
|
|
])
|
|
).toThrow()
|
|
})
|
|
})
|
|
|
|
it('shows the confirmation gate before any automatic send controls', () => {
|
|
const html = renderToStaticMarkup(<QAWeeklyMail week="2026-W43" busy={false} />)
|
|
expect(html).toContain('自动发送')
|
|
expect(html).toContain('未确认')
|
|
expect(html).toContain('确认本周周报')
|
|
expect(html).not.toContain('立即发送')
|
|
expect(html).not.toContain('发送设置')
|
|
})
|