来源仓库:jxc/ai-fresh-delivery 来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d 快照树: 09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件) 按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据 (生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、 deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
73 lines
3.5 KiB
TypeScript
73 lines
3.5 KiB
TypeScript
import { readFileSync } from 'node:fs';
|
||
import path from 'node:path';
|
||
import { describe, expect, it } from 'vitest';
|
||
|
||
/**
|
||
* 验收不合格退回 → **供应商也要收到通知**(缺口修复 2026-09-16)
|
||
*
|
||
* 修复前的缺口:
|
||
* 验收退回后订单回退 40→30、备货被 `resetSupplierPreparationForResupply` 打回
|
||
* 「重新供货」,但 `notifyInspectionRejected` **只发内部 4 个角色**
|
||
* (operator / admin / super_admin / purchaser)。
|
||
* 供应商侧没有主动推送 —— 供应商 webhook 也只支持 `preparations.allocated`
|
||
* 一个事件(`supplierPrepWebhookService`)→ **货被退了,供应商却不知道**。
|
||
*
|
||
* 修复:沿用本仓已有模式(`mainlineEventNotificationService.notifyPreparationsCreated`),
|
||
* 把 `supplier_code` 解析成绑定账号后逐个推送。
|
||
*
|
||
* 本测试只做**源码级契约**(该项目同类测试的既有风格),不连库。
|
||
*/
|
||
|
||
const readServer = (rel: string) => readFileSync(path.join(__dirname, '..', rel), 'utf8');
|
||
|
||
describe('验收退回:供应商通知(缺口修复)', () => {
|
||
const notifSvc = readServer('src/services/inspectionRejectNotificationService.ts');
|
||
const compliance = readServer('src/services/inspectionComplianceService.ts');
|
||
|
||
it('服务导出供应商通知,并接入既有寻址能力', () => {
|
||
expect(notifSvc).toContain('export async function notifySupplierInspectionRejected');
|
||
expect(notifSvc).toContain("import { listSupplierUsersForCodes } from './bidAwardService'");
|
||
expect(notifSvc).toContain("import { notifyRoleUsers, notifyUser } from './notificationService'");
|
||
});
|
||
|
||
it('内部提醒之后必须调用供应商提醒(否则退回对供应商仍静默)', () => {
|
||
// notifyInspectionRejected 内:内部 notifyRoleUsers 之后要有供应商调用
|
||
const idxRoles = notifSvc.indexOf('await notifyRoleUsers(');
|
||
const idxSupplier = notifSvc.indexOf('await notifySupplierInspectionRejected(input)');
|
||
expect(idxRoles).toBeGreaterThan(-1);
|
||
expect(idxSupplier).toBeGreaterThan(idxRoles);
|
||
});
|
||
|
||
it('通知类型用独立键,便于按角色分流与统计', () => {
|
||
expect(notifSvc).toContain("notifyType: 'inspection_rejected_to_supplier'");
|
||
// 内部键保持不变,避免影响既有 211 条历史通知
|
||
expect(notifSvc).toContain("notifyType: 'inspection_rejected',");
|
||
});
|
||
|
||
it('自采(无供应商)不发送,且不会因缺 supplier_code 而报错', () => {
|
||
expect(notifSvc).toContain("if (!supplierCode || String(input.sourceType || '') === 'purchase')");
|
||
expect(notifSvc).toContain('return { sent: 0, skipped: true }');
|
||
});
|
||
|
||
it('供应商无绑定账号时留痕但不抛错(属正常情况,非故障)', () => {
|
||
expect(notifSvc).toContain('无可用账号,退货通知未送出');
|
||
});
|
||
|
||
it('发送失败只记日志、不阻断验收主流程', () => {
|
||
expect(notifSvc).toContain('供应商退货通知发送失败');
|
||
expect(notifSvc).toContain('解析供应商账号失败');
|
||
});
|
||
|
||
it('调用点必须把 supplier_code / source_type / branchCode 传进来', () => {
|
||
// 三者缺任一,供应商寻址就会失败
|
||
expect(compliance).toContain('supplierCode: row.supplier_code');
|
||
expect(compliance).toContain('sourceType: row.source_type');
|
||
expect(compliance).toContain('branchCode,');
|
||
});
|
||
|
||
it('退回仍走退供链路(与本通知配套,不能被本次改动破坏)', () => {
|
||
expect(compliance).toContain('rollbackOrderForInspectionReject');
|
||
expect(compliance).toContain('resetSupplierPreparationForResupply');
|
||
});
|
||
});
|