gongxiangp2/lib/__tests__/task-detail-source-mapping-audit.test.ts

52 lines
1.9 KiB
TypeScript

/** @jest-environment node */
const { planGroup } = require('../../scripts/audit-task-detail-source-mapping.cjs')
const row = (id: string, name: string, sourceIndex: number, sliceIndex = 0) => ({
id,
fileName: name,
fileUrl: `https://example.test/client-1780000000000-${sourceIndex}-${sliceIndex}-${name}`,
})
describe('historical task-detail source mapping audit', () => {
test('uses upload source indexes and ZIP deduplication, never ZIP directory order', () => {
const result = planGroup([
row('a', '功能1-preview.webp', 0),
row('b', '功能2-preview.webp', 1),
row('c', '功能1-preview.webp', 2),
row('d', '功能2-preview.webp', 3),
], ['功能2-2.jpg', '功能1.jpg', '功能2.jpg', '功能1-2.jpg'])
expect(result).toMatchObject({
status: 'verified',
changes: [
{ id: 'c', after: '功能1-2-preview.webp' },
{ id: 'd', after: '功能2-2-preview.webp' },
],
})
})
test('different source extensions with identical preview labels stay manual', () => {
const result = planGroup([
row('a', '功能1-preview.webp', 0),
row('b', '功能1-preview.webp', 1),
], ['功能1.jpg', '功能1.png'])
expect(result).toMatchObject({ status: 'manual', reason: '存在多种可能的原图对应关系' })
})
test('multiple preview slices remain attached to one ZIP member', () => {
const result = planGroup([
row('a', '详情-001.webp', 0, 0),
row('b', '详情-002.webp', 0, 1),
], ['详情.jpg'])
expect(result).toMatchObject({ status: 'verified', changes: [], sources: 1 })
})
test('missing upload source identity stays manual', () => {
const result = planGroup([
{ id: 'a', fileName: '功能1-preview.webp', fileUrl: 'https://example.test/old.webp' },
row('b', '功能1-preview.webp', 1),
], ['功能1.jpg', '功能1-2.jpg'])
expect(result).toMatchObject({ status: 'manual' })
})
})