周报页新增自动发送区:管理员配置 SMTP/收件人/发送星期与小时,授权码用主密钥加密保存。 确认绑定当前草稿版本与正文哈希,正文再改则确认失效;worker 每分钟仅在启用、到点、周已结束且未发送过时发一次。 邮件同时提供渲染后的 HTML 与可读纯文本;SMTP 仅允许 TLS,拒绝明文。 迁移 000060 新增设置、确认与发送记录三张表,唯一键防重复发送。
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
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'],
|
||||
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('发送设置')
|
||||
})
|
||||
Reference in New Issue
Block a user