27 lines
1.1 KiB
TypeScript
27 lines
1.1 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
|
|
const { amapRoutes } = vi.hoisted(() => ({
|
|
amapRoutes: { planRoadRoute: vi.fn() },
|
|
}));
|
|
vi.mock('../../../src/services/amap/amap.routes', () => amapRoutes);
|
|
|
|
import { RoutesService } from '../../../src/nest/routes/routes.service';
|
|
|
|
describe('RoutesService', () => {
|
|
it('delegates road route planning to the AMap adapter', async () => {
|
|
amapRoutes.planRoadRoute.mockResolvedValue({ supported: true, coordinates: [[1, 2]] });
|
|
|
|
await expect(new RoutesService().plan({ mode: 'driving', points: [{ lat: 39.9, lng: 116.3 }, { lat: 40, lng: 116.4 }] })).resolves.toEqual({
|
|
supported: true,
|
|
coordinates: [[1, 2]],
|
|
});
|
|
expect(amapRoutes.planRoadRoute).toHaveBeenCalledWith(expect.anything(), [{ lat: 39.9, lng: 116.3 }, { lat: 40, lng: 116.4 }], 'driving');
|
|
});
|
|
|
|
it('rejects transit mode because it is served by /api/transit', async () => {
|
|
await expect(new RoutesService().plan({ mode: 'transit', points: [{ lat: 1, lng: 2 }, { lat: 3, lng: 4 }] })).rejects.toMatchObject({
|
|
status: 400,
|
|
});
|
|
});
|
|
});
|