voko-notice.test.js
1.41 KB
import { describe, expect, it } from 'vitest'
import { renderTemplate } from '../src/templates/index.js'
describe('voko-notice 模板', () => {
it.each(['en', 'zh'])('%s:认领与求助两种通知都能渲染,内容被转义', (locale) => {
const claimed = renderTemplate('voko-notice', { locale, kind: 'claimed', agent: 'Scout', url: 'https://alpha.voko.world/agents' })
expect(claimed.subject).toContain('Scout')
const help = renderTemplate('voko-notice', { locale, kind: 'help', agent: 'Scout', task: 'Translate <b>', question: 'Which tone?', url: 'http://localhost:5201/help' })
expect(help.text).toContain('Which tone?')
expect(help.html).toContain('Translate <b>')
expect(help.html).not.toContain('<b>')
})
it('缺字段、未知类型、非 https 链接直接报错', () => {
expect(() => renderTemplate('voko-notice', { locale: 'en', kind: 'help', agent: 'Scout', url: 'https://x.test' })).toThrow(/missing field "task"/)
expect(() => renderTemplate('voko-notice', { locale: 'en', kind: 'weekly', agent: 'Scout', url: 'https://x.test' })).toThrow(/unsupported kind/)
expect(renderTemplate('voko-notice', { locale: 'zh', kind: 'digest', summary: 'Scout:结算 2 单', url: 'https://x.test' }).text).toContain('结算 2 单')
expect(() => renderTemplate('voko-notice', { locale: 'en', kind: 'claimed', agent: 'Scout', url: 'http://evil.test' })).toThrow(/must use https/)
})
})