Files
SupplierSystem/server/tests/stockInboundProductionDateNull.test.ts
T
雨天 639abd2775 fix(库存): 生产日期留空不补今天并加列表筛选
独立入库没填生产日期时,原先用 COALESCE(…, 今天) 补成当天;现直接
写 NULL(效期推不出来也保持 NULL),覆盖 Web 批量、Excel 导入与
称台单行入库。验收/退回补送/财务三处同类默认值属冻结面,本轮未动。

库存列表:生产日期可排序(空值排最后);工具栏加「入库时间」区间
筛选(默认不筛),口径为该批次最早一次入库流水,只认 YYYY-MM-DD。
2026-10-21 15:51:50 +08:00

42 lines
1.9 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.
/**
* 独立入库:生产日期**留空就是没有**(2026-10-21 开发者:
* 「如果我没有填写生产日期 应该是就没有生产日期吧 而不是采取当前的时间作为生产日期」)。
*
* 钉住的是"不臆造":留空落 NULL,不得再用 `COALESCE(…, NOW())` 补成入库当天。
* 覆盖同一文件的独立入库两条写入路径:批量/Excel(writeStockImportRow)与称台单行(inboundFromWeigh)。
*
* 设计:docs/design/20261021-库存入库生产日期留空不补今天.md
*/
import { readFileSync } from 'fs';
import { describe, expect, it } from 'vitest';
const src = readFileSync(new URL('../src/services/stockInboundService.ts', import.meta.url), 'utf8');
describe('独立入库 · 生产日期留空不补今天', () => {
it('两处写 inventory 的 INSERT 都用 $6::date(空 ⇒ NULL)', () => {
expect(src.match(/\$6::date/g) || []).toHaveLength(2);
});
it('文件内不再把生产日期 COALESCE 成今天', () => {
expect(src).not.toContain("COALESCE($6::date, (NOW() AT TIME ZONE 'Asia/Shanghai')::date)");
// 也不许换成别的"今天"写法绕过去
expect(src).not.toMatch(/production_date[\s\S]{0,40}CURRENT_DATE/);
});
it('入参归一化:空串 ⇒ null(不会给 $6 塞空串导致 cast 报错)', () => {
const fnIdx = src.indexOf('function normalizeProductionDate(');
expect(fnIdx).toBeGreaterThan(-1);
const fn = src.slice(fnIdx, fnIdx + 300);
expect(fn).toContain('let s = trimText(raw);');
expect(fn).toContain('if (!s) return null;');
});
it('前端留空就不传该字段(两端口径一致)', () => {
const panel = readFileSync(
new URL('../../src/pages/inventory/StockInboundPanel.tsx', import.meta.url),
'utf8'
);
expect(panel).toContain('production_date: line.production_date || undefined,');
});
});