From 067854b697e9774de1e2c4c60b31c6b603907d3c Mon Sep 17 00:00:00 2001 From: sbriat Date: Mon, 18 Sep 2023 14:09:33 +0200 Subject: [PATCH] basic RouteCompleter --- .../queries/match/algorithm.abstract.ts | 6 +- ...ssenger-oriented-carpool-path.completer.ts | 1 - .../match/completer/route.completer.ts | 34 +++ .../queries/match/match.query-handler.ts | 6 +- .../application/queries/match/match.query.ts | 8 +- .../match/passenger-oriented-algorithm.ts | 5 + .../ad/core/domain/candidate.entity.ts | 5 + src/modules/ad/core/domain/candidate.types.ts | 7 +- .../grpc-controllers/match.grpc-controller.ts | 12 +- .../unit/core/match.query-handler.spec.ts | 42 ++-- .../ad/tests/unit/core/match.query.spec.ts | 219 ++++++++++-------- .../core/passenger-oriented-algorithm.spec.ts | 38 +-- ...er-oriented-carpool-path-completer.spec.ts | 35 +-- .../passenger-oriented-geo-filter.spec.ts | 35 +-- .../core/passenger-oriented-selector.spec.ts | 47 ++-- .../interface/match.grpc.controller.spec.ts | 10 + 16 files changed, 301 insertions(+), 209 deletions(-) create mode 100644 src/modules/ad/core/application/queries/match/completer/route.completer.ts diff --git a/src/modules/ad/core/application/queries/match/algorithm.abstract.ts b/src/modules/ad/core/application/queries/match/algorithm.abstract.ts index f993730..faeb9bc 100644 --- a/src/modules/ad/core/application/queries/match/algorithm.abstract.ts +++ b/src/modules/ad/core/application/queries/match/algorithm.abstract.ts @@ -20,6 +20,7 @@ export abstract class Algorithm { for (const processor of this.processors) { this.candidates = await processor.execute(this.candidates); } + // console.log(JSON.stringify(this.candidates, null, 2)); return this.candidates.map((candidate: CandidateEntity) => MatchEntity.create({ adId: candidate.id }), ); @@ -43,9 +44,6 @@ export abstract class Selector { * A processor processes candidates information */ export abstract class Processor { - protected readonly query: MatchQuery; - constructor(query: MatchQuery) { - this.query = query; - } + constructor(protected readonly query: MatchQuery) {} abstract execute(candidates: CandidateEntity[]): Promise; } diff --git a/src/modules/ad/core/application/queries/match/completer/passenger-oriented-carpool-path.completer.ts b/src/modules/ad/core/application/queries/match/completer/passenger-oriented-carpool-path.completer.ts index 201c5ac..f5232ab 100644 --- a/src/modules/ad/core/application/queries/match/completer/passenger-oriented-carpool-path.completer.ts +++ b/src/modules/ad/core/application/queries/match/completer/passenger-oriented-carpool-path.completer.ts @@ -49,7 +49,6 @@ export class PassengerOrientedCarpoolPathCompleter extends Completer { ), ); candidate.setCarpoolPath(carpoolPathCreator.carpoolPath()); - // console.log(JSON.stringify(candidate, null, 2)); }); return candidates; }; diff --git a/src/modules/ad/core/application/queries/match/completer/route.completer.ts b/src/modules/ad/core/application/queries/match/completer/route.completer.ts new file mode 100644 index 0000000..2f516ec --- /dev/null +++ b/src/modules/ad/core/application/queries/match/completer/route.completer.ts @@ -0,0 +1,34 @@ +import { CandidateEntity } from '@modules/ad/core/domain/candidate.entity'; +import { Completer } from './completer.abstract'; +import { MatchQuery } from '../match.query'; +import { WayStep } from '@modules/ad/core/domain/value-objects/waystep.value-object'; + +export class RouteCompleter extends Completer { + protected readonly type: RouteCompleterType; + constructor(query: MatchQuery, type: RouteCompleterType) { + super(query); + this.type = type; + } + + complete = async ( + candidates: CandidateEntity[], + ): Promise => { + await Promise.all( + candidates.map(async (candidate: CandidateEntity) => { + const candidateRoute = await this.query.routeProvider.getBasic( + (candidate.getProps().carpoolSteps as WayStep[]).map( + (wayStep: WayStep) => wayStep.point, + ), + ); + candidate.setMetrics(candidateRoute.distance, candidateRoute.duration); + return candidate; + }), + ); + return candidates; + }; +} + +export enum RouteCompleterType { + BASIC = 'basic', + DETAILED = 'detailed', +} diff --git a/src/modules/ad/core/application/queries/match/match.query-handler.ts b/src/modules/ad/core/application/queries/match/match.query-handler.ts index 14a8af5..fb263fc 100644 --- a/src/modules/ad/core/application/queries/match/match.query-handler.ts +++ b/src/modules/ad/core/application/queries/match/match.query-handler.ts @@ -7,7 +7,6 @@ import { Inject } from '@nestjs/common'; import { AdRepositoryPort } from '@modules/ad/core/application/ports/ad.repository.port'; import { AD_REPOSITORY, - AD_ROUTE_PROVIDER, INPUT_DATETIME_TRANSFORMER, PARAMS_PROVIDER, } from '@modules/ad/ad.di-tokens'; @@ -15,7 +14,6 @@ import { MatchEntity } from '@modules/ad/core/domain/match.entity'; import { DefaultParamsProviderPort } from '../../ports/default-params-provider.port'; import { DefaultParams } from '../../ports/default-params.type'; import { DateTimeTransformerPort } from '../../ports/datetime-transformer.port'; -import { RouteProviderPort } from '../../ports/route-provider.port'; @QueryHandler(MatchQuery) export class MatchQueryHandler implements IQueryHandler { @@ -27,8 +25,6 @@ export class MatchQueryHandler implements IQueryHandler { @Inject(AD_REPOSITORY) private readonly repository: AdRepositoryPort, @Inject(INPUT_DATETIME_TRANSFORMER) private readonly datetimeTransformer: DateTimeTransformerPort, - @Inject(AD_ROUTE_PROVIDER) - private readonly routeProvider: RouteProviderPort, ) { this._defaultParams = defaultParamsProvider.getParams(); } @@ -54,7 +50,7 @@ export class MatchQueryHandler implements IQueryHandler { maxDetourDurationRatio: this._defaultParams.MAX_DETOUR_DURATION_RATIO, }) .setDatesAndSchedule(this.datetimeTransformer); - await query.setRoutes(this.routeProvider); + await query.setRoutes(); let algorithm: Algorithm; switch (query.algorithmType) { diff --git a/src/modules/ad/core/application/queries/match/match.query.ts b/src/modules/ad/core/application/queries/match/match.query.ts index 3fb9a4d..8f96427 100644 --- a/src/modules/ad/core/application/queries/match/match.query.ts +++ b/src/modules/ad/core/application/queries/match/match.query.ts @@ -39,8 +39,9 @@ export class MatchQuery extends QueryBase { passengerRoute?: Route; backAzimuth?: number; private readonly originWaypoint: Waypoint; + routeProvider: RouteProviderPort; - constructor(props: MatchRequestDto) { + constructor(props: MatchRequestDto, routeProvider: RouteProviderPort) { super(); this.driver = props.driver; this.passenger = props.passenger; @@ -65,6 +66,7 @@ export class MatchQuery extends QueryBase { this.originWaypoint = this.waypoints.filter( (waypoint: Waypoint) => waypoint.position == 0, )[0]; + this.routeProvider = routeProvider; } setMissingMarginDurations = (defaultMarginDuration: number): MatchQuery => { @@ -178,7 +180,7 @@ export class MatchQuery extends QueryBase { return this; }; - setRoutes = async (routeProvider: RouteProviderPort): Promise => { + setRoutes = async (): Promise => { const roles: Role[] = []; if (this.driver) roles.push(Role.DRIVER); if (this.passenger) roles.push(Role.PASSENGER); @@ -197,7 +199,7 @@ export class MatchQuery extends QueryBase { await Promise.all( pathCreator.getBasePaths().map(async (path: Path) => ({ type: path.type, - route: await routeProvider.getBasic(path.waypoints), + route: await this.routeProvider.getBasic(path.waypoints), })), ) ).forEach((typedRoute: TypedRoute) => { diff --git a/src/modules/ad/core/application/queries/match/passenger-oriented-algorithm.ts b/src/modules/ad/core/application/queries/match/passenger-oriented-algorithm.ts index dc0642b..d9bc5af 100644 --- a/src/modules/ad/core/application/queries/match/passenger-oriented-algorithm.ts +++ b/src/modules/ad/core/application/queries/match/passenger-oriented-algorithm.ts @@ -4,6 +4,10 @@ import { PassengerOrientedCarpoolPathCompleter } from './completer/passenger-ori import { PassengerOrientedGeoFilter } from './filter/passenger-oriented-geo.filter'; import { AdRepositoryPort } from '../../ports/ad.repository.port'; import { PassengerOrientedSelector } from './selector/passenger-oriented.selector'; +import { + RouteCompleter, + RouteCompleterType, +} from './completer/route.completer'; export class PassengerOrientedAlgorithm extends Algorithm { constructor( @@ -14,6 +18,7 @@ export class PassengerOrientedAlgorithm extends Algorithm { this.selector = new PassengerOrientedSelector(query, repository); this.processors = [ new PassengerOrientedCarpoolPathCompleter(query), + new RouteCompleter(query, RouteCompleterType.BASIC), new PassengerOrientedGeoFilter(query), ]; } diff --git a/src/modules/ad/core/domain/candidate.entity.ts b/src/modules/ad/core/domain/candidate.entity.ts index 3add4e3..d932eb9 100644 --- a/src/modules/ad/core/domain/candidate.entity.ts +++ b/src/modules/ad/core/domain/candidate.entity.ts @@ -14,6 +14,11 @@ export class CandidateEntity extends AggregateRoot { this.props.carpoolSteps = waySteps; }; + setMetrics = (distance: number, duration: number): void => { + this.props.distance = distance; + this.props.duration = duration; + }; + validate(): void { // entity business rules validation to protect it's invariant before saving entity to a database } diff --git a/src/modules/ad/core/domain/candidate.types.ts b/src/modules/ad/core/domain/candidate.types.ts index b86b09b..84af6ef 100644 --- a/src/modules/ad/core/domain/candidate.types.ts +++ b/src/modules/ad/core/domain/candidate.types.ts @@ -10,6 +10,8 @@ export interface CandidateProps { driverDistance: number; driverDuration: number; carpoolSteps?: WayStepProps[]; // carpool path for the crew (driver + passenger) + distance?: number; + duration?: number; } // Properties that are needed for a Candidate creation @@ -22,11 +24,6 @@ export interface CreateCandidateProps { passengerWaypoints: PointProps[]; } -export type Spacetime = { - duration: number; - distance?: number; -}; - export enum Target { START = 'START', INTERMEDIATE = 'INTERMEDIATE', diff --git a/src/modules/ad/interface/grpc-controllers/match.grpc-controller.ts b/src/modules/ad/interface/grpc-controllers/match.grpc-controller.ts index 826b5f5..1f80b69 100644 --- a/src/modules/ad/interface/grpc-controllers/match.grpc-controller.ts +++ b/src/modules/ad/interface/grpc-controllers/match.grpc-controller.ts @@ -1,4 +1,4 @@ -import { Controller, UsePipes } from '@nestjs/common'; +import { Controller, Inject, UsePipes } from '@nestjs/common'; import { GrpcMethod, RpcException } from '@nestjs/microservices'; import { ResponseBase, RpcValidationPipe } from '@mobicoop/ddd-library'; import { RpcExceptionCode } from '@mobicoop/ddd-library'; @@ -7,6 +7,8 @@ import { QueryBus } from '@nestjs/cqrs'; import { MatchRequestDto } from './dtos/match.request.dto'; import { MatchQuery } from '@modules/ad/core/application/queries/match/match.query'; import { MatchEntity } from '@modules/ad/core/domain/match.entity'; +import { AD_ROUTE_PROVIDER } from '@modules/ad/ad.di-tokens'; +import { RouteProviderPort } from '@modules/ad/core/application/ports/route-provider.port'; @UsePipes( new RpcValidationPipe({ @@ -16,13 +18,17 @@ import { MatchEntity } from '@modules/ad/core/domain/match.entity'; ) @Controller() export class MatchGrpcController { - constructor(private readonly queryBus: QueryBus) {} + constructor( + private readonly queryBus: QueryBus, + @Inject(AD_ROUTE_PROVIDER) + private readonly routeProvider: RouteProviderPort, + ) {} @GrpcMethod('MatcherService', 'Match') async match(data: MatchRequestDto): Promise { try { const matches: MatchEntity[] = await this.queryBus.execute( - new MatchQuery(data), + new MatchQuery(data, this.routeProvider), ); return new MatchPaginatedResponseDto({ data: matches.map((match: MatchEntity) => ({ diff --git a/src/modules/ad/tests/unit/core/match.query-handler.spec.ts b/src/modules/ad/tests/unit/core/match.query-handler.spec.ts index d02303c..c96bd3b 100644 --- a/src/modules/ad/tests/unit/core/match.query-handler.spec.ts +++ b/src/modules/ad/tests/unit/core/match.query-handler.spec.ts @@ -1,6 +1,5 @@ import { AD_REPOSITORY, - AD_ROUTE_PROVIDER, INPUT_DATETIME_TRANSFORMER, PARAMS_PROVIDER, } from '@modules/ad/ad.di-tokens'; @@ -114,10 +113,6 @@ describe('Match Query Handler', () => { provide: INPUT_DATETIME_TRANSFORMER, useValue: mockInputDateTimeTransformer, }, - { - provide: AD_ROUTE_PROVIDER, - useValue: mockRouteProvider, - }, ], }).compile(); @@ -129,23 +124,26 @@ describe('Match Query Handler', () => { }); it('should return a Match entity', async () => { - const matchQuery = new MatchQuery({ - algorithmType: AlgorithmType.PASSENGER_ORIENTED, - driver: false, - passenger: true, - frequency: Frequency.PUNCTUAL, - fromDate: '2023-08-28', - toDate: '2023-08-28', - schedule: [ - { - time: '07:05', - day: 1, - margin: 900, - }, - ], - strict: false, - waypoints: [originWaypoint, destinationWaypoint], - }); + const matchQuery = new MatchQuery( + { + algorithmType: AlgorithmType.PASSENGER_ORIENTED, + driver: false, + passenger: true, + frequency: Frequency.PUNCTUAL, + fromDate: '2023-08-28', + toDate: '2023-08-28', + schedule: [ + { + time: '07:05', + day: 1, + margin: 900, + }, + ], + strict: false, + waypoints: [originWaypoint, destinationWaypoint], + }, + mockRouteProvider, + ); const matches: MatchEntity[] = await matchQueryHandler.execute(matchQuery); expect(matches.length).toBeGreaterThanOrEqual(0); }); diff --git a/src/modules/ad/tests/unit/core/match.query.spec.ts b/src/modules/ad/tests/unit/core/match.query.spec.ts index 17440de..8c0c580 100644 --- a/src/modules/ad/tests/unit/core/match.query.spec.ts +++ b/src/modules/ad/tests/unit/core/match.query.spec.ts @@ -108,17 +108,20 @@ const mockRouteProvider: RouteProviderPort = { describe('Match Query', () => { it('should set default values', async () => { - const matchQuery = new MatchQuery({ - frequency: Frequency.PUNCTUAL, - fromDate: '2023-08-28', - toDate: '2023-08-28', - schedule: [ - { - time: '01:05', - }, - ], - waypoints: [originWaypoint, destinationWaypoint], - }); + const matchQuery = new MatchQuery( + { + frequency: Frequency.PUNCTUAL, + fromDate: '2023-08-28', + toDate: '2023-08-28', + schedule: [ + { + time: '01:05', + }, + ], + waypoints: [originWaypoint, destinationWaypoint], + }, + mockRouteProvider, + ); matchQuery .setMissingMarginDurations(defaultParams.DEPARTURE_TIME_MARGIN) .setMissingStrict(defaultParams.STRICT) @@ -159,19 +162,22 @@ describe('Match Query', () => { }); it('should set good values for seats', async () => { - const matchQuery = new MatchQuery({ - frequency: Frequency.PUNCTUAL, - fromDate: '2023-08-28', - toDate: '2023-08-28', - seatsProposed: -1, - seatsRequested: -1, - schedule: [ - { - time: '07:05', - }, - ], - waypoints: [originWaypoint, destinationWaypoint], - }); + const matchQuery = new MatchQuery( + { + frequency: Frequency.PUNCTUAL, + fromDate: '2023-08-28', + toDate: '2023-08-28', + seatsProposed: -1, + seatsRequested: -1, + schedule: [ + { + time: '07:05', + }, + ], + waypoints: [originWaypoint, destinationWaypoint], + }, + mockRouteProvider, + ); matchQuery.setDefaultDriverAndPassengerParameters({ driver: defaultParams.DRIVER, passenger: defaultParams.PASSENGER, @@ -183,101 +189,114 @@ describe('Match Query', () => { }); it('should set route for a driver only', async () => { - const matchQuery = new MatchQuery({ - driver: true, - passenger: false, - frequency: Frequency.PUNCTUAL, - fromDate: '2023-08-28', - toDate: '2023-08-28', - schedule: [ - { - time: '01:05', - }, - ], - waypoints: [originWaypoint, destinationWaypoint], - }); - await matchQuery.setRoutes(mockRouteProvider); + const matchQuery = new MatchQuery( + { + driver: true, + passenger: false, + frequency: Frequency.PUNCTUAL, + fromDate: '2023-08-28', + toDate: '2023-08-28', + schedule: [ + { + time: '01:05', + }, + ], + waypoints: [originWaypoint, destinationWaypoint], + }, + mockRouteProvider, + ); + await matchQuery.setRoutes(); expect(matchQuery.driverRoute?.distance).toBe(350101); expect(matchQuery.passengerRoute).toBeUndefined(); }); it('should set route for a passenger only', async () => { - const matchQuery = new MatchQuery({ - driver: false, - passenger: true, - frequency: Frequency.PUNCTUAL, - fromDate: '2023-08-28', - toDate: '2023-08-28', - schedule: [ - { - time: '01:05', - }, - ], - waypoints: [originWaypoint, destinationWaypoint], - }); - await matchQuery.setRoutes(mockRouteProvider); + const matchQuery = new MatchQuery( + { + driver: false, + passenger: true, + frequency: Frequency.PUNCTUAL, + fromDate: '2023-08-28', + toDate: '2023-08-28', + schedule: [ + { + time: '01:05', + }, + ], + waypoints: [originWaypoint, destinationWaypoint], + }, + mockRouteProvider, + ); + await matchQuery.setRoutes(); expect(matchQuery.passengerRoute?.distance).toBe(340102); expect(matchQuery.driverRoute).toBeUndefined(); }); it('should set route for a driver and passenger', async () => { - const matchQuery = new MatchQuery({ - driver: true, - passenger: true, - frequency: Frequency.PUNCTUAL, - fromDate: '2023-08-28', - toDate: '2023-08-28', - schedule: [ - { - time: '01:05', - }, - ], - waypoints: [originWaypoint, destinationWaypoint], - }); - await matchQuery.setRoutes(mockRouteProvider); + const matchQuery = new MatchQuery( + { + driver: true, + passenger: true, + frequency: Frequency.PUNCTUAL, + fromDate: '2023-08-28', + toDate: '2023-08-28', + schedule: [ + { + time: '01:05', + }, + ], + waypoints: [originWaypoint, destinationWaypoint], + }, + mockRouteProvider, + ); + await matchQuery.setRoutes(); expect(matchQuery.driverRoute?.distance).toBe(350101); expect(matchQuery.passengerRoute?.distance).toBe(350101); }); it('should set route for a driver and passenger with 3 waypoints', async () => { - const matchQuery = new MatchQuery({ - driver: true, - passenger: true, - frequency: Frequency.PUNCTUAL, - fromDate: '2023-08-28', - toDate: '2023-08-28', - schedule: [ - { - time: '01:05', - }, - ], - waypoints: [ - originWaypoint, - intermediateWaypoint, - { ...destinationWaypoint, position: 2 }, - ], - }); - await matchQuery.setRoutes(mockRouteProvider); + const matchQuery = new MatchQuery( + { + driver: true, + passenger: true, + frequency: Frequency.PUNCTUAL, + fromDate: '2023-08-28', + toDate: '2023-08-28', + schedule: [ + { + time: '01:05', + }, + ], + waypoints: [ + originWaypoint, + intermediateWaypoint, + { ...destinationWaypoint, position: 2 }, + ], + }, + mockRouteProvider, + ); + await matchQuery.setRoutes(); expect(matchQuery.driverRoute?.distance).toBe(350101); expect(matchQuery.passengerRoute?.distance).toBe(340102); }); it('should throw an exception if route is not found', async () => { - const matchQuery = new MatchQuery({ - driver: true, - passenger: false, - frequency: Frequency.PUNCTUAL, - fromDate: '2023-08-28', - toDate: '2023-08-28', - schedule: [ - { - time: '01:05', - }, - ], - waypoints: [originWaypoint, destinationWaypoint], - }); - await expect( - matchQuery.setRoutes(mockRouteProvider), - ).rejects.toBeInstanceOf(Error); + const matchQuery = new MatchQuery( + { + driver: true, + passenger: false, + frequency: Frequency.PUNCTUAL, + fromDate: '2023-08-28', + toDate: '2023-08-28', + schedule: [ + { + time: '01:05', + }, + ], + waypoints: [originWaypoint, destinationWaypoint], + }, + mockRouteProvider, + ); + await expect(matchQuery.setRoutes()).rejects.toBeInstanceOf(Error); }); }); diff --git a/src/modules/ad/tests/unit/core/passenger-oriented-algorithm.spec.ts b/src/modules/ad/tests/unit/core/passenger-oriented-algorithm.spec.ts index 8c72f43..705a9a3 100644 --- a/src/modules/ad/tests/unit/core/passenger-oriented-algorithm.spec.ts +++ b/src/modules/ad/tests/unit/core/passenger-oriented-algorithm.spec.ts @@ -25,21 +25,29 @@ const destinationWaypoint: Waypoint = { country: 'France', }; -const matchQuery = new MatchQuery({ - algorithmType: AlgorithmType.PASSENGER_ORIENTED, - driver: false, - passenger: true, - frequency: Frequency.PUNCTUAL, - fromDate: '2023-08-28', - toDate: '2023-08-28', - schedule: [ - { - time: '07:05', - }, - ], - strict: false, - waypoints: [originWaypoint, destinationWaypoint], -}); +const matchQuery = new MatchQuery( + { + algorithmType: AlgorithmType.PASSENGER_ORIENTED, + driver: false, + passenger: true, + frequency: Frequency.PUNCTUAL, + fromDate: '2023-08-28', + toDate: '2023-08-28', + schedule: [ + { + time: '07:05', + }, + ], + strict: false, + waypoints: [originWaypoint, destinationWaypoint], + }, + { + getBasic: jest.fn().mockImplementation(() => ({ + duration: 6500, + distance: 89745, + })), + }, +); const mockMatcherRepository: AdRepositoryPort = { insertExtra: jest.fn(), diff --git a/src/modules/ad/tests/unit/core/passenger-oriented-carpool-path-completer.spec.ts b/src/modules/ad/tests/unit/core/passenger-oriented-carpool-path-completer.spec.ts index 9d607b7..cc0aa4b 100644 --- a/src/modules/ad/tests/unit/core/passenger-oriented-carpool-path-completer.spec.ts +++ b/src/modules/ad/tests/unit/core/passenger-oriented-carpool-path-completer.spec.ts @@ -24,21 +24,26 @@ const destinationWaypoint: Waypoint = { country: 'France', }; -const matchQuery = new MatchQuery({ - algorithmType: AlgorithmType.PASSENGER_ORIENTED, - driver: true, - passenger: true, - frequency: Frequency.PUNCTUAL, - fromDate: '2023-08-28', - toDate: '2023-08-28', - schedule: [ - { - time: '07:05', - }, - ], - strict: false, - waypoints: [originWaypoint, destinationWaypoint], -}); +const matchQuery = new MatchQuery( + { + algorithmType: AlgorithmType.PASSENGER_ORIENTED, + driver: true, + passenger: true, + frequency: Frequency.PUNCTUAL, + fromDate: '2023-08-28', + toDate: '2023-08-28', + schedule: [ + { + time: '07:05', + }, + ], + strict: false, + waypoints: [originWaypoint, destinationWaypoint], + }, + { + getBasic: jest.fn(), + }, +); const candidates: CandidateEntity[] = [ CandidateEntity.create({ diff --git a/src/modules/ad/tests/unit/core/passenger-oriented-geo-filter.spec.ts b/src/modules/ad/tests/unit/core/passenger-oriented-geo-filter.spec.ts index 51770d9..2782557 100644 --- a/src/modules/ad/tests/unit/core/passenger-oriented-geo-filter.spec.ts +++ b/src/modules/ad/tests/unit/core/passenger-oriented-geo-filter.spec.ts @@ -24,21 +24,26 @@ const destinationWaypoint: Waypoint = { country: 'France', }; -const matchQuery = new MatchQuery({ - algorithmType: AlgorithmType.PASSENGER_ORIENTED, - driver: true, - passenger: true, - frequency: Frequency.PUNCTUAL, - fromDate: '2023-08-28', - toDate: '2023-08-28', - schedule: [ - { - time: '07:05', - }, - ], - strict: false, - waypoints: [originWaypoint, destinationWaypoint], -}); +const matchQuery = new MatchQuery( + { + algorithmType: AlgorithmType.PASSENGER_ORIENTED, + driver: true, + passenger: true, + frequency: Frequency.PUNCTUAL, + fromDate: '2023-08-28', + toDate: '2023-08-28', + schedule: [ + { + time: '07:05', + }, + ], + strict: false, + waypoints: [originWaypoint, destinationWaypoint], + }, + { + getBasic: jest.fn(), + }, +); const candidates: CandidateEntity[] = [ CandidateEntity.create({ diff --git a/src/modules/ad/tests/unit/core/passenger-oriented-selector.spec.ts b/src/modules/ad/tests/unit/core/passenger-oriented-selector.spec.ts index 4659916..0972a6f 100644 --- a/src/modules/ad/tests/unit/core/passenger-oriented-selector.spec.ts +++ b/src/modules/ad/tests/unit/core/passenger-oriented-selector.spec.ts @@ -25,27 +25,32 @@ const destinationWaypoint: Waypoint = { country: 'France', }; -const matchQuery = new MatchQuery({ - algorithmType: AlgorithmType.PASSENGER_ORIENTED, - driver: true, - passenger: true, - frequency: Frequency.PUNCTUAL, - fromDate: '2023-06-21', - toDate: '2023-06-21', - useAzimuth: true, - azimuthMargin: 10, - useProportion: true, - proportion: 0.3, - schedule: [ - { - day: 3, - time: '07:05', - margin: 900, - }, - ], - strict: false, - waypoints: [originWaypoint, destinationWaypoint], -}); +const matchQuery = new MatchQuery( + { + algorithmType: AlgorithmType.PASSENGER_ORIENTED, + driver: true, + passenger: true, + frequency: Frequency.PUNCTUAL, + fromDate: '2023-06-21', + toDate: '2023-06-21', + useAzimuth: true, + azimuthMargin: 10, + useProportion: true, + proportion: 0.3, + schedule: [ + { + day: 3, + time: '07:05', + margin: 900, + }, + ], + strict: false, + waypoints: [originWaypoint, destinationWaypoint], + }, + { + getBasic: jest.fn(), + }, +); matchQuery.driverRoute = { distance: 150120, duration: 6540, diff --git a/src/modules/ad/tests/unit/interface/match.grpc.controller.spec.ts b/src/modules/ad/tests/unit/interface/match.grpc.controller.spec.ts index 91020a9..cf614ed 100644 --- a/src/modules/ad/tests/unit/interface/match.grpc.controller.spec.ts +++ b/src/modules/ad/tests/unit/interface/match.grpc.controller.spec.ts @@ -1,4 +1,6 @@ import { RpcExceptionCode } from '@mobicoop/ddd-library'; +import { AD_ROUTE_PROVIDER } from '@modules/ad/ad.di-tokens'; +import { RouteProviderPort } from '@modules/ad/core/application/ports/route-provider.port'; import { AlgorithmType } from '@modules/ad/core/application/types/algorithm.types'; import { Frequency } from '@modules/ad/core/domain/ad.types'; import { MatchEntity } from '@modules/ad/core/domain/match.entity'; @@ -62,6 +64,10 @@ const mockQueryBus = { }), }; +const mockRouteProvider: RouteProviderPort = { + getBasic: jest.fn(), +}; + describe('Match Grpc Controller', () => { let matchGrpcController: MatchGrpcController; @@ -73,6 +79,10 @@ describe('Match Grpc Controller', () => { provide: QueryBus, useValue: mockQueryBus, }, + { + provide: AD_ROUTE_PROVIDER, + useValue: mockRouteProvider, + }, ], }).compile();