import { readFileSync } from 'node:fs'; import path from 'node:path'; import { describe, expect, it } from 'vitest'; const read = (rel: string) => readFileSync(path.join(__dirname, '..', '..', rel), 'utf8'); const readServer = (rel: string) => readFileSync(path.join(__dirname, '..', rel), 'utf8'); describe('验收退回操作日志', () => { it('COMMIT 成功后退回才写 inspection_reject,不挡业务', () => { const svc = readServer('src/services/inspectionComplianceService.ts'); expect(svc).toContain("operationType: 'inspection_reject'"); expect(svc).toContain('logInspectionReject'); expect(svc.indexOf('await client.query(\'COMMIT\')')).toBeGreaterThan(-1); expect(svc).toContain('[inspection] 退回操作日志写入失败'); }); it('独立入库提前 bounce 与订单退供主路径都记', () => { const svc = readServer('src/services/inspectionComplianceService.ts'); const bounce = svc.indexOf('bounceIndependentInboundPendingInspection'); const bounceLog = svc.indexOf('independentInbound: true', bounce); const mainLog = svc.indexOf('if (isRejected)'); const mainCall = svc.indexOf('logInspectionReject', mainLog); expect(bounceLog).toBeGreaterThan(bounce); expect(mainCall).toBeGreaterThan(mainLog); }); it('确认入库路径不写 inspection_reject', () => { const svc = readServer('src/services/inspectionComplianceService.ts'); expect(svc).not.toContain("if (!isRejected) {\n logInspectionReject"); expect(svc).toMatch(/if \(isRejected\) \{\s*logInspectionReject/); }); it('操作日志页可筛可展示', () => { const page = read('src/pages/system/OperationLogs.tsx'); expect(page).toContain("'inspection_reject'"); expect(page).toContain('formatInspectionRejectDetail'); const zh = read('src/i18n/locales/zh-CN/system.ts'); expect(zh).toContain('"logs.op.inspection_reject": "验收退回"'); }); });