来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
99 lines
3.5 KiB
TypeScript
99 lines
3.5 KiB
TypeScript
import { readFileSync } from 'fs';
|
|
import path from 'path';
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
|
|
const { query } = vi.hoisted(() => ({
|
|
query: vi.fn(),
|
|
}));
|
|
|
|
vi.mock('../src/db', () => ({
|
|
pool: { query, connect: vi.fn() },
|
|
getRawPoolQuery: () => vi.fn(),
|
|
}));
|
|
|
|
vi.mock('../src/services/bidConfigService', () => ({
|
|
getBidSettings: vi.fn(),
|
|
assertBidEnabled: vi.fn(),
|
|
}));
|
|
|
|
vi.mock('../src/services/inventoryStockCoverService', () => ({
|
|
applyStockCoverForOrder: vi.fn(),
|
|
}));
|
|
|
|
vi.mock('../src/services/bidAwardService', () => ({
|
|
notifySuppliersBidOpened: vi.fn(),
|
|
}));
|
|
|
|
import { dropSkusFromActivePerOrderBidRoundsIfNoUnassignedRemain } from '../src/services/bidRoundService';
|
|
|
|
describe('订单列表自采 vs 未分配隔离', () => {
|
|
const allocSrc = readFileSync(
|
|
path.join(__dirname, '../src/services/orderAllocationService.ts'),
|
|
'utf8'
|
|
);
|
|
const manageSrc = readFileSync(
|
|
path.join(__dirname, '../src/services/orderManageItemsService.ts'),
|
|
'utf8'
|
|
);
|
|
const bidSrc = readFileSync(path.join(__dirname, '../src/services/bidRoundService.ts'), 'utf8');
|
|
|
|
it('软落仍关闭未分配转自采,只对 forceSelfPurchaseItemIds 建单', () => {
|
|
expect(allocSrc).toMatch(/selfPurchaseUnassigned:\s*false/);
|
|
expect(allocSrc).toContain('forceSelfPurchaseItemIds');
|
|
expect(manageSrc).toContain('forceSelfPurchaseItemIds');
|
|
expect(manageSrc).not.toMatch(/selfPurchaseUnassigned:\s*true/);
|
|
});
|
|
|
|
it('不改 listOrderSkusNeedingBidProcure 把 INTERNAL 剔出竞价范围', () => {
|
|
const fnStart = bidSrc.indexOf('export async function listOrderSkusNeedingBidProcure');
|
|
const fnEnd = bidSrc.indexOf(
|
|
'export async function dropSkusFromActivePerOrderBidRoundsIfNoUnassignedRemain'
|
|
);
|
|
expect(fnStart).toBeGreaterThan(0);
|
|
const body = bidSrc.slice(fnStart, fnEnd > fnStart ? fnEnd : fnStart + 5000);
|
|
expect(body).not.toMatch(/supplier_code\s*<>\s*'INTERNAL'|NOT IN \('INTERNAL'/);
|
|
});
|
|
|
|
it('已入库改履约方走转挂完成态,不红冲、不建 OIS', () => {
|
|
expect(manageSrc).toContain('reattributeInboundFulfillment');
|
|
expect(manageSrc).not.toContain('reversePurchaseInboundForSupplierSwitch');
|
|
expect(manageSrc).toContain('inboundReattributeItemIds');
|
|
expect(manageSrc).not.toContain("code: 'self_purchase_blocked_inbound'");
|
|
});
|
|
|
|
it('已落库自采行改数量也进 force 名单;仓内加工仍禁止改派供应商', () => {
|
|
expect(manageSrc).toMatch(/forceSelfPurchaseItemIds\.push\(id\)/);
|
|
expect(manageSrc).toContain('warehouse_processing_self_purchase_only');
|
|
});
|
|
|
|
it('该 SKU 已无未分配净需求时从进行中按单轮次删除标的', async () => {
|
|
const client = {
|
|
query: vi
|
|
.fn()
|
|
.mockResolvedValueOnce({ rows: [] })
|
|
.mockResolvedValueOnce({ rowCount: 1, rows: [] }),
|
|
};
|
|
const dropped = await dropSkusFromActivePerOrderBidRoundsIfNoUnassignedRemain({
|
|
orderCode: 'ORD1',
|
|
skuCodes: ['SKU_A'],
|
|
client,
|
|
});
|
|
expect(dropped).toEqual(['SKU_A']);
|
|
expect(client.query).toHaveBeenCalledTimes(2);
|
|
expect(String(client.query.mock.calls[1][0])).toContain('DELETE FROM bid_round_items');
|
|
});
|
|
|
|
it('仍有未分配兄弟行时不删标的', async () => {
|
|
const client = {
|
|
query: vi.fn().mockResolvedValueOnce({ rows: [{ sku_code: 'SKU_A' }] }),
|
|
};
|
|
const dropped = await dropSkusFromActivePerOrderBidRoundsIfNoUnassignedRemain({
|
|
orderCode: 'ORD1',
|
|
skuCodes: ['SKU_A'],
|
|
client,
|
|
});
|
|
expect(dropped).toEqual([]);
|
|
expect(client.query).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|