Files
SupplierSystem/server/tests/deliveryLoadingItemNamePriority.test.ts
T
Ubuntu e21dc4db62
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
fix(商品名): 核货与报价单统一取商品档案名——skus.sku_name → order_items.item_name → picking_items.item_name(单一实现+真库PREPARE与行为演练)
2026-10-21 11:12:11 +08:00

70 lines
3.2 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 { readFileSync } from 'fs';
import { describe, expect, it } from 'vitest';
import { deliveryLoadingItemNameSql } from '../src/services/deliveryLoadingService';
/**
* 配送核货「商品名」取值链(2026-10-21 开发者指定):
* `skus.sku_name` → `order_items.item_name` → `picking_items.item_name`
*
* 起因:核货界面原来优先取 `picking_items.item_name` / `order_items.item_name`(下单当刻的快照名),
* **商品档案改名后仍显示旧名称**。这里把取值链收成单一实现(三处 SQL 共用),并用真实断言钉住顺序。
*/
const src = readFileSync(new URL('../src/services/deliveryLoadingService.ts', import.meta.url), 'utf8');
describe('deliveryLoadingItemNameSql:顺序与空值语义', () => {
it('三段齐全时:档案名 → 订单行名 → 分拣行名', () => {
const sql = deliveryLoadingItemNameSql({
skuName: 's.sku_name',
orderItemName: 'oi.item_name',
pickingItemName: 'pi.item_name',
});
expect(sql).toBe(
"COALESCE(NULLIF(TRIM(s.sku_name), ''), NULLIF(TRIM(oi.item_name), ''), NULLIF(TRIM(pi.item_name), ''))"
);
// 顺序断言(防被改回"快照名优先")
expect(sql.indexOf('s.sku_name')).toBeLessThan(sql.indexOf('oi.item_name'));
expect(sql.indexOf('oi.item_name')).toBeLessThan(sql.indexOf('pi.item_name'));
});
it('每段都套 NULLIF(TRIM(…), \'\'),空串不会被当成有效名称', () => {
const sql = deliveryLoadingItemNameSql({ skuName: 'sk.sku_name', orderItemName: 'oi.item_name' });
expect(sql).toBe("COALESCE(NULLIF(TRIM(sk.sku_name), ''), NULLIF(TRIM(oi.item_name), ''))");
});
it('缺列(null/undefined/空白)自动跳过,不产生 NULLIF(TRIM(NULL), _) 这种脏 SQL', () => {
expect(deliveryLoadingItemNameSql({ skuName: ' ', orderItemName: 'oi.item_name' })).toBe(
"COALESCE(NULLIF(TRIM(oi.item_name), ''))"
);
expect(deliveryLoadingItemNameSql({ orderItemName: 'oi.item_name' })).not.toContain('sku_name');
});
it('一段都没有 ⇒ NULL(与原来"取不到就是 null"一致,不造空串)', () => {
expect(deliveryLoadingItemNameSql({})).toBe('NULL');
});
});
describe('三处 SQL 都改用取值链(防口径漂移)', () => {
it('核货列表 SQL 用 s.sku_name 优先,而不是裸取 pi.item_name', () => {
expect(src).toContain(
"documentedLoadingItemNameSqlAnchor".replace('documentedLoadingItemNameSqlAnchor', "skuName: 's.sku_name'")
);
// 旧写法(裸选 pi.item_name 作为 item_name)必须已消失
expect(src).not.toContain('SELECT pi.id, pi.pick_code, pi.item_name,');
});
it('无分拣行补行 SQL(order_items 侧)也走取值链', () => {
expect(src).toContain("$2::text AS pick_code,");
expect(src).toContain("orderItemName: 'oi.item_name',");
expect(src).not.toMatch(/\$2::text AS pick_code,\s*\n\s*oi\.item_name,/);
});
it('确认拣货 SQL 也走取值链,并关联了 skus(别只改名字不改 JOIN)', () => {
expect(src).toContain("skuName: 'sk.sku_name',");
expect(src).toContain(
'LEFT JOIN skus sk ON sk.sku_code = COALESCE('
);
expect(src).not.toContain(' pi.item_name, pi.order_code, pi.branch_code,');
});
});