Files
SupplierSystem/server/tests/mainSystemQtyLock.test.ts
T
Ubuntu d0fa4871ef
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(数量锁): 主系统分配行的「计划数量」三道门——界面只读 + 服务层 409 + 小程序锁
开发者口径:「主系统给子系统的订单,这个**计划数量**取消可以编辑的权限(**子系统正常录单的不要被影响**)」,
并追加裁决:① 小程序也一起锁(只锁主系统发来的);② 后端也拒绝。

判据统一为**行级** `order_items.main_order_code`(= 主系统分配过来的行):
· ① Web 订单明细:计划数量渲染文本(上一提交 1fc98bb)
· ② 服务层(改明细 5 个入口共用:Web / 小程序 ×3 / MCP):`quantity` 改动 **409 `main_system_qty_locked`**,
  在"通知主系统"之前抛出(被拒的改动不会既报错又发通知);错误文案说明"数量由主系统下发,
  不符请联系主系统重新分配,或用缺货上报"
· ③ 小程序(订单管理端 + 采购员端):明细接口补 `main_order_code`(两处 SELECT)+ 数量格
  `planQtyLocked` 置灰、点击不进编辑弹窗(未加任何提示语,按前端文案纪律等批准)

不受影响:我方正常录单的订单;主系统单里我方自建行(加菜/自建,无 main_order_code);
**价格**仍走"先改后通知";主系统发来的量变更申请仍由我方审、同意后落我方记录(走 apply 直写)。
因此 `notifyMainSystemPriceQtyChanges` 的**数量分支**对分配行不再触发(代码保留作回退兜底)。

真库端到端(真 JWT 打 PATCH /api/workflow/orders/:code/items):
抄手皮 8 → 13 ⇒ **HTTP 409 / main_system_qty_locked**,且**未写库**(订单仍 8/15/30)。

测试:新增 `server/tests/mainSystemQtyLock.test.ts`(5 条:只拦 quantity+guarded、错误码、价格仍通知、
两个小程序明细接口都带 main_order_code、planQtyLocked 是行级判据)+ 前端 `orderDetailPlanQtyLock.test.ts`(3 条);
更新 `mainSystemPriceQtyRequest.test.ts` 里被改名的接线钉子。服务端全量失败集与基线**逐文件一致(24,零新增)**。

文档:设计文档 §10.5(三道门 + 不受影响清单 + 数量分支不再触发);
对接清单 §4.5.13(我方回执:数量只读、改量通知不再产生、价格不变、他们要改分配量请走申请通道)。
2026-10-10 13:29:53 +08:00

76 lines
3.6 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('服务层:主系统分配行改数量 ⇒ 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('status: 409');
// 抛错在"通知主系统"之前 ⇒ 被拒的改动不会既报错又发通知
const noticeIdx = service.indexOf('priceQtyNotices = guardedChanges;');
expect(noticeIdx).toBeGreaterThan(idx);
});
it('价格不受影响(仍走先改后通知),我方自建行也不在 guarded 里', () => {
const idx = service.indexOf('const guardedChanges = changes.filter');
const body = service.slice(idx, idx + 1600);
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())');
expect(mpJs).toMatch(/if \(field === 'qty' && item\.planQtyLocked\) return;/);
// 数量格带置灰样式(不加文案)
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/);
});
});