Files
SupplierSystem/server/tests/mpDeliveryMap.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

108 lines
4.5 KiB
TypeScript

import { readFileSync } from 'fs';
import { afterEach, describe, expect, it } from 'vitest';
import { getMapClientConfig } from '../src/services/geoProvider';
import { applyRoutePlanToDriverTasks, publicRoutePlanForDriver } from '../src/services/deliveryRoutingService';
const appJson = JSON.parse(
readFileSync(new URL('../../miniprogram/app.json', import.meta.url), 'utf8')
);
const wxml = readFileSync(
new URL('../../miniprogram/components/delivery-panel/index.wxml', import.meta.url),
'utf8'
);
const panelJs = readFileSync(
new URL('../../miniprogram/components/delivery-panel/index.js', import.meta.url),
'utf8'
);
const locUtil = readFileSync(
new URL('../../miniprogram/utils/deliveryLocation.js', import.meta.url),
'utf8'
);
const mapUtil = readFileSync(
new URL('../../miniprogram/utils/deliveryMap.js', import.meta.url),
'utf8'
);
const exampleConfig = readFileSync(
new URL('../../miniprogram/config.example.js', import.meta.url),
'utf8'
);
const mobileRoute = readFileSync(
new URL('../src/routes/mobile/mobileDeliveryRoutes.ts', import.meta.url),
'utf8'
);
describe('小程序配送腾讯地图脚手架', () => {
const prevKey = process.env.TENCENT_MAP_KEY;
const prevSk = process.env.TENCENT_MAP_SK;
afterEach(() => {
if (prevKey === undefined) delete process.env.TENCENT_MAP_KEY;
else process.env.TENCENT_MAP_KEY = prevKey;
if (prevSk === undefined) delete process.env.TENCENT_MAP_SK;
else process.env.TENCENT_MAP_SK = prevSk;
});
it('declares getLocation, background location, and Tencent route-plan plugin', () => {
expect(appJson.requiredPrivateInfos).toContain('getLocation');
expect(appJson.requiredPrivateInfos).toContain('onLocationChange');
expect(appJson.requiredPrivateInfos).toContain('startLocationUpdateBackground');
expect(appJson.requiredPrivateInfos).not.toContain('startLocationUpdate');
expect(appJson.requiredBackgroundModes).toContain('location');
expect(appJson.plugins['route-plan']).toMatchObject({
version: '2.2.0',
provider: 'wx50b5593e81dd937a',
});
expect(appJson.permission['scope.userLocation'].desc.length).toBeLessThanOrEqual(30);
expect(appJson.permission['scope.userLocationBackground'].desc.length).toBeLessThanOrEqual(30);
expect(appJson.permission['scope.userLocation'].desc).toMatch(/导航/);
});
it('shows planned route polyline, next-stop nav, and location watch while delivering', () => {
expect(wxml).toMatch(/<map/);
expect(wxml).toMatch(/polyline/);
expect(wxml).toMatch(/onNavigateNext/);
expect(panelJs).toMatch(/startDeliveryLocationWatch/);
expect(panelJs).toMatch(/reportDeliveryLocation/);
expect(panelJs).not.toMatch(/hide\(\)\s*\{[\s\S]{0,80}stopDeliveryLocationWatch/);
expect(locUtil).toMatch(/startLocationUpdateBackground/);
expect(locUtil).not.toMatch(/wx\.startLocationUpdate\s*\(/);
expect(mobileRoute).toMatch(/markDeliveryGeofenceEntered/);
const locCall = panelJs.slice(panelJs.indexOf('reportDeliveryLocation({'), panelJs.indexOf('is_delivering: true'));
expect(locCall).not.toMatch(/order_code/);
expect(mapUtil).toMatch(/wx\.openLocation/);
expect(mapUtil).not.toMatch(/plugin:\/\/route-plan/);
expect(exampleConfig).not.toMatch(/tencentMapKey/);
expect(mobileRoute).toMatch(/route_plan: routePlan/);
expect(mobileRoute).toMatch(/map_client: getMapClientConfig/);
});
it('orders driver tasks by last_route_plan sequence', () => {
const plan = publicRoutePlanForDriver({
departure_time: '05:10',
finish_time: '07:00',
total_distance_km: 12,
stops: [
{ sequence: 2, task_code: 'T2', lat: 31, lng: 121 },
{ sequence: 1, task_code: 'T1', lat: 31.1, lng: 121.1 },
],
});
expect(plan?.stops.map((s) => s.task_code)).toEqual(['T1', 'T2']);
const rows = applyRoutePlanToDriverTasks(
[{ task_code: 'T2' }, { task_code: 'T9' }, { task_code: 'T1' }],
plan
);
expect(rows.map((r) => r.task_code)).toEqual(['T1', 'T2', 'T9']);
expect(rows[0].route_sequence).toBe(1);
expect(rows[2].route_sequence).toBeNull();
});
it('exposes tencent key from env and never returns SK', () => {
process.env.TENCENT_MAP_KEY = 'test-client-key';
process.env.TENCENT_MAP_SK = 'must-not-leave-server';
expect(getMapClientConfig()).toEqual({ provider: 'tencent', key: 'test-client-key' });
expect(JSON.stringify(getMapClientConfig())).not.toMatch(/must-not-leave-server/);
delete process.env.TENCENT_MAP_KEY;
expect(getMapClientConfig()).toEqual({ provider: 'none', key: '' });
});
});