Files
SupplierSystem/server/tests/deliveryPlanOnDepart.test.ts
T
Ubuntu deb3e72750
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
chore: 以 AI 生鲜配送系统 当前版本作为 SupplierSystem 起点
来源仓库: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 经哈希比对与线上同值),
整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。
供应商系统后续开发自本提交开始。
2026-10-08 17:35:43 +08:00

112 lines
5.0 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 { readFileSync } from 'node:fs';
import path from 'path';
import { createRequire } from 'node:module';
import { describe, expect, it } from 'vitest';
import { mergeCompletedWithNearestRemaining } from '../src/services/deliveryRoutingService';
const require = createRequire(import.meta.url);
const { findNextNavTask } = require('../../miniprogram/utils/deliveryMap.js');
describe('发车首枪规划 + 完成后就近', () => {
const route = readFileSync(
path.join(__dirname, '../src/routes/mobile/mobileDeliveryRoutes.ts'),
'utf8'
);
const routing = readFileSync(
path.join(__dirname, '../src/services/deliveryRoutingService.ts'),
'utf8'
);
it('planDriverOpenTasks 只查 10/20', () => {
const start = routing.indexOf('export async function planDriverOpenTasks');
const next = routing.indexOf('export async function', start + 10);
const fn = routing.slice(start, next > start ? next : undefined);
expect(fn).toContain('task_status, 0) IN (10, 20)');
expect(fn).not.toMatch(/IN \(10, 20, 30\)/);
});
it('单笔发车仅在写入当日原点后异步规划,不 await', () => {
const startFn = route.slice(
route.indexOf("router.post('/delivery/start'"),
route.indexOf("router.post('/delivery/start-batch'")
);
expect(startFn).toContain('const wroteOrigin = await captureFirstDepartOriginOfDay');
expect(startFn).toContain('if (wroteOrigin)');
const planIdx = startFn.indexOf('planDriverOpenTasks(personCode, departPoint)');
expect(planIdx).toBeGreaterThan(-1);
expect(startFn.slice(Math.max(0, planIdx - 12), planIdx)).not.toContain('await ');
expect(startFn.slice(planIdx, planIdx + 120)).toContain('.catch(() => undefined)');
const jsonIdx = startFn.indexOf('return res.json({ success: true })');
expect(planIdx).toBeLessThan(jsonIdx);
});
it('批量发车在有成功单之后才记原点,仅 wroteOrigin 时规划', () => {
const batchFn = route.slice(route.indexOf("router.post('/delivery/start-batch'"));
const loopIdx = batchFn.indexOf('for (const task of taskRows)');
const captureIdx = batchFn.indexOf('captureFirstDepartOriginOfDay');
expect(captureIdx).toBeGreaterThan(loopIdx);
expect(batchFn).toContain('if (started.length)');
expect(batchFn).toContain('if (wroteOrigin)');
const planIdx = batchFn.indexOf('planDriverOpenTasks(personCode, departPoint)');
expect(planIdx).toBeGreaterThan(-1);
expect(batchFn.slice(Math.max(0, planIdx - 12), planIdx)).not.toContain('await ');
});
it('结束配送成功后异步就近重排,不 await、失败不拦', () => {
const stopFn = route.slice(route.indexOf("router.post('/delivery/stop'"));
const finalizeIdx = stopFn.indexOf('finalizeOrderFulfillment');
const reorderIdx = stopFn.indexOf('reorderOpenStopsFromPoint(personCode, parseRequestLatLng(req.body), taskCode)');
expect(reorderIdx).toBeGreaterThan(finalizeIdx);
expect(stopFn.slice(Math.max(0, reorderIdx - 12), reorderIdx)).not.toContain('await ');
expect(stopFn.slice(reorderIdx, reorderIdx + 160)).toContain('.catch(');
const jsonIdx = stopFn.indexOf('return res.json({ success: true })', reorderIdx);
expect(jsonIdx).toBeGreaterThan(reorderIdx);
});
it('完成后合并快照:已完成在前,就近未完成接在后', () => {
const merged = mergeCompletedWithNearestRemaining(
[{ task_code: 'A', sequence: 2 }, { task_code: 'A', sequence: 1 }],
[
{ task_code: 'C', customer_name: '近' },
{ task_code: 'B', customer_name: '远' },
{ task_code: 'A' },
]
);
expect(merged.map((s) => s.task_code)).toEqual(['A', 'C', 'B']);
expect(merged.map((s) => s.sequence)).toEqual([1, 2, 3]);
expect(merged[0].is_completed).toBe(true);
expect(merged[1].is_completed).toBe(false);
});
it('偏离触发后就近重排剩余站,不腾讯整车含 30', () => {
const start = routing.indexOf('export async function replanOnLocationDeviation');
const next = routing.indexOf('export async function', start + 10);
const fn = routing.slice(start, next > start ? next : undefined);
expect(fn).toContain('last_route_plan');
expect(fn).toContain('reorderOpenStopsFromPoint');
expect(fn).not.toContain('planDeliveryRoute');
expect(fn).not.toMatch(/IN \(10, 20, 30\)/);
});
it('下一站:进圈优先,否则未完成里 sequence 最小(含待发 10)', () => {
const tasks = [
{ task_code: 'done', task_status: 30, can_navigate: true, route_sequence: 1 },
{ task_code: 'far', task_status: 20, can_navigate: true, route_sequence: 3 },
{ task_code: 'near10', task_status: 10, can_navigate: true, route_sequence: 2 },
];
expect(findNextNavTask(tasks).task_code).toBe('near10');
expect(
findNextNavTask([
...tasks,
{
task_code: 'entered',
task_status: 20,
can_navigate: true,
geofence_entered_at: '2026-09-22T08:00:00Z',
route_sequence: 9,
},
]).task_code
).toBe('entered');
});
});