import { describe, expect, it } from 'vitest';
|
|
import { AUDIT_BIZ_SIGN_HEADER, buildAuditBizSignHeaders, createAuditCorrelationId, resolveAuditBizSign } from './auditHeaders';
|
|
describe('online form audit headers', () => {
|
it('extracts biz_sign from the serialized standard form payload', () => {
|
const payload = { data: JSON.stringify({ biz_sign: '839875756384423365', name: '阿莫西林胶囊' }) };
|
expect(buildAuditBizSignHeaders(payload)).toEqual({ [AUDIT_BIZ_SIGN_HEADER]: '839875756384423365' });
|
});
|
|
it('supports the JNPF id mirror field', () => {
|
expect(resolveAuditBizSign({ data: JSON.stringify({ biz_sign_jnpfId: '839875756384423365' }) })).toBe('839875756384423365');
|
});
|
|
it('extracts biz_sign from workflow formData and visualdev map payloads', () => {
|
expect(resolveAuditBizSign({ formData: { biz_sign: '839875756384423365' } })).toBe('839875756384423365');
|
expect(resolveAuditBizSign({ map: { biz_sign_jnpfId: '839875756384423365' } })).toBe('839875756384423365');
|
});
|
|
it('creates a 32-character UUID correlation id for unsigned events', () => {
|
expect(createAuditCorrelationId()).toMatch(/^[0-9a-f]{32}$/);
|
});
|
|
it('uses a fallback correlation id only when the payload has no real biz_sign', () => {
|
const fallback = '0123456789abcdef0123456789abcdef';
|
expect(buildAuditBizSignHeaders({ data: '{}' }, fallback)).toEqual({ [AUDIT_BIZ_SIGN_HEADER]: fallback });
|
expect(buildAuditBizSignHeaders({ biz_sign: 'real-sign' }, fallback)).toEqual({ [AUDIT_BIZ_SIGN_HEADER]: 'real-sign' });
|
});
|
|
it('does not add a header for missing, malformed, or invalid values', () => {
|
expect(buildAuditBizSignHeaders({ data: '{}' })).toEqual({});
|
expect(buildAuditBizSignHeaders({ data: '{invalid' })).toEqual({});
|
expect(buildAuditBizSignHeaders({ data: JSON.stringify({ biz_sign: 'invalid sign' }) })).toEqual({});
|
});
|
});
|