来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
67 lines
2.8 KiB
TypeScript
67 lines
2.8 KiB
TypeScript
import { readFileSync } from 'fs';
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
|
|
vi.mock('../src/db', () => ({
|
|
pool: { query: vi.fn(), connect: vi.fn() },
|
|
getRawPoolQuery: () => vi.fn(),
|
|
}));
|
|
|
|
import { managementListStatusSql } from '../src/services/deliveryTaskQueryService';
|
|
|
|
const queryService = readFileSync(
|
|
new URL('../src/services/deliveryTaskQueryService.ts', import.meta.url),
|
|
'utf8'
|
|
);
|
|
|
|
function functionBody(name: string): string {
|
|
const start = queryService.indexOf(`export async function ${name}`);
|
|
expect(start).toBeGreaterThanOrEqual(0);
|
|
const next = queryService.indexOf('export async function', start + 1);
|
|
return next >= 0 ? queryService.slice(start, next) : queryService.slice(start);
|
|
}
|
|
|
|
describe('Web 配送管理列表可查已完成', () => {
|
|
it('includeCompleted 默认放出 90,但必须已有配送任务', () => {
|
|
const sql = managementListStatusSql(true);
|
|
expect(sql).toContain('dt.task_code IS NOT NULL');
|
|
expect(sql).toMatch(/< 90 OR dt\.task_code IS NOT NULL/);
|
|
expect(sql).not.toMatch(/task_status, 10\) < 30/);
|
|
expect(managementListStatusSql(undefined)).toBe(sql);
|
|
});
|
|
|
|
it('includeCompleted=false 仍排除 90 与已完成任务', () => {
|
|
const sql = managementListStatusSql(false);
|
|
expect(sql).toContain('COALESCE(o.order_status, 0) < 90');
|
|
expect(sql).toContain('COALESCE(dt.task_status, 10) < 30');
|
|
expect(sql).not.toContain('OR dt.task_code IS NOT NULL');
|
|
});
|
|
|
|
it('管理列表查询使用 managementListStatusSql,不再写死一刀切 < 90', () => {
|
|
const body = functionBody('listDeliveryTasksForManagement');
|
|
expect(body).toContain('managementListStatusSql(input.includeCompleted)');
|
|
expect(body).not.toMatch(/AND COALESCE\(o\.order_status, 0\) < 90/);
|
|
});
|
|
|
|
it('司机列表与红点仍排除已完成', () => {
|
|
const list = functionBody('listDeliveryTasksForDriver');
|
|
const count = functionBody('countPendingDriverDeliveryTasks');
|
|
for (const body of [list, count]) {
|
|
expect(body).toContain('AND COALESCE(o.order_status, 0) < 90');
|
|
expect(body).toContain('AND COALESCE(dt.task_status, 10) < 30');
|
|
}
|
|
});
|
|
|
|
it('任务列表 SELECT 带出客户档案配送时间', () => {
|
|
expect(queryService).toContain("NULLIF(TRIM(c.delivery_time), '') AS customer_delivery_time");
|
|
expect(queryService).toContain('customer_delivery_time: raw.customer_delivery_time');
|
|
});
|
|
|
|
it('管理列表才补送达照片;司机列表不 enrich', () => {
|
|
const management = functionBody('listDeliveryTasksForManagement');
|
|
const driver = functionBody('listDeliveryTasksForDriver');
|
|
expect(management).toContain('enrichManagementSignPhotos');
|
|
expect(driver).not.toContain('enrichManagementSignPhotos');
|
|
expect(queryService).toContain("sign_type = 'delivery'");
|
|
});
|
|
});
|