Files
SupplierSystem/server/tests/quoteSheetEditHandoff.test.ts
T
Ubuntu ca9e0ab3cc refactor(报价单): 彻底删除内部待审改价,改价一律发申请由配送商审核
用户裁定(2026-10-18):两个系统只能交流数据、不能直接修改对方数据;自己只能改自己的。
- 删除「待审改价」:service / 4 个路由 / 面板 / 相关测试;新增迁移 drop 该租户表(含 legacy_public)
- 编辑生效单:立即落本系统 + 自动发「配送商销售价确认」申请(quoteSheetEditService)
- 报价单生效/提交/审批:不再 triggerQuoteCostSync 直推对方成本价,改为发提议由对方审核
- 删除定时重试直推任务(runQuoteCostSyncReconcile)
2026-10-18 20:46:14 +08:00

114 lines
4.2 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 { beforeEach, describe, expect, it, vi } from 'vitest';
/**
* 编辑生效报价单的新口径(2026-10-18 用户裁定「方案 A + 自己只能改自己的」):
* · 供应商改**自己**报价单的销售价 ⇒ 立即落本系统;
* · 然后自动发一条「配送商销售价确认」申请给对方审核(A 方向 `submitPriceProposal`);
* · 本系统**不再**做内部待审改价,也**不再**直接推对方成本价;
* · 传递失败**不回滚**已生效改价,只把原因回给前端。
*/
const h = vi.hoisted(() => ({
updateCalls: [] as unknown[],
submitCalls: [] as unknown[],
submitImpl: null as null | (() => Promise<unknown>),
}));
vi.mock('../src/services/quoteSheetService', async (importOriginal) => {
const actual = await importOriginal<typeof import('../src/services/quoteSheetService')>();
return {
...actual,
loadQuoteSheetForUpdate: async () => ({
quote_sheet_code: 'QS1',
branch_code: 'BR002',
status: 1,
approval_status: 30,
auto_sale_price_by_cost: false,
}),
updateQuoteSheet: async (input: unknown) => {
h.updateCalls.push(input);
return { quote_sheet_code: 'QS1', items: [] };
},
};
});
vi.mock('../src/services/quotePriceProposalService', async (importOriginal) => {
const actual = await importOriginal<typeof import('../src/services/quotePriceProposalService')>();
return {
...actual,
submitPriceProposal: async (input: unknown) => {
h.submitCalls.push(input);
if (h.submitImpl) return h.submitImpl();
return {
applied: false,
replayed: false,
proposal: { id: 'p-1', status: 'pending' },
mapping: { total: 1, mapped: 1, unmapped: 0 },
};
},
};
});
import { applyQuoteSheetEditAndRequestDeliveryReview } from '../src/services/quoteSheetEditService';
const baseInput = {
quoteSheetCode: 'QS1',
operatingBranchCode: 'BR002',
ctx: { isSuperAdmin: true, permissions: ['customer_manage'] } as any,
requestedBy: null,
items: [
{ sku_code: 'SKU1', unit: '斤', price: 10, sale_price: 10, cost_price: 0 },
],
};
beforeEach(() => {
h.updateCalls = [];
h.submitCalls = [];
h.submitImpl = null;
});
describe('编辑生效报价单:自己改自己的 + 自动发申请给对方审核', () => {
it('价格编辑 ⇒ 立即落本系统,并自动发起 A 方向提议(返回 proposal_id)', async () => {
const res = await applyQuoteSheetEditAndRequestDeliveryReview(baseInput as any);
expect(res.applied).toBe(true);
expect(h.updateCalls).toHaveLength(1);
expect(h.submitCalls).toHaveLength(1);
expect((h.submitCalls[0] as any).quoteSheetCode).toBe('QS1');
expect(res.delivery_handoff).toEqual({ ok: true, proposal_id: 'p-1', status: 'pending' });
});
it('非价格编辑(无 items)⇒ 只落本系统,不发申请', async () => {
const { items, ...rest } = baseInput as any;
const res = await applyQuoteSheetEditAndRequestDeliveryReview(rest);
expect(res.applied).toBe(true);
expect(h.submitCalls).toHaveLength(0);
expect(res.delivery_handoff).toEqual({ ok: true, skipped: 'not_price_related' });
});
it('报价单没绑定主系统使用公司 ⇒ 无需传递(skipped),本地照常生效', async () => {
h.submitImpl = async () => {
throw Object.assign(new Error('该报价单没有绑定主系统分公司客户(MAIN_*),无需提交'), {
status: 400,
code: 'not_usage_company',
});
};
const res = await applyQuoteSheetEditAndRequestDeliveryReview(baseInput as any);
expect(res.applied).toBe(true);
expect(res.delivery_handoff).toMatchObject({ ok: true, skipped: 'no_usage_company' });
});
it('传递失败 ⇒ 不回滚已生效改价,返回失败原因', async () => {
h.submitImpl = async () => {
throw Object.assign(new Error('主系统暂不可用'), { status: 502, code: 'main_system_unavailable' });
};
const res = await applyQuoteSheetEditAndRequestDeliveryReview(baseInput as any);
expect(res.applied).toBe(true);
expect(h.updateCalls).toHaveLength(1);
expect(res.delivery_handoff).toMatchObject({
ok: false,
code: 'main_system_unavailable',
message: '主系统暂不可用',
});
});
});