Files
Artveris/apps/api/src/blockchain/certificate-text.spec.ts
T

22 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { DEFAULT_CERTIFICATE_TEXT_TEMPLATE, renderCertificateText, validateCertificateTextTemplate } from '@artveris/shared';
const values = { '作品名称': '十二生肖莲花手工杯', '版本': '一个装', '追溯码': '295708006702', '档案编号': 'ARTVERIS-000005', '作者': '黄志伟' };
describe('证书文本模板', () => {
it('默认作品名称加版本', () => {
expect(renderCertificateText(DEFAULT_CERTIFICATE_TEXT_TEMPLATE, values)).toBe('十二生肖莲花手工杯 一个装');
});
it('支持自定义次序、普通文字、重复字段和真实换行', () => {
expect(renderCertificateText('{{版本}}:{{作品名称}}\n{{追溯码}} {{ 作者 }} {{档案编号}} {{版本}}', values))
.toBe('一个装:十二生肖莲花手工杯\n295708006702 黄志伟 ARTVERIS-000005 一个装');
});
it('缺少字段显示为空且字段值不进行二次模板替换', () => {
expect(renderCertificateText(DEFAULT_CERTIFICATE_TEXT_TEMPLATE, { ...values, '版本': '' })).toBe(values.作品名称);
expect(renderCertificateText('{{作品名称}}', { ...values, '作品名称': '{{作者}}' })).toBe('{{作者}}');
});
it('拒绝空值、超长、未知字段、错误花括号和表达式', () => {
for (const template of ['', ' ', 'a'.repeat(501), '{{不存在}}', '{作品名称}', '{{作品名称', '{{作品名称.toUpperCase()}}']) {
expect(validateCertificateTextTemplate(template)).not.toBeNull();
}
});
});