Trek_CN/server/tests/unit/services/amap/amap.routes.test.ts

43 lines
1.5 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest';
import { planRoadRoute } from '../../../../src/services/amap/amap.routes';
function makePoints(count: number) {
return Array.from({ length: count }, (_, index) => ({
lat: 39.9 + index * 0.001,
lng: 116.3 + index * 0.001,
}));
}
describe('AMap road routes adapter', () => {
it('splits a route with more than the AMap waypoint limit and joins segments without duplicate points', async () => {
const client = {
get: vi.fn()
.mockResolvedValueOnce({
status: '1',
route: { paths: [{ distance: '1000', duration: '600', steps: [{ polyline: '116.403714,39.910627;116.404714,39.911627' }] }] },
})
.mockResolvedValueOnce({
status: '1',
route: { paths: [{ distance: '1000', duration: '600', steps: [{ polyline: '116.404714,39.911627;116.405714,39.912627' }] }] },
}),
};
const result = await planRoadRoute(client, makePoints(20), 'driving');
expect(result.supported).toBe(true);
expect(result.coordinates).toHaveLength(3);
expect(client.get).toHaveBeenCalledTimes(2);
});
it('returns an explicit unsupported result outside mainland China', async () => {
const client = { get: vi.fn() };
await expect(planRoadRoute(client, [{ lat: 51.5072, lng: -0.1276 }, { lat: 51.51, lng: -0.12 }], 'walking')).resolves.toEqual({
supported: false,
reason: 'AMAP_UNSUPPORTED_AREA',
});
expect(client.get).not.toHaveBeenCalled();
});
});