- T1 资金/库存/报价/自采 P1(BIZ-1/2/3/4/10/13/14) - T2 主系统反向事件墓碑/改派/孤儿处理(BIZ-6/8/9) - T3 选分公司 ticket、trust proxy、角色权限收口(SEC-2/3/4) - T4 缺列/RLS/tenant 名单/FK/迁移执行器(DATA-1..8) - T5 401 登出/分页/映射口径/blob/ZIP 中文名(FE-1..4/BIZ-15) - T6 测试脚本目标守卫/config fail-fast/容器配置(OPS-2..8) - T7 前后端测试与 lint 门禁清零 - T8 应付卡片按关联订单日(口径 A) - T9 存储对象全链路归属校验、敏感列禁写、审计 target_id 超长修复
113 lines
4.0 KiB
TypeScript
113 lines
4.0 KiB
TypeScript
import express from 'express';
|
||
import request from 'supertest';
|
||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||
|
||
/**
|
||
* 竞价邀约删除/恢复:**前端传参名必须被后端识别**(2026-10-18 反向核对)。
|
||
*
|
||
* 事故:前端 `workflowApi` 按详情接口同款字段名传 `?supplier=SUP-A`,后端 delete/restore
|
||
* 只读 `supplier_code` ⇒ `supplierCode=null` ⇒ service 的 `scope=''` 会把同一轮**所有供应商**
|
||
* 的 pending/expired 行一起软删(或一起恢复)。
|
||
*
|
||
* 修复:后端同时接受 `supplier` 与 `supplier_code`。本文件只钉 HTTP 参数链路。
|
||
*/
|
||
|
||
const H = vi.hoisted(() => ({
|
||
softDelete: vi.fn(),
|
||
restore: vi.fn(),
|
||
}));
|
||
|
||
vi.mock('../src/middleware/auth', () => ({
|
||
authMiddleware: (req: { userId?: string }, _res: unknown, next: () => void) => {
|
||
req.userId = 'user-1';
|
||
next();
|
||
},
|
||
}));
|
||
|
||
vi.mock('../src/modules/workflow/context', async (importOriginal) => {
|
||
const actual = await importOriginal<typeof import('../src/modules/workflow/context')>();
|
||
return {
|
||
...actual,
|
||
getWorkflowCtx: async () => ({
|
||
userId: 'user-1',
|
||
roles: ['admin'],
|
||
permissions: ['order_manage'],
|
||
branchCode: 'BR002',
|
||
isSuperAdmin: false,
|
||
}),
|
||
requireAdminRole: () => undefined,
|
||
requireWorkflowPermission: () => undefined,
|
||
};
|
||
});
|
||
|
||
vi.mock('../src/services/tenantScope', async (importOriginal) => {
|
||
const actual = await importOriginal<typeof import('../src/services/tenantScope')>();
|
||
return { ...actual, getEffectiveBranchCode: () => 'BR002', readOperatingBranchCode: () => null };
|
||
});
|
||
|
||
vi.mock('../src/services/mainSystemBidQuotes', () => ({
|
||
listBidInvitations: vi.fn(),
|
||
refreshBidInvitation: vi.fn(),
|
||
submitBidQuotes: vi.fn(),
|
||
syncBidInvitations: vi.fn(),
|
||
}));
|
||
|
||
vi.mock('../src/services/mainSystemBidInbox', () => ({
|
||
softDeleteBidInvitation: (...args: unknown[]) => H.softDelete(...args),
|
||
restoreBidInvitation: (...args: unknown[]) => H.restore(...args),
|
||
}));
|
||
|
||
const { mountMainSystemBidWorkflowRoutes } = await import('../src/modules/workflow/routes/mainSystemBidRoutes');
|
||
|
||
function buildApp() {
|
||
const app = express();
|
||
app.use(express.json());
|
||
const router = express.Router();
|
||
mountMainSystemBidWorkflowRoutes(router);
|
||
app.use('/api/workflow', router);
|
||
return app;
|
||
}
|
||
|
||
const app = buildApp();
|
||
|
||
beforeEach(() => {
|
||
H.softDelete.mockReset();
|
||
H.restore.mockReset();
|
||
H.softDelete.mockResolvedValue({ ok: true, roundCode: 'BID001' });
|
||
H.restore.mockResolvedValue({ ok: true, roundCode: 'BID001' });
|
||
});
|
||
|
||
describe('竞价邀约删除/恢复:supplier 参数链路', () => {
|
||
it('删除:前端 `?supplier=SUP-A` 必须精确传到 service(否则会误删同轮所有供应商)', async () => {
|
||
const res = await request(app)
|
||
.post('/api/workflow/main-system/bid-invitations/round-1/delete?supplier=SUP-A')
|
||
.send({});
|
||
expect(res.status).toBe(200);
|
||
expect(H.softDelete).toHaveBeenCalledWith(
|
||
expect.objectContaining({ branchCode: 'BR002', roundId: 'round-1', supplierCode: 'SUP-A' })
|
||
);
|
||
});
|
||
|
||
it('恢复:前端 `?supplier=SUP-A` 同样必须精确传到 service', async () => {
|
||
const res = await request(app)
|
||
.post('/api/workflow/main-system/bid-invitations/round-1/restore?supplier=SUP-A')
|
||
.send({});
|
||
expect(res.status).toBe(200);
|
||
expect(H.restore).toHaveBeenCalledWith(
|
||
expect.objectContaining({ branchCode: 'BR002', roundId: 'round-1', supplierCode: 'SUP-A' })
|
||
);
|
||
});
|
||
|
||
it('兼容旧字段 `supplier_code`(query 与 body 均可)', async () => {
|
||
await request(app)
|
||
.post('/api/workflow/main-system/bid-invitations/round-1/delete?supplier_code=SUP-B')
|
||
.send({});
|
||
expect(H.softDelete).toHaveBeenLastCalledWith(expect.objectContaining({ supplierCode: 'SUP-B' }));
|
||
|
||
await request(app)
|
||
.post('/api/workflow/main-system/bid-invitations/round-1/restore')
|
||
.send({ supplier_code: 'SUP-C' });
|
||
expect(H.restore).toHaveBeenLastCalledWith(expect.objectContaining({ supplierCode: 'SUP-C' }));
|
||
});
|
||
});
|