Files
SupplierSystem/server/tests/mainSystemQtyLock.test.ts
T
Ubuntu d8fbecc066
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
feat(加工): 解封主系统分配行的「加工方式/加工方」——三处拦截全部删除(数量/配送时间锁不变)
开发者真机报障(截图提示「分发订单的加工方式无法修改(以主系统为准)」):
「这块需要解封 当前加工方式是自己设置了」。

根因:§11 的 C 口径已把加工方式交给我方设置,但 2026-10-10 那道旧锁只解开一半——
Web 详情加工格早前已放开(D2''),**服务层与小程序还拦着** ⇒ 能改、保存却 409。

改前 / 改后:
· 服务层(改明细 5 个入口共用):主系统分配行改 processing_method/processing_owner
  ⇒ 409 main_system_processing_locked「分发订单的加工方式无法修改(以主系统为准)」
  + collectMainSystemProcessingChanges + 与价格数量的并集判据
  ⇒ **整段删除**(含收集函数与类型);改动照常落库,不通知主系统(无此反向通道)
· 小程序:加工方式 picker disabled、加工方 chip 置灰、两个 handler 各弹一次同一 toast
  ⇒ 全部去掉;js/wxml 同步
· **保留**:计划数量锁(409 main_system_qty_locked + 小程序数量格)、
  配送时间锁(409 main_system_delivery_date_locked)——一行未动

测试:server/tests/mainSystemQtyLock.test.ts 改为反向棘轮(旧 409 码/旧文案/收集函数/并集判据
都不得回归;小程序加工格已解禁而数量格仍锁),10 项通过。
回归:后端 2970 passed / 32 failed(0 新增,全部在基线集内);前端相关 115 项通过;
tsc 前后端 0 错误;设计门禁 8 通过 / check-ai-cost 长期红 / verify-facts 未执行(库需口令)。

遗留(待开发者决定):三语词条 orders.detail.processingLocked 已无使用点(死文案),
按「前端文案不得擅自增删」未动,是否清词条请示后再做。

设计:docs/design/20261014-主系统加工需求与我方加工决策.md §12(新增);
docs/design/20261011-跨系统改价改量审核.md §10.5.1(标注加工方式部分作废,保留数量/配送时间)。
2026-10-14 22:54:09 +08:00

151 lines
8.0 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 'node:fs';
import { describe, expect, it } from 'vitest';
/**
* 主系统分配行的**数量不可改**(开发者 2026-10-10 口径):
* 「主系统给子系统的订单,这个**计划数量**取消可以编辑的权限(子系统正常录单的不要被影响)」。
*
* 三道门(缺一不可):
* ① 界面(Web 订单明细):计划数量渲染成文本 —— `orderDetailPlanQtyLock.test.ts`;
* ② 服务层(改明细 5 个入口共用):主系统分配行的 `quantity` 改动 **409 直接拒绝**(本文件);
* ③ 小程序(订单管理端 + 采购员端):明细接口带 `main_order_code`、数量格置灰不进编辑弹窗。
*
* 只锁**数量**:价格仍走「先改后通知」(2026-10-12 口径);我方自建行(加菜/自录)完全不受影响。
*/
const service = readFileSync(
new URL('../src/services/orderManageItemsService.ts', import.meta.url),
'utf8'
);
const mobileAdmin = readFileSync(
new URL('../src/routes/mobile/mobileAdminRoutes.ts', import.meta.url),
'utf8'
);
const mobilePurchaser = readFileSync(
new URL('../src/routes/mobile/mobilePurchaserOrderRoutes.ts', import.meta.url),
'utf8'
);
const mpJs = readFileSync(
new URL('../../miniprogram/pages/order-manage-detail/order-manage-detail.js', import.meta.url),
'utf8'
);
const mpWxml = readFileSync(
new URL('../../miniprogram/pages/order-manage-detail/order-manage-detail.wxml', import.meta.url),
'utf8'
);
describe('服务层:加工方式锁已解封(2026-10-14 开发者令),配送时间仍锁', () => {
it('加工方式/加工方**不再被拦**:旧 409 通道已删除(反向棘轮,防回归)', () => {
/**
* 2026-10-14 开发者:「这块需要解封 当前加工方式是自己设置了」。
* 口径来源 docs/design/20261014-主系统加工需求与我方加工决策.md §6.3 D2''、§7 验收 5:
* 主系统的 `processingMethod` 只作**提示**(并入行备注),加工方式由**我方**设置 ⇒
* 不能再拦(拦了只会拦住我们自己:详情页能改、保存却 409)。
*/
expect(service).not.toMatch(/code: 'main_system_processing_locked'/);
expect(service).not.toContain('分发订单的加工方式无法修改(以主系统为准)');
expect(service).not.toMatch(/function collectMainSystemProcessingChanges/);
expect(service).not.toContain('guardedProcessingChanges');
expect(service).not.toContain('if (changes.length || processingChanges.length) {');
// 留痕:解封原因写在服务层注释里(下次有人想加回这道门,先看这段)
expect(service).toContain('加工方式**已解封**');
});
it('配送时间改动 ⇒ 409 main_system_delivery_date_locked,判据=整单存在主系统分配行', () => {
const idx = service.indexOf('export async function updateOrderDeliveryDate');
expect(idx).toBeGreaterThan(-1);
const body = service.slice(idx, idx + 2600);
expect(body).toContain("code: 'main_system_delivery_date_locked'");
expect(body).toContain('分发订单的配送时间无法修改(以主系统为准)');
expect(body, '判据必须按行 main_order_code(与我方自建单区分)').toContain(
"NULLIF(TRIM(main_order_code), '') IS NOT NULL"
);
// 必须在状态闸门/更新之前拦下
expect(body.indexOf('main_system_delivery_date_locked')).toBeLessThan(
body.indexOf('canEditDeliveryDateByStatus')
);
});
});
describe('服务层:主系统分配行改数量 ⇒ 409(不是"先改后通知")', () => {
it('只拦 quantity、只拦 guarded(主系统分配行),错误码固定', () => {
const idx = service.indexOf("const qtyLocked = guardedChanges.filter");
expect(idx, '未找到数量拦住逻辑').toBeGreaterThan(-1);
const body = service.slice(idx, idx + 1200);
expect(body).toContain("change.field === 'quantity'");
expect(body).toContain("code: 'main_system_qty_locked'");
// 文案与小程序一致(「分发订单的数量无法修改」),便于用户在两处看到同一句话
expect(body).toContain('分发订单的数量无法修改(${names})');
expect(body).toContain('status: 409');
// 抛错在"通知主系统"之前 ⇒ 被拒的改动不会既报错又发通知
const noticeIdx = service.indexOf('priceQtyNotices = guardedChanges;');
expect(noticeIdx).toBeGreaterThan(idx);
});
it('价格不受影响(仍走先改后通知),我方自建行也不在 guarded 里', () => {
const idx = service.indexOf('const guardedChanges = changes.filter');
// 窗口要覆盖"数量拦下 → 价格放行"整段(2026-10-14 起加工方式那道门已删)
const body = service.slice(idx, idx + 2600);
expect(body).toContain('priceQtyNotices = guardedChanges;');
// 仍然只对 guarded(= isMainSystemAllocatedLines 判定的主系统分配行)生效
expect(body).toContain('guarded.has(change.itemId)');
});
});
describe('小程序:明细接口带 main_order_code,数量格按行锁', () => {
it('订单管理端 / 采购员端明细查询都返回行级来源', () => {
expect(mobileAdmin).toMatch(/oi\.main_order_code/);
expect(mobilePurchaser).toMatch(/oi\.main_order_code/);
});
it('小程序按行判定 planQtyLocked,且点击数量格不进编辑弹窗', () => {
expect(mpJs).toContain('planQtyLocked: Boolean(String(row.main_order_code || \'\').trim())');
// 点击给一句说明(开发者 2026-10-10 定稿文案:「分发订单的数量无法修改」),然后不进编辑弹窗
expect(mpJs).toMatch(/if \(field === 'qty' && item\.planQtyLocked\) \{/);
expect(mpJs).toContain("'分发订单的数量无法修改'");
expect(mpJs).toMatch(/wx\.showToast\(\{ title: '分发订单的数量无法修改', icon: 'none' \}\);/);
// 数量格带置灰样式(不加文案)
expect(mpWxml).toContain("{{item.planQtyLocked ? 'cell-locked' : ''}}");
});
it('我方正常录单不受影响:判据是**行上有 main_order_code**,不是整单标记', () => {
expect(mpJs).not.toMatch(/planQtyLocked: Boolean\([^)]*isMainSystemOrder/);
expect(mpJs).toMatch(/planQtyLocked: Boolean\(String\(row\.main_order_code/);
});
it('小程序:加工方式/加工方已解禁(仍与主系统行解耦,数量格照旧锁)', () => {
/**
* 三条门要一起开,否则出现"界面能改、保存 409"(2026-10-14 开发者报的正是这个):
* Web 详情(早前已开)+ 服务层(本次)+ 小程序(本次)。
*/
expect(mpJs).not.toContain('加工方式无法修改');
expect(mpWxml).not.toContain('disabled="{{item.planQtyLocked}}"');
expect(mpWxml).not.toContain('加工方式一起只读');
// 数量锁**不得**被顺手放开
expect(mpJs).toMatch(/if \(field === 'qty' && item\.planQtyLocked\) \{/);
expect(mpWxml).toContain("class=\"g-td c-qty {{item.planQtyLocked ? 'cell-locked' : ''}}\"");
});
});
describe('主系统分配单:子系统不能新增商品行(2026-10-12)', () => {
const importService = readFileSync(
new URL('../src/services/mainSystemOrderImport.ts', import.meta.url),
'utf8'
);
it('服务层第二道门:主系统单新增行 ⇒ 400 main_system_order_no_manual_append', () => {
const idx = service.indexOf('子系统不能新增商品行');
expect(idx, '未找到主系统单禁止新增行的守卫').toBeGreaterThan(-1);
const body = service.slice(idx, idx + 1800);
expect(body).toContain("code: 'main_system_order_no_manual_append'");
expect(body).toContain('public.main_system_order_imports');
// 边界(勿错伤):加菜放行 + 只对已存在的单生效 + 系统追加放行
expect(body).toContain('!params.allowMainSystemAppend');
expect(body).toContain('!newRowIsExtraDish');
expect(body).toContain('existingMap.size > 0');
});
it('主系统导入的系统追加放行(否则导入会被自己的门拦住)', () => {
expect(importService).toContain('allowMainSystemAppend: true');
});
});