/** * 独立入库:生产日期**留空就是没有**(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,'); }); });