- 详情底部保存会带 orderPatch.delivery_address;地址变化后执行坐标解析与路线重算 - 解析失败返回 delivery_address_geocode_failed,前端提示重新核验地址 - 补充契约测试
111 lines
5.4 KiB
TypeScript
111 lines
5.4 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');
|
||
// 2026-10-13:UPDATE 多写了 delivery_address_overridden(我方为准标记),断言放宽到写地址本身
|
||
expect(fn).toMatch(/UPDATE orders\s+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('地址已保存但坐标解析失败时返回 geocode_failed,前端提示重新核验', () => {
|
||
const start = manageService.indexOf('export async function updateOrderDeliveryAddress');
|
||
const fn = manageService.slice(start, start + 4200);
|
||
expect(manageService).toContain('geocode_failed: geocodeFailed');
|
||
const page = readFileSync(
|
||
new URL('../../src/pages/orders/orderManagement/OrderManagementPage.tsx', import.meta.url),
|
||
'utf8'
|
||
);
|
||
expect(page).toContain("t('orders.addressGeocodeFailed')");
|
||
expect(manageService).toContain('delivery_address_geocode_failed');
|
||
});
|
||
|
||
it('终态与垃圾桶分别拒:>=90 与 order_trashed', () => {
|
||
const start = manageService.indexOf('export async function updateOrderDeliveryAddress');
|
||
const fn = manageService.slice(start, start + 4200);
|
||
// 2026-10-13 开发者口径 1A:**已发车(>=60)就不能改地址**(原实现只拦 >=90)
|
||
expect(fn).toContain('status >= 60');
|
||
expect(fn).toContain("code: 'delivery_address_too_late'");
|
||
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");
|
||
});
|
||
});
|