111 lines
2.6 KiB
TypeScript
111 lines
2.6 KiB
TypeScript
import {
|
|
AD_GET_BASIC_ROUTE_CONTROLLER,
|
|
AD_GET_DETAILED_ROUTE_CONTROLLER,
|
|
} from '@modules/ad/ad.di-tokens';
|
|
import { Point } from '@modules/ad/core/application/types/point.type';
|
|
import { Route } from '@modules/ad/core/application/types/route.type';
|
|
import { RouteProvider } from '@modules/ad/infrastructure/route-provider';
|
|
import { GetRouteControllerPort } from '@modules/geography/core/application/ports/get-route-controller.port';
|
|
import { Test, TestingModule } from '@nestjs/testing';
|
|
|
|
const originPoint: Point = {
|
|
lat: 48.689445,
|
|
lon: 6.17651,
|
|
};
|
|
const destinationPoint: Point = {
|
|
lat: 48.8566,
|
|
lon: 2.3522,
|
|
};
|
|
|
|
const mockGetBasicRouteController: GetRouteControllerPort = {
|
|
get: jest.fn().mockImplementationOnce(() => ({
|
|
distance: 350101,
|
|
duration: 14422,
|
|
fwdAzimuth: 273,
|
|
backAzimuth: 93,
|
|
distanceAzimuth: 336544,
|
|
points: [
|
|
{
|
|
lon: 6.1765102,
|
|
lat: 48.689445,
|
|
},
|
|
{
|
|
lon: 4.984578,
|
|
lat: 48.725687,
|
|
},
|
|
{
|
|
lon: 2.3522,
|
|
lat: 48.8566,
|
|
},
|
|
],
|
|
})),
|
|
};
|
|
|
|
const mockGetDetailedRouteController: GetRouteControllerPort = {
|
|
get: jest.fn().mockImplementationOnce(() => ({
|
|
distance: 350102,
|
|
duration: 14423,
|
|
fwdAzimuth: 273,
|
|
backAzimuth: 93,
|
|
distanceAzimuth: 336544,
|
|
points: [
|
|
{
|
|
lon: 6.1765102,
|
|
lat: 48.689445,
|
|
},
|
|
{
|
|
lon: 4.984578,
|
|
lat: 48.725687,
|
|
},
|
|
{
|
|
lon: 2.3522,
|
|
lat: 48.8566,
|
|
},
|
|
],
|
|
})),
|
|
};
|
|
|
|
describe('Route provider', () => {
|
|
let routeProvider: RouteProvider;
|
|
|
|
beforeAll(async () => {
|
|
const module: TestingModule = await Test.createTestingModule({
|
|
providers: [
|
|
RouteProvider,
|
|
{
|
|
provide: AD_GET_BASIC_ROUTE_CONTROLLER,
|
|
useValue: mockGetBasicRouteController,
|
|
},
|
|
{
|
|
provide: AD_GET_DETAILED_ROUTE_CONTROLLER,
|
|
useValue: mockGetDetailedRouteController,
|
|
},
|
|
],
|
|
}).compile();
|
|
|
|
routeProvider = module.get<RouteProvider>(RouteProvider);
|
|
});
|
|
|
|
it('should be defined', () => {
|
|
expect(routeProvider).toBeDefined();
|
|
});
|
|
|
|
it('should provide a basic route', async () => {
|
|
const route: Route = await routeProvider.getBasic([
|
|
originPoint,
|
|
destinationPoint,
|
|
]);
|
|
expect(route.distance).toBe(350101);
|
|
expect(route.duration).toBe(14422);
|
|
});
|
|
|
|
it('should provide a detailed route', async () => {
|
|
const route: Route = await routeProvider.getDetailed([
|
|
originPoint,
|
|
destinationPoint,
|
|
]);
|
|
expect(route.distance).toBe(350102);
|
|
expect(route.duration).toBe(14423);
|
|
});
|
|
});
|