来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
170 lines
7.6 KiB
TypeScript
170 lines
7.6 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
const { query, getSupplierPrepPriceAmendConfig } = vi.hoisted(() => ({
|
|
query: vi.fn(),
|
|
getSupplierPrepPriceAmendConfig: vi.fn(),
|
|
}));
|
|
|
|
vi.mock('../src/db', () => ({
|
|
pool: { query, connect: vi.fn() },
|
|
getRawPoolQuery: () => vi.fn(),
|
|
}));
|
|
|
|
vi.mock('../src/services/preparationPriceAmendConfigService', () => ({
|
|
getSupplierPrepPriceAmendConfig,
|
|
}));
|
|
|
|
import {
|
|
countSupplierPendingPreparations,
|
|
countSupplierPriceAmendPreparations,
|
|
} from '../src/services/supplierPreparationStatusService';
|
|
import { countPendingProcessingTasks } from '../src/services/processingTaskService';
|
|
import { countPendingPickingOrders } from '../src/services/orderManagementQueryService';
|
|
import { countPendingInspectionsAll } from '../src/services/inspectionQueryService';
|
|
import { countPendingPurchaserTasks, countPendingBranchPurchaseTasks } from '../src/services/purchaseOrderQueryService';
|
|
import { countPendingDriverDeliveryTasks } from '../src/services/deliveryTaskQueryService';
|
|
|
|
describe('mobile badge count SQL', () => {
|
|
beforeEach(() => {
|
|
query.mockReset();
|
|
getSupplierPrepPriceAmendConfig.mockReset();
|
|
getSupplierPrepPriceAmendConfig.mockResolvedValue({ window_hours: 24, enabled: true });
|
|
});
|
|
|
|
it('countSupplierPendingPreparations 对齐 /preparations active 视口径且无 LIMIT', async () => {
|
|
query.mockResolvedValueOnce({ rows: [{ c: 4 }] });
|
|
const count = await countSupplierPendingPreparations('SUP1');
|
|
expect(count).toBe(4);
|
|
const [sql, params] = query.mock.calls[0];
|
|
const text = String(sql);
|
|
expect(text).toContain('FROM supplier_preparations');
|
|
expect(text).toContain('sp.supplier_code = $1');
|
|
expect(text).toMatch(/sp\.prepare_status\s*<\s*30/);
|
|
expect(text).toContain('is_history_repair');
|
|
expect(text).toContain('_o_active.deleted_at IS NULL');
|
|
expect(text).not.toMatch(/LIMIT/i);
|
|
expect(params).toEqual(['SUP1']);
|
|
});
|
|
|
|
it('countSupplierPendingPreparations 空供应商直接返回 0 且不打库', async () => {
|
|
expect(await countSupplierPendingPreparations(' ')).toBe(0);
|
|
expect(query).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('countSupplierPriceAmendPreparations 对齐 view=price_amend 且无 LIMIT', async () => {
|
|
query.mockResolvedValueOnce({ rows: [{ c: 3 }] });
|
|
const count = await countSupplierPriceAmendPreparations('SUP1', 'B1');
|
|
expect(count).toBe(3);
|
|
expect(getSupplierPrepPriceAmendConfig).toHaveBeenCalledWith('B1');
|
|
const [sql, params] = query.mock.calls[0];
|
|
const text = String(sql);
|
|
expect(text).toContain('FROM supplier_preparations');
|
|
expect(text).toMatch(/sp\.prepare_status\s*=\s*30/);
|
|
expect(text).toContain('transferred_to_purchase');
|
|
expect(text).toContain('is_stockout');
|
|
expect(text).toContain("INTERVAL '1 hour'");
|
|
expect(text).toContain('is_history_repair');
|
|
expect(text).toContain('_o_active.deleted_at IS NULL');
|
|
expect(text).not.toMatch(/LIMIT/i);
|
|
expect(params).toEqual(['SUP1', 24]);
|
|
});
|
|
|
|
it('countSupplierPriceAmendPreparations window_hours=0 返回 0 且不 COUNT 备货表', async () => {
|
|
getSupplierPrepPriceAmendConfig.mockResolvedValueOnce({ window_hours: 0, enabled: false });
|
|
expect(await countSupplierPriceAmendPreparations('SUP1', 'B1')).toBe(0);
|
|
expect(query).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('countPendingProcessingTasks 覆盖今天+下单日轴 work/inspect 且含无订单需求单、无 LIMIT', async () => {
|
|
query.mockResolvedValueOnce({ rows: [{ c: 9 }] });
|
|
const count = await countPendingProcessingTasks();
|
|
expect(count).toBe(9);
|
|
const text = String(query.mock.calls[0][0]);
|
|
expect(text).toContain('FROM processing_tasks');
|
|
expect(text).toContain('LEFT JOIN orders o');
|
|
expect(text).toMatch(/pt\.process_status\s+IN\s*\(\s*10\s*,\s*20\s*,\s*30\s*\)/);
|
|
expect(text).toContain('pt.order_code IS NULL');
|
|
expect(text).toContain('_o_active.deleted_at IS NULL');
|
|
expect(text).toContain("AT TIME ZONE 'Asia/Shanghai'");
|
|
expect(text).toContain('pt.created_at');
|
|
expect(text).not.toContain('o.delivery_date');
|
|
expect(text).not.toMatch(/LIMIT/i);
|
|
});
|
|
|
|
it('countPendingInspectionsAll 覆盖全部待验且订单未删除、无日期、无 LIMIT', async () => {
|
|
query.mockResolvedValueOnce({ rows: [{ c: 2 }] });
|
|
const count = await countPendingInspectionsAll();
|
|
expect(count).toBe(2);
|
|
const text = String(query.mock.calls[0][0]);
|
|
expect(text).toContain('FROM inspections');
|
|
expect(text).toContain('i.inspection_time IS NULL');
|
|
expect(text).toContain('_o_active.deleted_at IS NULL');
|
|
expect(text).not.toContain('LEFT JOIN orders');
|
|
expect(text).not.toContain('delivery_date');
|
|
expect(text).not.toMatch(/LIMIT/i);
|
|
expect(text).not.toContain('source_type');
|
|
});
|
|
|
|
it('countPendingPurchaserTasks 覆盖今天+下单日待采、本人或自由池、无 LIMIT', async () => {
|
|
query.mockResolvedValueOnce({ rows: [{ c: 4 }] });
|
|
const count = await countPendingPurchaserTasks('B1', 'P1');
|
|
expect(count).toBe(4);
|
|
const [sql, params] = query.mock.calls[0];
|
|
const text = String(sql);
|
|
expect(text).toContain('FROM purchase_orders');
|
|
expect(text).toContain('LEFT JOIN orders o');
|
|
expect(text).toMatch(/po\.purchase_status\s+IN\s*\(\s*10\s*,\s*32\s*\)/);
|
|
expect(text).toContain('_o_active.deleted_at IS NULL');
|
|
expect(text).toContain('o.created_at');
|
|
expect(text).toContain("AT TIME ZONE 'Asia/Shanghai'");
|
|
expect(text).not.toMatch(/LIMIT/i);
|
|
expect(params).toEqual(['B1', 'P1']);
|
|
});
|
|
|
|
it('countPendingBranchPurchaseTasks 覆盖今天+下单日待采、分公司全部、无 LIMIT', async () => {
|
|
query.mockResolvedValueOnce({ rows: [{ c: 7 }] });
|
|
const count = await countPendingBranchPurchaseTasks('B1');
|
|
expect(count).toBe(7);
|
|
const [sql, params] = query.mock.calls[0];
|
|
const text = String(sql);
|
|
expect(text).toContain('FROM purchase_orders');
|
|
expect(text).toContain('LEFT JOIN orders o');
|
|
expect(text).toMatch(/po\.purchase_status\s+IN\s*\(\s*10\s*,\s*32\s*\)/);
|
|
expect(text).toContain('_o_active.deleted_at IS NULL');
|
|
expect(text).toContain('o.created_at');
|
|
expect(text).not.toContain('purchaser_code = $2');
|
|
expect(text).not.toMatch(/LIMIT/i);
|
|
expect(params).toEqual(['B1']);
|
|
});
|
|
|
|
it('countPendingPickingOrders 数今天配送日待处理 status<50、排除垃圾桶且无 LIMIT', async () => {
|
|
query.mockResolvedValueOnce({ rows: [{ c: 6 }] });
|
|
const count = await countPendingPickingOrders();
|
|
expect(count).toBe(6);
|
|
const text = String(query.mock.calls[0][0]);
|
|
expect(text).toContain('FROM orders o');
|
|
expect(text).toMatch(/o\.order_status\s*<\s*50/);
|
|
expect(text).toContain('o.deleted_at IS NULL');
|
|
expect(text).toContain('o.delivery_date::date');
|
|
expect(text).toContain("AT TIME ZONE 'Asia/Shanghai'");
|
|
expect(text).not.toMatch(/LIMIT/i);
|
|
});
|
|
|
|
it('countPendingDriverDeliveryTasks 数今天配送日未完成且无 LIMIT', async () => {
|
|
query.mockResolvedValueOnce({ rows: [{ c: 3 }] });
|
|
const count = await countPendingDriverDeliveryTasks({ personCode: 'D1', branchCode: 'B1' });
|
|
expect(count).toBe(3);
|
|
const [sql, params] = query.mock.calls[0];
|
|
const text = String(sql);
|
|
expect(text).toContain('FROM delivery_tasks dt');
|
|
expect(text).toContain('INNER JOIN orders o');
|
|
expect(text).toMatch(/dt\.task_status[\s\S]*<\s*30/);
|
|
expect(text).toMatch(/o\.order_status[\s\S]*>=\s*50/);
|
|
expect(text).toContain('o.delivery_date');
|
|
expect(text).toContain("AT TIME ZONE 'Asia/Shanghai'");
|
|
expect(text).not.toMatch(/LIMIT/i);
|
|
expect(params[0]).toBe('D1');
|
|
expect(params[1]).toBe('B1');
|
|
});
|
|
});
|