免入库(主系统骑手上门取货): - 50 展示「待取货」、副文案「待主系统骑手上门取货」、不建我方配送任务(守卫与开关解耦) - 我方 50 即回写备货完成;两开关(SKIP_INBOUND_AWAIT_PICKUP / FULFILLMENT_EVENTS)改默认开 核货事实镜像(「核货完毕」标记): - 按主系统 lookup 的 actual_qty 落台账,新增 GET/POST /orders/:orderCode/main-system-prep-facts[/refresh] - 详情行内显示「核货完毕」(含核货量),分配对账兜底刷新 实收数量/单位口径变更(对方先改 + 我方事后同步): - 台账加 applied_at;inbound 与 picking_check 同为事实登记(驳回不回滚) - 同意才落我方值:免入库改装车核货量、送仓改验收实收(已入库走既有库存调整)、已结算/已结案只留痕 - 计划量与金额一起改,并同步结算投影(syncStatementsForOrderSafe) - 审核页语义改「主系统实际值(已生效)/ 是否同步」+ 已处理历史(双方时间与落值结论) 台账对照与回写修复: - 行级对照改整单一次性(同名商品不再重复认领)+ 存量纠正 healOrderPrepMapping - 堵住客户绑定回填旁路(免入库单不再被派我方骑手) - 回写触发函数改对象参数(修 branch/order 传反导致的静默不回写) 文档:设计文档 4 篇 +《给主系统 AI 的对接改造清单》§2.9(第六批契约) 回归:服务端全量与 HEAD 基线一致(24 个失败文件同集合);前端 140 文件 / 699 测试全绿;tsc 双端干净
97 lines
4.6 KiB
TypeScript
97 lines
4.6 KiB
TypeScript
import { readFileSync } from 'node:fs';
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
/**
|
|
* 「收货地址」两条链路(2026-10-11 开发者提出):
|
|
* ① 主系统分公司的**仓库地址**要自动带进我方订单(P1-10 的 `branch_address`,此前一直没消费);
|
|
* ② 明细锁(40+)后也要能**单独改地址** —— 只写表头,不碰明细、不动状态链。
|
|
*
|
|
* 本文件按仓库既有做法做**源级契约**钉住(真正的行为验证走本地真库 smoke,见 docs 变更记录)。
|
|
*/
|
|
const orderRoutes = readFileSync(
|
|
new URL('../src/modules/workflow/routes/orderRoutes.ts', import.meta.url),
|
|
'utf8'
|
|
);
|
|
const manageService = readFileSync(
|
|
new URL('../src/services/orderManageItemsService.ts', import.meta.url),
|
|
'utf8'
|
|
);
|
|
const importService = readFileSync(
|
|
new URL('../src/services/mainSystemOrderImport.ts', import.meta.url),
|
|
'utf8'
|
|
);
|
|
const prepApi = readFileSync(
|
|
new URL('../src/services/mainSystem/api/preparations.ts', import.meta.url),
|
|
'utf8'
|
|
);
|
|
const webhookRoutes = readFileSync(
|
|
new URL('../src/routes/mainSystemIntegration.ts', import.meta.url),
|
|
'utf8'
|
|
);
|
|
|
|
describe('单独改收货地址:路由与门槛', () => {
|
|
it('路由存在且与配送日路由分离(不是管理员专用)', () => {
|
|
expect(orderRoutes).toContain("router.patch('/orders/:orderCode/delivery-address'");
|
|
const start = orderRoutes.indexOf("router.patch('/orders/:orderCode/delivery-address'");
|
|
const route = orderRoutes.slice(start, orderRoutes.indexOf('\nrouter.', start + 10));
|
|
// 权限:能编辑订单的人都能改地址;不得出现"仅管理员"的 403 分支
|
|
for (const code of ['order_edit', 'order_entry', 'order_manage', 'allocation_manage']) {
|
|
expect(route).toContain(`'${code}'`);
|
|
}
|
|
expect(route).not.toContain('仅管理员');
|
|
expect(route).toContain('assertOrderCodeAccess');
|
|
expect(route).toContain('updateOrderDeliveryAddress');
|
|
});
|
|
|
|
it('服务只写表头:不动明细、不推进状态链', () => {
|
|
const start = manageService.indexOf('export async function updateOrderDeliveryAddress');
|
|
const fn = manageService.slice(start, start + 4200);
|
|
expect(fn).toContain('export async function updateOrderDeliveryAddress');
|
|
expect(fn).toContain('UPDATE orders SET delivery_address = $1');
|
|
// 明细与状态链:这段代码里一个字都不许出现
|
|
expect(fn).not.toContain('order_items');
|
|
expect(fn).not.toContain('UPDATE orders SET order_status');
|
|
expect(fn).not.toContain('advanceOrderWorkflow');
|
|
});
|
|
|
|
it('终态与垃圾桶分别拒:>=90 与 order_trashed', () => {
|
|
const start = manageService.indexOf('export async function updateOrderDeliveryAddress');
|
|
const fn = manageService.slice(start, start + 4200);
|
|
expect(fn).toContain('status >= 90');
|
|
expect(fn).toContain("code: 'invalid_status'");
|
|
expect(fn).toContain("code: 'order_trashed'");
|
|
expect(fn).toContain('order_delivery_address_edit');
|
|
});
|
|
});
|
|
|
|
describe('主系统仓库地址(P1-10):带进我方订单', () => {
|
|
it('备货行模型与映射都读 branch_name / branch_address(拉取与 webhook 同口径)', () => {
|
|
expect(prepApi).toContain('branchName: string | null;');
|
|
expect(prepApi).toContain('branchAddress: string | null;');
|
|
expect(prepApi).toContain('branchName: raw?.branch_name');
|
|
expect(prepApi).toContain('branchAddress:');
|
|
expect(prepApi).toContain('raw?.branch_address');
|
|
expect(webhookRoutes).toContain('raw?.branch_address');
|
|
});
|
|
|
|
it('导入建单时仓库地址优先:mainBranchAddress 进 resolveImportDeliveryAddress 且排在最前', () => {
|
|
expect(importService).toContain('mainBranchAddress');
|
|
const start = importService.indexOf('async function resolveImportDeliveryAddress');
|
|
const fn = importService.slice(start, start + 2200);
|
|
// 主系统地址命中即返回(在客户档案/上次填写之前)
|
|
const mainHit = fn.indexOf('if (mainBranchAddress)');
|
|
const customerHit = fn.indexOf('FROM customers c');
|
|
expect(mainHit).toBeGreaterThan(0);
|
|
expect(customerHit).toBeGreaterThan(mainHit);
|
|
// 建单调用点确实把当日首行的分公司地址传了进去
|
|
expect(importService).toContain('mainBranchAddress:');
|
|
expect(importService).toMatch(/allRows\.find\(\(row\) => row\.branchAddress\)/);
|
|
});
|
|
|
|
it('只补空的客户档案地址,不覆盖人工维护过的地址', () => {
|
|
const start = importService.indexOf('async function resolveImportDeliveryAddress');
|
|
const fn = importService.slice(start, start + 2200);
|
|
expect(fn).toContain("NULLIF(TRIM(COALESCE(address, '')), '') IS NULL");
|
|
});
|
|
});
|