mirror of
https://gitlab.com/mobicoop/v3/service/matcher.git
synced 2026-01-01 07:52:41 +00:00
move route compute to create service as entity creation is not async
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import { ArgumentOutOfRangeException } from '@mobicoop/ddd-library';
|
||||
import { Coordinates } from '@modules/geography/core/domain/value-objects/coordinates.value-object';
|
||||
|
||||
describe('Waypoint value object', () => {
|
||||
it('should create a waypoint value object', () => {
|
||||
const coordinatesVO = new Coordinates({
|
||||
lon: 48.689445,
|
||||
lat: 6.17651,
|
||||
});
|
||||
expect(coordinatesVO.lon).toBe(48.689445);
|
||||
expect(coordinatesVO.lat).toBe(6.17651);
|
||||
});
|
||||
it('should throw an exception if longitude is invalid', () => {
|
||||
try {
|
||||
new Coordinates({
|
||||
lon: 348.689445,
|
||||
lat: 6.17651,
|
||||
});
|
||||
} catch (e: any) {
|
||||
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
|
||||
}
|
||||
try {
|
||||
new Coordinates({
|
||||
lon: -348.689445,
|
||||
lat: 6.17651,
|
||||
});
|
||||
} catch (e: any) {
|
||||
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
|
||||
}
|
||||
});
|
||||
it('should throw an exception if latitude is invalid', () => {
|
||||
try {
|
||||
new Coordinates({
|
||||
lon: 48.689445,
|
||||
lat: 96.17651,
|
||||
});
|
||||
} catch (e: any) {
|
||||
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
|
||||
}
|
||||
try {
|
||||
new Coordinates({
|
||||
lon: 48.689445,
|
||||
lat: -96.17651,
|
||||
});
|
||||
} catch (e: any) {
|
||||
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -46,7 +46,7 @@ describe('Waypoint value object', () => {
|
||||
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
|
||||
}
|
||||
});
|
||||
it('should throw an exception if longitude is invalid', () => {
|
||||
it('should throw an exception if latitude is invalid', () => {
|
||||
try {
|
||||
new Waypoint({
|
||||
position: 0,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Role } from '@modules/geography/core/domain/route.types';
|
||||
import { GetRouteController } from '@modules/geography/interface/controllers/get-route.controller';
|
||||
import { GetBasicRouteController } from '@modules/geography/interface/controllers/get-basic-route.controller';
|
||||
import { RouteMapper } from '@modules/geography/route.mapper';
|
||||
import { QueryBus } from '@nestjs/cqrs';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
@@ -14,8 +14,8 @@ const mockRouteMapper = {
|
||||
toResponse: jest.fn(),
|
||||
};
|
||||
|
||||
describe('Get Route Controller', () => {
|
||||
let getRouteController: GetRouteController;
|
||||
describe('Get Basic Route Controller', () => {
|
||||
let getBasicRouteController: GetBasicRouteController;
|
||||
|
||||
beforeAll(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
@@ -28,11 +28,13 @@ describe('Get Route Controller', () => {
|
||||
provide: RouteMapper,
|
||||
useValue: mockRouteMapper,
|
||||
},
|
||||
GetRouteController,
|
||||
GetBasicRouteController,
|
||||
],
|
||||
}).compile();
|
||||
|
||||
getRouteController = module.get<GetRouteController>(GetRouteController);
|
||||
getBasicRouteController = module.get<GetBasicRouteController>(
|
||||
GetBasicRouteController,
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -40,12 +42,12 @@ describe('Get Route Controller', () => {
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(getRouteController).toBeDefined();
|
||||
expect(getBasicRouteController).toBeDefined();
|
||||
});
|
||||
|
||||
it('should get a route', async () => {
|
||||
jest.spyOn(mockQueryBus, 'execute');
|
||||
await getRouteController.get({
|
||||
await getBasicRouteController.get({
|
||||
roles: [Role.DRIVER],
|
||||
waypoints: [
|
||||
{
|
||||
@@ -59,11 +61,6 @@ describe('Get Route Controller', () => {
|
||||
lat: 2.3522,
|
||||
},
|
||||
],
|
||||
georouterSettings: {
|
||||
points: true,
|
||||
detailedDistance: false,
|
||||
detailedDuration: false,
|
||||
},
|
||||
});
|
||||
expect(mockQueryBus.execute).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
@@ -38,7 +38,7 @@ describe('Route Mapper', () => {
|
||||
fwdAzimuth: 283,
|
||||
backAzimuth: 93,
|
||||
distanceAzimuth: 19840,
|
||||
spacetimePoints: [],
|
||||
points: [],
|
||||
waypoints: [
|
||||
{
|
||||
position: 0,
|
||||
|
||||
Reference in New Issue
Block a user