来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
116 lines
3.1 KiB
TypeScript
116 lines
3.1 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
||
import {
|
||
computeUnloadSeconds,
|
||
pickGeofenceEnterTask,
|
||
shouldMarkGeofenceEnter,
|
||
shouldTakeOpenEnterOnComplete,
|
||
type GeofenceCandidate,
|
||
} from '../src/services/deliveryGeofenceLogic';
|
||
|
||
const A: GeofenceCandidate = {
|
||
task_code: 'T1',
|
||
lat: 31.23,
|
||
lng: 121.47,
|
||
geofence_entered_at: null,
|
||
created_at: '2026-09-17T05:00:00+08:00',
|
||
};
|
||
const B: GeofenceCandidate = {
|
||
task_code: 'T2',
|
||
lat: 31.2305,
|
||
lng: 121.4704,
|
||
geofence_entered_at: null,
|
||
created_at: '2026-09-17T05:01:00+08:00',
|
||
};
|
||
|
||
const nearB = { lat: 31.2305, lng: 121.4704, radiusM: 300 };
|
||
|
||
describe('delivery geofence / unload', () => {
|
||
it('unload seconds = end − enter', () => {
|
||
expect(
|
||
computeUnloadSeconds('2026-09-17T06:00:00+08:00', '2026-09-17T06:08:30+08:00')
|
||
).toBe(510);
|
||
});
|
||
|
||
it('缺进圈或结束 → 时长空;负差空', () => {
|
||
expect(computeUnloadSeconds(null, '2026-09-17T06:08:00+08:00')).toBeNull();
|
||
expect(computeUnloadSeconds('2026-09-17T06:08:00+08:00', null)).toBeNull();
|
||
expect(
|
||
computeUnloadSeconds('2026-09-17T06:10:00+08:00', '2026-09-17T06:08:00+08:00')
|
||
).toBeNull();
|
||
});
|
||
|
||
it('两家都在圈内取离点更近的一单', () => {
|
||
const picked = pickGeofenceEnterTask([B, A], nearB);
|
||
expect(picked?.task_code).toBe('T2');
|
||
});
|
||
|
||
it('第一单仍配送中且已进圈时第二单不能抢记', () => {
|
||
const enteredA = { ...A, geofence_entered_at: '2026-09-17T06:00:00+08:00' };
|
||
expect(pickGeofenceEnterTask([enteredA, B], nearB)).toBeNull();
|
||
expect(
|
||
shouldMarkGeofenceEnter({
|
||
lat: 31.23,
|
||
lng: 121.47,
|
||
radiusM: 300,
|
||
next: enteredA,
|
||
})
|
||
).toBe(false);
|
||
});
|
||
|
||
it('第一单结束后只剩第二单则写第二单', () => {
|
||
expect(pickGeofenceEnterTask([B], nearB)?.task_code).toBe('T2');
|
||
});
|
||
|
||
it('圈外 / 无坐标 / 精度过差不进圈', () => {
|
||
expect(
|
||
pickGeofenceEnterTask([A], {
|
||
lat: 31.24,
|
||
lng: 121.48,
|
||
radiusM: 300,
|
||
})
|
||
).toBeNull();
|
||
expect(
|
||
shouldMarkGeofenceEnter({
|
||
lat: 31.23,
|
||
lng: 121.47,
|
||
radiusM: 300,
|
||
next: { ...A, lat: null, lng: null },
|
||
})
|
||
).toBe(false);
|
||
expect(
|
||
pickGeofenceEnterTask([A], {
|
||
lat: 31.23,
|
||
lng: 121.47,
|
||
accuracy: 400,
|
||
radiusM: 300,
|
||
})
|
||
).toBeNull();
|
||
});
|
||
|
||
it('下一站圈内且精度可接受 → 进圈', () => {
|
||
expect(
|
||
shouldMarkGeofenceEnter({
|
||
lat: 31.2302,
|
||
lng: 121.4701,
|
||
accuracy: 20,
|
||
radiusM: 300,
|
||
next: A,
|
||
})
|
||
).toBe(true);
|
||
expect(
|
||
pickGeofenceEnterTask([A], {
|
||
lat: 31.2302,
|
||
lng: 121.4701,
|
||
accuracy: 20,
|
||
radiusM: 300,
|
||
})?.task_code
|
||
).toBe('T1');
|
||
});
|
||
|
||
it('结束配送:本单无进圈钟则拿走另一单的未完成进圈钟', () => {
|
||
expect(shouldTakeOpenEnterOnComplete(false, true)).toBe(true);
|
||
expect(shouldTakeOpenEnterOnComplete(true, true)).toBe(false);
|
||
expect(shouldTakeOpenEnterOnComplete(false, false)).toBe(false);
|
||
});
|
||
});
|