70 lines
3.3 KiB
TypeScript
70 lines
3.3 KiB
TypeScript
import { readFileSync } from 'fs';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { quoteItemDisplayNameSql, quoteItemNameJoinSql } from '../src/services/quoteItemDisplayNameSql';
|
|
|
|
/**
|
|
* 报价单商品名:**档案当前名优先、历史快照兜底**(2026-10-21 开发者指定)。
|
|
*
|
|
* `customer_quote_sheet_items.sku_name` 是建单当时的快照;档案改名后(肉片 → 肉片全瘦、
|
|
* 韭菜 → 韭菜叶水面)若仍用快照名,卡片/导出/打印/对比/历史报价单都会显示旧名。
|
|
* 快照**保留**用于审计与价格追溯,但不得覆盖当前展示名。
|
|
*/
|
|
|
|
const sheetSvc = readFileSync(new URL('../src/services/quoteSheetService.ts', import.meta.url), 'utf8');
|
|
const mappingSvc = readFileSync(new URL('../src/services/skuMappingService.ts', import.meta.url), 'utf8');
|
|
const proposalSvc = readFileSync(new URL('../src/services/quotePriceProposalService.ts', import.meta.url), 'utf8');
|
|
|
|
describe('quoteItemDisplayNameSql:单一实现', () => {
|
|
it('档案名在前、快照名兜底', () => {
|
|
expect(quoteItemDisplayNameSql()).toBe(
|
|
"COALESCE(NULLIF(TRIM(s.sku_name), ''), NULLIF(TRIM(i.sku_name), ''))"
|
|
);
|
|
const sql = quoteItemDisplayNameSql();
|
|
expect(sql.indexOf('s.sku_name')).toBeLessThan(sql.indexOf('i.sku_name'));
|
|
});
|
|
|
|
it('支持别名(不同查询里的表别名不一样)', () => {
|
|
expect(quoteItemDisplayNameSql({ itemAlias: 'x', skuAlias: 'y' })).toBe(
|
|
"COALESCE(NULLIF(TRIM(y.sku_name), ''), NULLIF(TRIM(x.sku_name), ''))"
|
|
);
|
|
});
|
|
|
|
it('关联片段按 sku_code 连接,别名可用', () => {
|
|
expect(quoteItemNameJoinSql()).toBe('LEFT JOIN skus s ON s.sku_code = i.sku_code');
|
|
expect(quoteItemNameJoinSql({ itemAlias: 'x', skuAlias: 'y' })).toBe(
|
|
'LEFT JOIN skus y ON y.sku_code = x.sku_code'
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('报价单详情:展示名用档案名、快照另存', () => {
|
|
it('明细查询同时返回展示名与快照列', () => {
|
|
expect(sheetSvc).toContain('${quoteItemDisplayNameSql()} AS sku_name');
|
|
expect(sheetSvc).toContain('i.sku_name AS sku_name_snapshot');
|
|
});
|
|
|
|
it('合并写回时用**快照**回填,不用档案名覆盖历史快照', () => {
|
|
expect(sheetSvc).toContain('row.sku_name_snapshot?.trim()');
|
|
});
|
|
});
|
|
|
|
describe('其它展示面同样档案优先', () => {
|
|
it('提交前映射统计(未映射商品清单)取档案名', () => {
|
|
expect(mappingSvc).toContain("COALESCE(NULLIF(TRIM(s.sku_name), ''), NULLIF(TRIM(i.sku_name), ''))");
|
|
});
|
|
|
|
it('供需变更/报价提议明细取档案名(3 处查询)', () => {
|
|
const hits = proposalSvc.match(/COALESCE\(NULLIF\(TRIM\(s\.sku_name\), ''\), NULLIF\(TRIM\(i\.sku_name\), ''\)\)/g) || [];
|
|
expect(hits.length).toBeGreaterThanOrEqual(3);
|
|
});
|
|
|
|
it('提议行名称链路:档案名优先,提议里的历史快照最后兜底', () => {
|
|
const block = proposalSvc.slice(proposalSvc.indexOf('// 档案名优先(sheetRow.sku_name'));
|
|
const order = ['sheetRow?.sku_name', 'dictRow?.sku_name', "toText((item as { sku_name?: unknown }).sku_name)"];
|
|
const positions = order.map((token) => block.indexOf(token));
|
|
expect(positions.every((p) => p >= 0)).toBe(true);
|
|
expect(positions[0]).toBeLessThan(positions[1]);
|
|
expect(positions[1]).toBeLessThan(positions[2]);
|
|
});
|
|
});
|