import { readFileSync } from 'fs'; import { describe, expect, it } from 'vitest'; /** * 小程序「加工」面板:独立加工必须能直接开始(申报成品),不能因为「没有验收行」被拦住。 * * 真机问题(2026-10-23):Web 端「待加工」有「开始加工」,小程序同一单却显示 * 「待完成到货验收后可开始加工」且没有按钮。 * 根因:独立加工单 `inspection_id` 为 NULL(创建时显式写 NULL),`inspection_completed` * 恒为 false;小程序用它当开工门槛,而后端 `startProcessingTask` 只在 * 「inspection_id 存在且 inspection_time 为空」时才拦。 */ const panelJs = readFileSync( new URL('../../miniprogram/components/processing-panel/index.js', import.meta.url), 'utf8' ); const panelWxml = readFileSync( new URL('../../miniprogram/components/processing-panel/index.wxml', import.meta.url), 'utf8' ); const taskService = readFileSync( new URL('../src/services/processingTaskService.ts', import.meta.url), 'utf8' ); const standaloneService = readFileSync( new URL('../src/services/processingStandaloneService.ts', import.meta.url), 'utf8' ); describe('小程序加工:独立加工开工门槛与后端一致', () => { it('独立加工单创建时 inspection_id 为 NULL(所以不存在“到货验收”这一步)', () => { expect(standaloneService).toContain("VALUES (NULL, NULL, $1, 'standalone'"); }); it('后端只在「有 inspection_id 且未验收」时拦开工', () => { expect(taskService).toContain( 'if (current.rows[0].inspection_id && current.rows[0].inspection_time == null)' ); }); it('小程序 can_start_work 对独立加工放行', () => { expect(panelJs).toContain("const isStandalone = row.source_type === 'standalone'"); expect(panelJs).toContain('(isStandalone || row.inspection_completed === true)'); }); it('「待完成到货验收」提示不再出现在独立加工上', () => { expect(panelWxml).toContain('!item.is_standalone && !item.inspection_completed'); }); });