move route compute to create service as entity creation is not async

This commit is contained in:
sbriat
2023-08-22 16:14:36 +02:00
parent 4762c844e1
commit ac8e459e90
27 changed files with 403 additions and 94 deletions

View File

@@ -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);
}
});
});

View File

@@ -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,

View File

@@ -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);
});

View File

@@ -38,7 +38,7 @@ describe('Route Mapper', () => {
fwdAzimuth: 283,
backAzimuth: 93,
distanceAzimuth: 19840,
spacetimePoints: [],
points: [],
waypoints: [
{
position: 0,