diff --git a/src/app.module.ts b/src/app.module.ts index 8236fec..30da99c 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -5,7 +5,7 @@ import { ConfigModule } from '@nestjs/config'; import { ConfigurationModule } from './modules/configuration/configuration.module'; import { HealthModule } from './modules/health/health.module'; import { MatcherModule } from './modules/matcher/matcher.module'; -import { AdModule } from './modules/ad/ad.modules'; +import { AdModule } from './modules/ad/ad.module'; @Module({ imports: [ diff --git a/src/modules/ad/ad.modules.ts b/src/modules/ad/ad.module.ts similarity index 100% rename from src/modules/ad/ad.modules.ts rename to src/modules/ad/ad.module.ts diff --git a/src/modules/ad/domain/dtos/create-ad.request.ts b/src/modules/ad/domain/dtos/create-ad.request.ts index 02fcd41..a540458 100644 --- a/src/modules/ad/domain/dtos/create-ad.request.ts +++ b/src/modules/ad/domain/dtos/create-ad.request.ts @@ -43,37 +43,37 @@ export class CreateAdRequest { @IsOptional() @IsString() @AutoMap() - monTime: string | null; + monTime?: string | null; @IsOptional() @IsString() @AutoMap() - tueTime: string | null; + tueTime?: string | null; @IsOptional() @IsString() @AutoMap() - wedTime: string | null; + wedTime?: string | null; @IsOptional() @IsString() @AutoMap() - thuTime!: string | null; + thuTime?: string | null; @IsOptional() @IsString() @AutoMap() - friTime: string | null; + friTime?: string | null; @IsOptional() @IsString() @AutoMap() - satTime: string | null; + satTime?: string | null; @IsOptional() @IsString() @AutoMap() - sunTime: string | null; + sunTime?: string | null; @IsNumber() @AutoMap() @@ -127,7 +127,7 @@ export class CreateAdRequest { @IsOptional() @IsNumber() @AutoMap() - seatsUsed: number; + seatsUsed?: number; @IsString() @AutoMap() @@ -137,5 +137,5 @@ export class CreateAdRequest { @AutoMap() updatedAt: string; - timezone: string; + timezone?: string; } diff --git a/src/modules/ad/domain/entities/time-converter.ts b/src/modules/ad/domain/entities/time-converter.ts index b5910e6..bc0418a 100644 --- a/src/modules/ad/domain/entities/time-converter.ts +++ b/src/modules/ad/domain/entities/time-converter.ts @@ -4,13 +4,16 @@ export class TimeConverter { static toUtcDatetime = ( date: string, time: string, - ianaTimezone: string, - ): Date => - date && time - ? new Date( - new DateTime(`${date}T${time}:00`, TimeZone.zone(ianaTimezone, false)) - .convert(TimeZone.zone('UTC')) - .toIsoString(), - ) - : undefined; + timezone: string, + ): Date => { + try { + return new Date( + new DateTime(`${date}T${time}:00`, TimeZone.zone(timezone, false)) + .convert(TimeZone.zone('UTC')) + .toIsoString(), + ); + } catch (e) { + return undefined; + } + }; } diff --git a/src/modules/ad/mappers/ad.profile.ts b/src/modules/ad/mappers/ad.profile.ts index 6cf8d8a..c0b61f2 100644 --- a/src/modules/ad/mappers/ad.profile.ts +++ b/src/modules/ad/mappers/ad.profile.ts @@ -55,72 +55,44 @@ export class AdProfile extends AutomapperProfile { ), forMember( (dest) => dest.monTime, - mapFrom((source) => - TimeConverter.toUtcDatetime( - source.fromDate, - source.monTime, - source.timezone, - ), + mapFrom(({ monTime: time, fromDate: date, timezone }) => + TimeConverter.toUtcDatetime(date, time, timezone), ), ), forMember( (dest) => dest.tueTime, - mapFrom((source) => - TimeConverter.toUtcDatetime( - source.fromDate, - source.tueTime, - source.timezone, - ), + mapFrom(({ tueTime: time, fromDate: date, timezone }) => + TimeConverter.toUtcDatetime(date, time, timezone), ), ), forMember( (dest) => dest.wedTime, - mapFrom((source) => - TimeConverter.toUtcDatetime( - source.fromDate, - source.wedTime, - source.timezone, - ), + mapFrom(({ wedTime: time, fromDate: date, timezone }) => + TimeConverter.toUtcDatetime(date, time, timezone), ), ), forMember( (dest) => dest.thuTime, - mapFrom((source) => - TimeConverter.toUtcDatetime( - source.fromDate, - source.thuTime, - source.timezone, - ), + mapFrom(({ thuTime: time, fromDate: date, timezone }) => + TimeConverter.toUtcDatetime(date, time, timezone), ), ), forMember( (dest) => dest.friTime, - mapFrom((source) => - TimeConverter.toUtcDatetime( - source.fromDate, - source.friTime, - source.timezone, - ), + mapFrom(({ friTime: time, fromDate: date, timezone }) => + TimeConverter.toUtcDatetime(date, time, timezone), ), ), forMember( (dest) => dest.satTime, - mapFrom((source) => - TimeConverter.toUtcDatetime( - source.fromDate, - source.satTime, - source.timezone, - ), + mapFrom(({ satTime: time, fromDate: date, timezone }) => + TimeConverter.toUtcDatetime(date, time, timezone), ), ), forMember( (dest) => dest.sunTime, - mapFrom((source) => - TimeConverter.toUtcDatetime( - source.fromDate, - source.sunTime, - source.timezone, - ), + mapFrom(({ sunTime: time, fromDate: date, timezone }) => + TimeConverter.toUtcDatetime(date, time, timezone), ), ), ); diff --git a/src/modules/ad/tests/unit/adapters/secondaries/messager.spec.ts b/src/modules/ad/tests/unit/adapters/secondaries/messager.spec.ts new file mode 100644 index 0000000..0bd23a9 --- /dev/null +++ b/src/modules/ad/tests/unit/adapters/secondaries/messager.spec.ts @@ -0,0 +1,47 @@ +import { AmqpConnection } from '@golevelup/nestjs-rabbitmq'; +import { ConfigService } from '@nestjs/config'; +import { Test, TestingModule } from '@nestjs/testing'; +import { Messager } from '../../../../adapters/secondaries/messager'; + +const mockAmqpConnection = { + publish: jest.fn().mockImplementation(), +}; + +const mockConfigService = { + get: jest.fn().mockResolvedValue({ + RMQ_EXCHANGE: 'mobicoop', + }), +}; + +describe('Messager', () => { + let messager: Messager; + + beforeAll(async () => { + const module: TestingModule = await Test.createTestingModule({ + imports: [], + providers: [ + Messager, + { + provide: AmqpConnection, + useValue: mockAmqpConnection, + }, + { + provide: ConfigService, + useValue: mockConfigService, + }, + ], + }).compile(); + + messager = module.get(Messager); + }); + + it('should be defined', () => { + expect(messager).toBeDefined(); + }); + + it('should publish a message', async () => { + jest.spyOn(mockAmqpConnection, 'publish'); + messager.publish('test.create.info', 'my-test'); + expect(mockAmqpConnection.publish).toHaveBeenCalledTimes(1); + }); +}); diff --git a/src/modules/ad/tests/unit/adapters/secondaries/timezone-finder.spec.ts b/src/modules/ad/tests/unit/adapters/secondaries/timezone-finder.spec.ts new file mode 100644 index 0000000..63d8462 --- /dev/null +++ b/src/modules/ad/tests/unit/adapters/secondaries/timezone-finder.spec.ts @@ -0,0 +1,35 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { TimezoneFinder } from '../../../../adapters/secondaries/timezone-finder'; +import { GeoTimezoneFinder } from '../../../../../geography/adapters/secondaries/geo-timezone-finder'; + +const mockGeoTimezoneFinder = { + timezones: jest.fn().mockImplementation(() => ['Europe/Paris']), +}; + +describe('Timezone Finder', () => { + let timezoneFinder: TimezoneFinder; + + beforeAll(async () => { + const module: TestingModule = await Test.createTestingModule({ + imports: [], + providers: [ + TimezoneFinder, + { + provide: GeoTimezoneFinder, + useValue: mockGeoTimezoneFinder, + }, + ], + }).compile(); + + timezoneFinder = module.get(TimezoneFinder); + }); + + it('should be defined', () => { + expect(timezoneFinder).toBeDefined(); + }); + it('should get timezone for Nancy(France) as Europe/Paris', () => { + const timezones = timezoneFinder.timezones(6.179373, 48.687913); + expect(timezones.length).toBe(1); + expect(timezones[0]).toBe('Europe/Paris'); + }); +}); diff --git a/src/modules/ad/tests/unit/domain/create-ad.usecase.spec.ts b/src/modules/ad/tests/unit/domain/create-ad.usecase.spec.ts new file mode 100644 index 0000000..c879974 --- /dev/null +++ b/src/modules/ad/tests/unit/domain/create-ad.usecase.spec.ts @@ -0,0 +1,91 @@ +import { CreateAdRequest } from '../../../domain/dtos/create-ad.request'; +import { PointType } from '../../../../geography/domain/types/point-type.enum'; +import { CreateAdUseCase } from '../../../domain/usecases/create-ad.usecase'; +import { Test, TestingModule } from '@nestjs/testing'; +import { AutomapperModule } from '@automapper/nestjs'; +import { classes } from '@automapper/classes'; +import { AdRepository } from '../../../adapters/secondaries/ad.repository'; +import { CreateAdCommand } from '../../../commands/create-ad.command'; +import { Ad } from '../../../domain/entities/ad'; +import { AdProfile } from '../../../mappers/ad.profile'; + +const mockAdRepository = {}; + +const createAdRequest: CreateAdRequest = { + uuid: '77c55dfc-c28b-4026-942e-f94e95401fb1', + driver: true, + passenger: false, + frequency: 2, + fromDate: '2023-04-26', + toDate: '2024-04-25', + monTime: '07:00', + tueTime: '07:00', + wedTime: '07:00', + thuTime: '07:00', + friTime: '07:00', + satTime: null, + sunTime: null, + monMargin: 900, + tueMargin: 900, + wedMargin: 900, + thuMargin: 900, + friMargin: 900, + satMargin: 900, + sunMargin: 900, + originType: PointType.OTHER, + destinationType: PointType.OTHER, + seatsDriver: 3, + seatsPassenger: 1, + createdAt: '2023-04-01 12:45', + updatedAt: '2023-04-01 12:45', + waypoints: [ + { lon: 6, lat: 45 }, + { lon: 6.5, lat: 45.5 }, + ], +}; + +describe('CreateAdUseCase', () => { + let createAdUseCase: CreateAdUseCase; + + beforeAll(async () => { + const module: TestingModule = await Test.createTestingModule({ + imports: [AutomapperModule.forRoot({ strategyInitializer: classes() })], + providers: [ + { + provide: AdRepository, + useValue: mockAdRepository, + }, + AdProfile, + CreateAdUseCase, + ], + }).compile(); + + createAdUseCase = module.get(CreateAdUseCase); + }); + + it('should be defined', () => { + expect(createAdUseCase).toBeDefined(); + }); + + describe('execute', () => { + it('should create an ad', async () => { + const ad = await createAdUseCase.execute( + new CreateAdCommand(createAdRequest), + ); + expect(ad).toBeInstanceOf(Ad); + }); + + // it('should throw an exception when error occurs', async () => { + // await expect( + // createAdUseCase.execute( + // new MatchQuery( + // matchRequest, + // defaultParams, + // mockGeorouterCreator, + // mockTimezoneFinder, + // ), + // ), + // ).rejects.toBeInstanceOf(MatcherException); + // }); + }); +}); diff --git a/src/modules/ad/tests/unit/domain/time-converter.spec.ts b/src/modules/ad/tests/unit/domain/time-converter.spec.ts new file mode 100644 index 0000000..5539cd9 --- /dev/null +++ b/src/modules/ad/tests/unit/domain/time-converter.spec.ts @@ -0,0 +1,35 @@ +import { TimeConverter } from '../../../domain/entities/time-converter'; + +describe('TimeConverter', () => { + it('should be defined', () => { + expect(new TimeConverter()).toBeDefined(); + }); + + it('should convert a Europe/Paris datetime to utc datetime', () => { + expect( + TimeConverter.toUtcDatetime( + '2023-05-01', + '07:00', + 'Europe/Paris', + ).getUTCHours(), + ).toBe(6); + }); + + it('should return undefined when trying to convert a Europe/Paris datetime to utc datetime without a valid date, time or timezone', () => { + expect( + TimeConverter.toUtcDatetime(undefined, '07:00', 'Europe/Paris'), + ).toBeUndefined(); + expect( + TimeConverter.toUtcDatetime('2023-13-01', '07:00', 'Europe/Paris'), + ).toBeUndefined(); + expect( + TimeConverter.toUtcDatetime('2023-05-01', undefined, 'Europe/Paris'), + ).toBeUndefined(); + expect( + TimeConverter.toUtcDatetime('2023-05-01', 'a', 'Europe/Paris'), + ).toBeUndefined(); + expect( + TimeConverter.toUtcDatetime('2023-13-01', '07:00', 'OlympusMons/Mars'), + ).toBeUndefined(); + }); +}); diff --git a/src/modules/matcher/adapters/primaries/matcher.controller.ts b/src/modules/matcher/adapters/primaries/matcher.controller.ts index 22b3b4a..76c0f9d 100644 --- a/src/modules/matcher/adapters/primaries/matcher.controller.ts +++ b/src/modules/matcher/adapters/primaries/matcher.controller.ts @@ -12,6 +12,7 @@ import { DefaultParamsProvider } from '../secondaries/default-params.provider'; import { GeorouterCreator } from '../secondaries/georouter-creator'; import { Match } from '../../domain/entities/ecosystem/match'; import { GeoTimezoneFinder } from '../../../geography/adapters/secondaries/geo-timezone-finder'; +import { TimeConverter } from '../secondaries/time-converter'; @UsePipes( new RpcValidationPipe({ @@ -27,6 +28,7 @@ export class MatcherController { @InjectMapper() private readonly _mapper: Mapper, private readonly georouterCreator: GeorouterCreator, private readonly timezoneFinder: GeoTimezoneFinder, + private readonly timeConverter: TimeConverter, ) {} @GrpcMethod('MatcherService', 'Match') @@ -38,6 +40,7 @@ export class MatcherController { this.defaultParamsProvider.getParams(), this.georouterCreator, this.timezoneFinder, + this.timeConverter, ), ); return Promise.resolve({ diff --git a/src/modules/matcher/adapters/primaries/matcher.proto b/src/modules/matcher/adapters/primaries/matcher.proto index af4e083..f18aaff 100644 --- a/src/modules/matcher/adapters/primaries/matcher.proto +++ b/src/modules/matcher/adapters/primaries/matcher.proto @@ -7,31 +7,32 @@ service MatcherService { } message MatchRequest { - repeated Point waypoints = 1; - string departure = 2; - string fromDate = 3; - Schedule schedule = 4; - bool driver = 5; - bool passenger = 6; - string toDate = 7; - int32 marginDuration = 8; - MarginDurations marginDurations = 9; - int32 seatsPassenger = 10; - int32 seatsDriver = 11; - bool strict = 12; - Algorithm algorithm = 13; - int32 remoteness = 14; - bool useProportion = 15; - int32 proportion = 16; - bool useAzimuth = 17; - int32 azimuthMargin = 18; - float maxDetourDistanceRatio = 19; - float maxDetourDurationRatio = 20; - repeated int32 exclusions = 21; - int32 identifier = 22; + Mode mode = 1; + string uuid = 2; + repeated Coordinates waypoints = 3; + string departure = 4; + string fromDate = 5; + Schedule schedule = 6; + bool driver = 7; + bool passenger = 8; + string toDate = 9; + int32 marginDuration = 10; + MarginDurations marginDurations = 11; + int32 seatsPassenger = 12; + int32 seatsDriver = 13; + bool strict = 14; + Algorithm algorithm = 15; + int32 remoteness = 16; + bool useProportion = 17; + int32 proportion = 18; + bool useAzimuth = 19; + int32 azimuthMargin = 20; + float maxDetourDistanceRatio = 21; + float maxDetourDurationRatio = 22; + repeated int32 exclusions = 23; } -message Point { +message Coordinates { float lon = 1; float lat = 2; } @@ -68,3 +69,9 @@ message Matches { repeated Match data = 1; int32 total = 2; } + +enum Mode { + MATCH = 0; + PUBLISH = 1; + PUBLISH_AND_MATCH = 2; +} diff --git a/src/modules/matcher/adapters/secondaries/default-params.provider.ts b/src/modules/matcher/adapters/secondaries/default-params.provider.ts index c67dc10..5bb3158 100644 --- a/src/modules/matcher/adapters/secondaries/default-params.provider.ts +++ b/src/modules/matcher/adapters/secondaries/default-params.provider.ts @@ -8,9 +8,7 @@ export class DefaultParamsProvider { getParams = (): IDefaultParams => { return { - DEFAULT_IDENTIFIER: parseInt( - this.configService.get('DEFAULT_IDENTIFIER'), - ), + DEFAULT_UUID: this.configService.get('DEFAULT_UUID'), MARGIN_DURATION: parseInt(this.configService.get('MARGIN_DURATION')), VALIDITY_DURATION: parseInt(this.configService.get('VALIDITY_DURATION')), DEFAULT_TIMEZONE: this.configService.get('DEFAULT_TIMEZONE'), diff --git a/src/modules/matcher/adapters/secondaries/time-converter.ts b/src/modules/matcher/adapters/secondaries/time-converter.ts new file mode 100644 index 0000000..63e8e62 --- /dev/null +++ b/src/modules/matcher/adapters/secondaries/time-converter.ts @@ -0,0 +1,21 @@ +import { Injectable } from '@nestjs/common'; +import { DateTime, TimeZone } from 'timezonecomplete'; +import { IConvertTime } from '../../domain/interfaces/time-converter.interface'; + +@Injectable() +export class TimeConverter implements IConvertTime { + toUtcDate = (date: Date, timezone: string): Date => { + try { + return new Date( + new DateTime( + `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}T${date.getHours()}:${date.getMinutes()}`, + TimeZone.zone(timezone, false), + ) + .convert(TimeZone.zone('UTC')) + .toIsoString(), + ); + } catch (e) { + return undefined; + } + }; +} diff --git a/src/modules/matcher/domain/dtos/match.request.ts b/src/modules/matcher/domain/dtos/match.request.ts index 5ffea23..bcd1824 100644 --- a/src/modules/matcher/domain/dtos/match.request.ts +++ b/src/modules/matcher/domain/dtos/match.request.ts @@ -15,19 +15,30 @@ import { Schedule } from '../types/schedule.type'; import { MarginDurations } from '../types/margin-durations.type'; import { AlgorithmType } from '../types/algorithm.enum'; import { IRequestTime } from '../interfaces/time-request.interface'; -import { IRequestPerson } from '../interfaces/person-request.interface'; +import { IRequestAd } from '../interfaces/ad-request.interface'; import { IRequestGeography } from '../interfaces/geography-request.interface'; import { IRequestRequirement } from '../interfaces/requirement-request.interface'; import { IRequestAlgorithmSettings } from '../interfaces/algorithm-settings-request.interface'; +import { Mode } from '../types/mode.enum'; export class MatchRequest implements IRequestTime, - IRequestPerson, + IRequestAd, IRequestGeography, IRequestRequirement, IRequestAlgorithmSettings { + @IsOptional() + @IsString() + @AutoMap() + uuid: string; + + @IsOptional() + @IsEnum(Mode) + @AutoMap() + mode: Mode; + @IsArray() @AutoMap() waypoints: Point[]; @@ -138,10 +149,7 @@ export class MatchRequest @IsOptional() @IsArray() - exclusions: number[]; + exclusions: string[]; - @IsOptional() - @IsInt() - @AutoMap() - identifier: number; + timezone?: string; } diff --git a/src/modules/matcher/domain/entities/ecosystem/actor.ts b/src/modules/matcher/domain/entities/ecosystem/actor.ts index 25436e5..78ea643 100644 --- a/src/modules/matcher/domain/entities/ecosystem/actor.ts +++ b/src/modules/matcher/domain/entities/ecosystem/actor.ts @@ -1,14 +1,14 @@ import { Role } from '../../types/role.enum'; import { Step } from '../../types/step.enum'; -import { Person } from './person'; +import { Ad } from './ad'; export class Actor { - person: Person; + ad: Ad; role: Role; step: Step; - constructor(person: Person, role: Role, step: Step) { - this.person = person; + constructor(ad: Ad, role: Role, step: Step) { + this.ad = ad; this.role = role; this.step = step; } diff --git a/src/modules/matcher/domain/entities/ecosystem/person.ts b/src/modules/matcher/domain/entities/ecosystem/ad.ts similarity index 54% rename from src/modules/matcher/domain/entities/ecosystem/person.ts rename to src/modules/matcher/domain/entities/ecosystem/ad.ts index 2f0906c..5046579 100644 --- a/src/modules/matcher/domain/entities/ecosystem/person.ts +++ b/src/modules/matcher/domain/entities/ecosystem/ad.ts @@ -1,24 +1,24 @@ -import { IRequestPerson } from '../../interfaces/person-request.interface'; +import { IRequestAd } from '../../interfaces/ad-request.interface'; -export class Person { - private personRequest: IRequestPerson; - private defaultIdentifier: number; +export class Ad { + private adRequest: IRequestAd; + private defaultUuid: string; private defaultMarginDuration: number; - identifier: number; + uuid: string; marginDurations: number[]; constructor( - personRequest: IRequestPerson, - defaultIdentifier: number, + adRequest: IRequestAd, + defaultUuid: string, defaultMarginDuration: number, ) { - this.personRequest = personRequest; - this.defaultIdentifier = defaultIdentifier; + this.adRequest = adRequest; + this.defaultUuid = defaultUuid; this.defaultMarginDuration = defaultMarginDuration; } init = (): void => { - this.setIdentifier(this.personRequest.identifier ?? this.defaultIdentifier); + this.setUuid(this.adRequest.uuid ?? this.defaultUuid); this.setMarginDurations([ this.defaultMarginDuration, this.defaultMarginDuration, @@ -30,8 +30,8 @@ export class Person { ]); }; - setIdentifier = (identifier: number): void => { - this.identifier = identifier; + setUuid = (uuid: string): void => { + this.uuid = uuid; }; setMarginDurations = (marginDurations: number[]): void => { diff --git a/src/modules/matcher/domain/entities/ecosystem/geography.ts b/src/modules/matcher/domain/entities/ecosystem/geography.ts index 68d1a39..9afd432 100644 --- a/src/modules/matcher/domain/entities/ecosystem/geography.ts +++ b/src/modules/matcher/domain/entities/ecosystem/geography.ts @@ -10,7 +10,7 @@ import { Role } from '../../types/role.enum'; import { IGeorouter } from '../../interfaces/georouter.interface'; import { Waypoint } from './waypoint'; import { Actor } from './actor'; -import { Person } from './person'; +import { Ad } from './ad'; import { Step } from '../../types/step.enum'; import { Path } from '../../types/path.type'; import { IFindTimezone } from '../../../../geography/domain/interfaces/timezone-finder.interface'; @@ -18,7 +18,7 @@ import { Timezoner } from './timezoner'; export class Geography { private geographyRequest: IRequestGeography; - private person: Person; + private ad: Ad; private points: Point[]; originType: PointType; destinationType: PointType; @@ -30,10 +30,10 @@ export class Geography { constructor( geographyRequest: IRequestGeography, timezoner: Timezoner, - person: Person, + ad: Ad, ) { this.geographyRequest = geographyRequest; - this.person = person; + this.ad = ad; this.points = []; this.originType = undefined; this.destinationType = undefined; @@ -178,11 +178,11 @@ export class Geography { return points.map((point, index) => { const waypoint = new Waypoint(point); if (index == 0) { - waypoint.addActor(new Actor(this.person, role, Step.START)); + waypoint.addActor(new Actor(this.ad, role, Step.START)); } else if (index == points.length - 1) { - waypoint.addActor(new Actor(this.person, role, Step.FINISH)); + waypoint.addActor(new Actor(this.ad, role, Step.FINISH)); } else { - waypoint.addActor(new Actor(this.person, role, Step.INTERMEDIATE)); + waypoint.addActor(new Actor(this.ad, role, Step.INTERMEDIATE)); } return waypoint; }); diff --git a/src/modules/matcher/domain/entities/ecosystem/time.ts b/src/modules/matcher/domain/entities/ecosystem/time.ts index 6059784..d49df7b 100644 --- a/src/modules/matcher/domain/entities/ecosystem/time.ts +++ b/src/modules/matcher/domain/entities/ecosystem/time.ts @@ -5,26 +5,30 @@ import { import { MarginDurations } from '../../types/margin-durations.type'; import { IRequestTime } from '../../interfaces/time-request.interface'; import { DAYS } from '../../types/days.const'; -import { Schedule } from '../../types/schedule.type'; +import { TimeSchedule } from '../../types/time-schedule.type'; import { Frequency } from '../../../../ad/domain/types/frequency.enum'; import { Day } from '../../types/day.type'; +import { IConvertTime } from '../../interfaces/time-converter.interface'; export class Time { private timeRequest: IRequestTime; private defaultValidityDuration: number; + private timeConverter: IConvertTime; frequency: Frequency; fromDate: Date; toDate: Date; - schedule: Schedule; + schedule: TimeSchedule; marginDurations: MarginDurations; constructor( timeRequest: IRequestTime, defaultMarginDuration: number, defaultValidityDuration: number, + timeConverter: IConvertTime, ) { this.timeRequest = timeRequest; this.defaultValidityDuration = defaultValidityDuration; + this.timeConverter = timeConverter; this.schedule = {}; this.marginDurations = { mon: defaultMarginDuration, @@ -128,8 +132,10 @@ export class Time { private setPunctualRequest = (): void => { if (this.timeRequest.departure) { this.frequency = Frequency.PUNCTUAL; - this.schedule[Day[this.fromDate.getDay()]] = - this.fromDate.getHours() + ':' + this.fromDate.getMinutes(); + this.schedule[Day[this.fromDate.getDay()]] = this.timeConverter.toUtcDate( + this.fromDate, + this.timeRequest.timezone, + ); } }; diff --git a/src/modules/matcher/domain/entities/engine/candidate.ts b/src/modules/matcher/domain/entities/engine/candidate.ts index 1a19a59..0ace859 100644 --- a/src/modules/matcher/domain/entities/engine/candidate.ts +++ b/src/modules/matcher/domain/entities/engine/candidate.ts @@ -1,5 +1,5 @@ -import { Person } from '../ecosystem/person'; +import { Ad } from '../ecosystem/ad'; export class Candidate { - person: Person; + ad: Ad; } diff --git a/src/modules/matcher/domain/interfaces/ad-request.interface.ts b/src/modules/matcher/domain/interfaces/ad-request.interface.ts new file mode 100644 index 0000000..4914482 --- /dev/null +++ b/src/modules/matcher/domain/interfaces/ad-request.interface.ts @@ -0,0 +1,3 @@ +export interface IRequestAd { + uuid?: string; +} diff --git a/src/modules/matcher/domain/interfaces/person-request.interface.ts b/src/modules/matcher/domain/interfaces/person-request.interface.ts deleted file mode 100644 index 9dd8075..0000000 --- a/src/modules/matcher/domain/interfaces/person-request.interface.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface IRequestPerson { - identifier?: number; -} diff --git a/src/modules/matcher/domain/interfaces/time-converter.interface.ts b/src/modules/matcher/domain/interfaces/time-converter.interface.ts new file mode 100644 index 0000000..cbbbfb0 --- /dev/null +++ b/src/modules/matcher/domain/interfaces/time-converter.interface.ts @@ -0,0 +1,3 @@ +export interface IConvertTime { + toUtcDate(date: Date, timezone: string): Date; +} diff --git a/src/modules/matcher/domain/interfaces/time-request.interface.ts b/src/modules/matcher/domain/interfaces/time-request.interface.ts index 1f8c6a7..d7f7df7 100644 --- a/src/modules/matcher/domain/interfaces/time-request.interface.ts +++ b/src/modules/matcher/domain/interfaces/time-request.interface.ts @@ -8,4 +8,5 @@ export interface IRequestTime { schedule?: Schedule; marginDuration?: number; marginDurations?: MarginDurations; + timezone?: string; } diff --git a/src/modules/matcher/domain/types/actor.type..ts b/src/modules/matcher/domain/types/actor.type..ts index aecaa9e..22315f7 100644 --- a/src/modules/matcher/domain/types/actor.type..ts +++ b/src/modules/matcher/domain/types/actor.type..ts @@ -1,9 +1,9 @@ -import { Person } from '../entities/ecosystem/person'; +import { Ad } from '../entities/ecosystem/ad'; import { Role } from './role.enum'; import { Step } from './step.enum'; export type Actor = { - person: Person; + ad: Ad; role: Role; step: Step; }; diff --git a/src/modules/matcher/domain/types/default-params.type.ts b/src/modules/matcher/domain/types/default-params.type.ts index f39bd3b..c91a26a 100644 --- a/src/modules/matcher/domain/types/default-params.type.ts +++ b/src/modules/matcher/domain/types/default-params.type.ts @@ -1,7 +1,7 @@ import { DefaultAlgorithmSettings } from './default-algorithm-settings.type'; export type IDefaultParams = { - DEFAULT_IDENTIFIER: number; + DEFAULT_UUID: string; MARGIN_DURATION: number; VALIDITY_DURATION: number; DEFAULT_TIMEZONE: string; diff --git a/src/modules/matcher/domain/types/mode.enum.ts b/src/modules/matcher/domain/types/mode.enum.ts new file mode 100644 index 0000000..be6d1eb --- /dev/null +++ b/src/modules/matcher/domain/types/mode.enum.ts @@ -0,0 +1,5 @@ +export enum Mode { + MATCH = 'MATCH', + PUBLISH = 'PUBLISH', + PUBLISH_AND_MATCH = 'PUBLISH_AND_MATCH', +} diff --git a/src/modules/matcher/domain/types/time-schedule.type.ts b/src/modules/matcher/domain/types/time-schedule.type.ts new file mode 100644 index 0000000..4bd6ea2 --- /dev/null +++ b/src/modules/matcher/domain/types/time-schedule.type.ts @@ -0,0 +1,9 @@ +export type TimeSchedule = { + mon?: Date; + tue?: Date; + wed?: Date; + thu?: Date; + fri?: Date; + sat?: Date; + sun?: Date; +}; diff --git a/src/modules/matcher/queries/match.query.ts b/src/modules/matcher/queries/match.query.ts index 7de0009..b8c09b5 100644 --- a/src/modules/matcher/queries/match.query.ts +++ b/src/modules/matcher/queries/match.query.ts @@ -1,6 +1,6 @@ import { MatchRequest } from '../domain/dtos/match.request'; import { Geography } from '../domain/entities/ecosystem/geography'; -import { Person } from '../domain/entities/ecosystem/person'; +import { Ad } from '../domain/entities/ecosystem/ad'; import { Requirement } from '../domain/entities/ecosystem/requirement'; import { Role } from '../domain/types/role.enum'; import { AlgorithmSettings } from '../domain/entities/ecosystem/algorithm-settings'; @@ -9,35 +9,42 @@ import { IDefaultParams } from '../domain/types/default-params.type'; import { IGeorouter } from '../domain/interfaces/georouter.interface'; import { ICreateGeorouter } from '../domain/interfaces/georouter-creator.interface'; import { IFindTimezone } from '../../geography/domain/interfaces/timezone-finder.interface'; +import { Mode } from '../domain/types/mode.enum'; +import { IConvertTime } from '../domain/interfaces/time-converter.interface'; export class MatchQuery { private readonly matchRequest: MatchRequest; private readonly defaultParams: IDefaultParams; private readonly georouterCreator: ICreateGeorouter; - person: Person; + mode: Mode; + ad: Ad; roles: Role[]; time: Time; geography: Geography; - exclusions: number[]; + exclusions: string[]; requirement: Requirement; algorithmSettings: AlgorithmSettings; georouter: IGeorouter; timezoneFinder: IFindTimezone; + timeConverter: IConvertTime; constructor( matchRequest: MatchRequest, defaultParams: IDefaultParams, georouterCreator: ICreateGeorouter, timezoneFinder: IFindTimezone, + timeConverter: IConvertTime, ) { this.matchRequest = matchRequest; this.defaultParams = defaultParams; this.georouterCreator = georouterCreator; this.timezoneFinder = timezoneFinder; - this.setPerson(); + this.timeConverter = timeConverter; + this.setMode(); + this.setAd(); this.setRoles(); - this.setTime(); this.setGeography(); + this.setTime(); this.setRequirement(); this.setAlgorithmSettings(); this.setExclusions(); @@ -47,13 +54,17 @@ export class MatchQuery { this.geography.createRoutes(this.roles, this.algorithmSettings.georouter); }; - private setPerson = (): void => { - this.person = new Person( + private setMode = (): void => { + this.mode = this.matchRequest.mode ?? Mode.MATCH; + }; + + private setAd = (): void => { + this.ad = new Ad( this.matchRequest, - this.defaultParams.DEFAULT_IDENTIFIER, + this.defaultParams.DEFAULT_UUID, this.defaultParams.MARGIN_DURATION, ); - this.person.init(); + this.ad.init(); }; private setRoles = (): void => { @@ -63,15 +74,6 @@ export class MatchQuery { if (this.roles.length == 0) this.roles.push(Role.PASSENGER); }; - private setTime = (): void => { - this.time = new Time( - this.matchRequest, - this.defaultParams.MARGIN_DURATION, - this.defaultParams.VALIDITY_DURATION, - ); - this.time.init(); - }; - private setGeography = (): void => { this.geography = new Geography( this.matchRequest, @@ -79,9 +81,20 @@ export class MatchQuery { timezone: this.defaultParams.DEFAULT_TIMEZONE, finder: this.timezoneFinder, }, - this.person, + this.ad, ); this.geography.init(); + if (this.geography.timezones.length > 0) + this.matchRequest.timezone = this.geography.timezones[0]; + }; + + private setTime = (): void => { + this.time = new Time( + this.matchRequest, + this.defaultParams.MARGIN_DURATION, + this.defaultParams.VALIDITY_DURATION, + ); + this.time.init(); }; private setRequirement = (): void => { @@ -102,8 +115,7 @@ export class MatchQuery { private setExclusions = (): void => { this.exclusions = []; - if (this.matchRequest.identifier) - this.exclusions.push(this.matchRequest.identifier); + if (this.matchRequest.uuid) this.exclusions.push(this.matchRequest.uuid); if (this.matchRequest.exclusions) this.exclusions.push(...this.matchRequest.exclusions); }; diff --git a/src/modules/matcher/tests/unit/adapters/secondaries/default-params.provider.spec.ts b/src/modules/matcher/tests/unit/adapters/secondaries/default-params.provider.spec.ts index 5221c14..a23a4d0 100644 --- a/src/modules/matcher/tests/unit/adapters/secondaries/default-params.provider.spec.ts +++ b/src/modules/matcher/tests/unit/adapters/secondaries/default-params.provider.spec.ts @@ -33,6 +33,6 @@ describe('DefaultParamsProvider', () => { it('should provide default params', async () => { const params: IDefaultParams = defaultParamsProvider.getParams(); - expect(params.DEFAULT_IDENTIFIER).toBe(99); + expect(params.DEFAULT_UUID).toBe(99); }); }); diff --git a/src/modules/matcher/tests/unit/domain/ecosystem/geography.spec.ts b/src/modules/matcher/tests/unit/domain/ecosystem/geography.spec.ts index 9b870e8..1ca35d5 100644 --- a/src/modules/matcher/tests/unit/domain/ecosystem/geography.spec.ts +++ b/src/modules/matcher/tests/unit/domain/ecosystem/geography.spec.ts @@ -1,4 +1,4 @@ -import { Person } from '../../../../domain/entities/ecosystem/person'; +import { Ad } from '../../../../domain/entities/ecosystem/ad'; import { Geography, RouteKey, @@ -9,11 +9,11 @@ import { Route } from '../../../../domain/entities/ecosystem/route'; import { IGeodesic } from '../../../../../geography/domain/interfaces/geodesic.interface'; import { PointType } from '../../../../../geography/domain/types/point-type.enum'; -const person: Person = new Person( +const ad: Ad = new Ad( { - identifier: 1, + uuid: '774aaab2-77df-4c6c-b70d-7b9e972e5bbc', }, - 0, + '00000000-0000-0000-0000-000000000000', 900, ); @@ -88,7 +88,7 @@ describe('Geography entity', () => { timezone: 'Europe/Paris', finder: mockTimezoneFinder, }, - person, + ad, ); expect(geography).toBeDefined(); }); @@ -114,7 +114,7 @@ describe('Geography entity', () => { timezone: 'Europe/Paris', finder: mockTimezoneFinder, }, - person, + ad, ); geography.init(); expect(geography.originType).toBe(PointType.LOCALITY); @@ -129,7 +129,7 @@ describe('Geography entity', () => { timezone: 'Europe/Paris', finder: mockTimezoneFinder, }, - person, + ad, ); expect(() => geography.init()).toThrow(); }); @@ -147,7 +147,7 @@ describe('Geography entity', () => { timezone: 'Europe/Paris', finder: mockTimezoneFinder, }, - person, + ad, ); expect(() => geography.init()).toThrow(); }); @@ -169,7 +169,7 @@ describe('Geography entity', () => { timezone: 'Europe/Paris', finder: mockTimezoneFinder, }, - person, + ad, ); expect(() => geography.init()).toThrow(); }); @@ -191,7 +191,7 @@ describe('Geography entity', () => { timezone: 'Europe/Paris', finder: mockTimezoneFinder, }, - person, + ad, ); expect(() => geography.init()).toThrow(); }); @@ -216,7 +216,7 @@ describe('Geography entity', () => { timezone: 'Europe/Paris', finder: mockTimezoneFinder, }, - person, + ad, ); geography.init(); await geography.createRoutes( @@ -249,7 +249,7 @@ describe('Geography entity', () => { timezone: 'Europe/Paris', finder: mockTimezoneFinder, }, - person, + ad, ); geography.init(); await geography.createRoutes( @@ -278,7 +278,7 @@ describe('Geography entity', () => { timezone: 'Europe/Paris', finder: mockTimezoneFinder, }, - person, + ad, ); geography.init(); await geography.createRoutes([Role.DRIVER], mockGeorouter); @@ -304,7 +304,7 @@ describe('Geography entity', () => { timezone: 'Europe/Paris', finder: mockTimezoneFinder, }, - person, + ad, ); geography.init(); await geography.createRoutes([Role.PASSENGER], mockGeorouter); diff --git a/src/modules/matcher/tests/unit/domain/ecosystem/person.spec.ts b/src/modules/matcher/tests/unit/domain/ecosystem/person.spec.ts index c9d604c..974d93e 100644 --- a/src/modules/matcher/tests/unit/domain/ecosystem/person.spec.ts +++ b/src/modules/matcher/tests/unit/domain/ecosystem/person.spec.ts @@ -1,40 +1,40 @@ -import { Person } from '../../../../domain/entities/ecosystem/person'; +import { Ad } from '../../../../domain/entities/ecosystem/ad'; -const DEFAULT_IDENTIFIER = 0; +const DEFAULT_UUID = '00000000-0000-0000-0000-000000000000'; const MARGIN_DURATION = 900; -describe('Person entity', () => { +describe('Ad entity', () => { it('should be defined', () => { - const person = new Person( + const ad = new Ad( { - identifier: 1, + uuid: '774aaab2-77df-4c6c-b70d-7b9e972e5bbc', }, - DEFAULT_IDENTIFIER, + DEFAULT_UUID, MARGIN_DURATION, ); - expect(person).toBeDefined(); + expect(ad).toBeDefined(); }); describe('init', () => { - it('should initialize a person with an identifier', () => { - const person = new Person( + it('should initialize an ad with a uuid', () => { + const ad = new Ad( { - identifier: 1, + uuid: '774aaab2-77df-4c6c-b70d-7b9e972e5bbc', }, - DEFAULT_IDENTIFIER, + DEFAULT_UUID, MARGIN_DURATION, ); - person.init(); - expect(person.identifier).toBe(1); - expect(person.marginDurations[0]).toBe(900); - expect(person.marginDurations[6]).toBe(900); + ad.init(); + expect(ad.uuid).toBe('774aaab2-77df-4c6c-b70d-7b9e972e5bbc'); + expect(ad.marginDurations[0]).toBe(900); + expect(ad.marginDurations[6]).toBe(900); }); - it('should initialize a person without an identifier', () => { - const person = new Person({}, DEFAULT_IDENTIFIER, MARGIN_DURATION); - person.init(); - expect(person.identifier).toBe(0); - expect(person.marginDurations[0]).toBe(900); - expect(person.marginDurations[6]).toBe(900); + it('should initialize an ad without a uuid', () => { + const ad = new Ad({}, DEFAULT_UUID, MARGIN_DURATION); + ad.init(); + expect(ad.uuid).toBe('00000000-0000-0000-0000-000000000000'); + expect(ad.marginDurations[0]).toBe(900); + expect(ad.marginDurations[6]).toBe(900); }); }); }); diff --git a/src/modules/matcher/tests/unit/domain/engine/algorithm-factory-creator.spec.ts b/src/modules/matcher/tests/unit/domain/engine/algorithm-factory-creator.spec.ts index 1a816ee..daa0dce 100644 --- a/src/modules/matcher/tests/unit/domain/engine/algorithm-factory-creator.spec.ts +++ b/src/modules/matcher/tests/unit/domain/engine/algorithm-factory-creator.spec.ts @@ -14,7 +14,7 @@ const mockTimezoneFinder = { }; const defaultParams: IDefaultParams = { - DEFAULT_IDENTIFIER: 0, + DEFAULT_UUID: '00000000-0000-0000-0000-000000000000', MARGIN_DURATION: 900, VALIDITY_DURATION: 365, DEFAULT_TIMEZONE: 'Europe/Paris', diff --git a/src/modules/matcher/tests/unit/domain/engine/algorithm-factory.abstract.spec.ts b/src/modules/matcher/tests/unit/domain/engine/algorithm-factory.abstract.spec.ts index f17f5a4..7b5d05f 100644 --- a/src/modules/matcher/tests/unit/domain/engine/algorithm-factory.abstract.spec.ts +++ b/src/modules/matcher/tests/unit/domain/engine/algorithm-factory.abstract.spec.ts @@ -16,7 +16,7 @@ const mockTimezoneFinder = { }; const defaultParams: IDefaultParams = { - DEFAULT_IDENTIFIER: 0, + DEFAULT_UUID: '00000000-0000-0000-0000-000000000000', MARGIN_DURATION: 900, VALIDITY_DURATION: 365, DEFAULT_TIMEZONE: 'Europe/Paris', diff --git a/src/modules/matcher/tests/unit/domain/engine/classic-algorithm-factory.spec.ts b/src/modules/matcher/tests/unit/domain/engine/classic-algorithm-factory.spec.ts index 690fee3..9d76d87 100644 --- a/src/modules/matcher/tests/unit/domain/engine/classic-algorithm-factory.spec.ts +++ b/src/modules/matcher/tests/unit/domain/engine/classic-algorithm-factory.spec.ts @@ -14,7 +14,7 @@ const mockTimezoneFinder = { }; const defaultParams: IDefaultParams = { - DEFAULT_IDENTIFIER: 0, + DEFAULT_UUID: '00000000-0000-0000-0000-000000000000', MARGIN_DURATION: 900, VALIDITY_DURATION: 365, DEFAULT_TIMEZONE: 'Europe/Paris', diff --git a/src/modules/matcher/tests/unit/domain/engine/classic-geo.filter.processor.spec.ts b/src/modules/matcher/tests/unit/domain/engine/classic-geo.filter.processor.spec.ts index fda1087..10ac6ad 100644 --- a/src/modules/matcher/tests/unit/domain/engine/classic-geo.filter.processor.spec.ts +++ b/src/modules/matcher/tests/unit/domain/engine/classic-geo.filter.processor.spec.ts @@ -14,7 +14,7 @@ const mockTimezoneFinder = { }; const defaultParams: IDefaultParams = { - DEFAULT_IDENTIFIER: 0, + DEFAULT_UUID: '00000000-0000-0000-0000-000000000000', MARGIN_DURATION: 900, VALIDITY_DURATION: 365, DEFAULT_TIMEZONE: 'Europe/Paris', diff --git a/src/modules/matcher/tests/unit/domain/engine/classic-time.filter.processor.spec.ts b/src/modules/matcher/tests/unit/domain/engine/classic-time.filter.processor.spec.ts index 6c703af..54791a5 100644 --- a/src/modules/matcher/tests/unit/domain/engine/classic-time.filter.processor.spec.ts +++ b/src/modules/matcher/tests/unit/domain/engine/classic-time.filter.processor.spec.ts @@ -14,7 +14,7 @@ const mockTimezoneFinder = { }; const defaultParams: IDefaultParams = { - DEFAULT_IDENTIFIER: 0, + DEFAULT_UUID: '00000000-0000-0000-0000-000000000000', MARGIN_DURATION: 900, VALIDITY_DURATION: 365, DEFAULT_TIMEZONE: 'Europe/Paris', diff --git a/src/modules/matcher/tests/unit/domain/engine/classic-waypoint.completer.processor.spec.ts b/src/modules/matcher/tests/unit/domain/engine/classic-waypoint.completer.processor.spec.ts index 9a52ce4..5b25396 100644 --- a/src/modules/matcher/tests/unit/domain/engine/classic-waypoint.completer.processor.spec.ts +++ b/src/modules/matcher/tests/unit/domain/engine/classic-waypoint.completer.processor.spec.ts @@ -14,7 +14,7 @@ const mockTimezoneFinder = { }; const defaultParams: IDefaultParams = { - DEFAULT_IDENTIFIER: 0, + DEFAULT_UUID: '00000000-0000-0000-0000-000000000000', MARGIN_DURATION: 900, VALIDITY_DURATION: 365, DEFAULT_TIMEZONE: 'Europe/Paris', diff --git a/src/modules/matcher/tests/unit/domain/engine/classic.selector.spec.ts b/src/modules/matcher/tests/unit/domain/engine/classic.selector.spec.ts index 77d616b..a15df9c 100644 --- a/src/modules/matcher/tests/unit/domain/engine/classic.selector.spec.ts +++ b/src/modules/matcher/tests/unit/domain/engine/classic.selector.spec.ts @@ -14,7 +14,7 @@ const mockTimezoneFinder = { }; const defaultParams: IDefaultParams = { - DEFAULT_IDENTIFIER: 0, + DEFAULT_UUID: '00000000-0000-0000-0000-000000000000', MARGIN_DURATION: 900, VALIDITY_DURATION: 365, DEFAULT_TIMEZONE: 'Europe/Paris', diff --git a/src/modules/matcher/tests/unit/domain/engine/completer.abstract.spec.ts b/src/modules/matcher/tests/unit/domain/engine/completer.abstract.spec.ts index 15fad37..913b309 100644 --- a/src/modules/matcher/tests/unit/domain/engine/completer.abstract.spec.ts +++ b/src/modules/matcher/tests/unit/domain/engine/completer.abstract.spec.ts @@ -14,7 +14,7 @@ const mockTimezoneFinder = { }; const defaultParams: IDefaultParams = { - DEFAULT_IDENTIFIER: 0, + DEFAULT_UUID: '00000000-0000-0000-0000-000000000000', MARGIN_DURATION: 900, VALIDITY_DURATION: 365, DEFAULT_TIMEZONE: 'Europe/Paris', diff --git a/src/modules/matcher/tests/unit/domain/engine/filter.abstract.spec.ts b/src/modules/matcher/tests/unit/domain/engine/filter.abstract.spec.ts index 6b96578..de67dc5 100644 --- a/src/modules/matcher/tests/unit/domain/engine/filter.abstract.spec.ts +++ b/src/modules/matcher/tests/unit/domain/engine/filter.abstract.spec.ts @@ -14,7 +14,7 @@ const mockTimezoneFinder = { }; const defaultParams: IDefaultParams = { - DEFAULT_IDENTIFIER: 0, + DEFAULT_UUID: '00000000-0000-0000-0000-000000000000', MARGIN_DURATION: 900, VALIDITY_DURATION: 365, DEFAULT_TIMEZONE: 'Europe/Paris', diff --git a/src/modules/matcher/tests/unit/domain/engine/journey.completer.processor.spec.ts b/src/modules/matcher/tests/unit/domain/engine/journey.completer.processor.spec.ts index eb79edf..f31b8e5 100644 --- a/src/modules/matcher/tests/unit/domain/engine/journey.completer.processor.spec.ts +++ b/src/modules/matcher/tests/unit/domain/engine/journey.completer.processor.spec.ts @@ -14,7 +14,7 @@ const mockTimezoneFinder = { }; const defaultParams: IDefaultParams = { - DEFAULT_IDENTIFIER: 0, + DEFAULT_UUID: '00000000-0000-0000-0000-000000000000', MARGIN_DURATION: 900, VALIDITY_DURATION: 365, DEFAULT_TIMEZONE: 'Europe/Paris', diff --git a/src/modules/matcher/tests/unit/domain/engine/matcher.spec.ts b/src/modules/matcher/tests/unit/domain/engine/matcher.spec.ts index 1240682..bb7446c 100644 --- a/src/modules/matcher/tests/unit/domain/engine/matcher.spec.ts +++ b/src/modules/matcher/tests/unit/domain/engine/matcher.spec.ts @@ -26,7 +26,7 @@ const mockTimezoneFinder = { }; const defaultParams: IDefaultParams = { - DEFAULT_IDENTIFIER: 0, + DEFAULT_UUID: '00000000-0000-0000-0000-000000000000', MARGIN_DURATION: 900, VALIDITY_DURATION: 365, DEFAULT_TIMEZONE: 'Europe/Paris', diff --git a/src/modules/matcher/tests/unit/domain/engine/processor.abstract.spec.ts b/src/modules/matcher/tests/unit/domain/engine/processor.abstract.spec.ts index 65f6a00..6665000 100644 --- a/src/modules/matcher/tests/unit/domain/engine/processor.abstract.spec.ts +++ b/src/modules/matcher/tests/unit/domain/engine/processor.abstract.spec.ts @@ -14,7 +14,7 @@ const mockTimezoneFinder = { }; const defaultParams: IDefaultParams = { - DEFAULT_IDENTIFIER: 0, + DEFAULT_UUID: '00000000-0000-0000-0000-000000000000', MARGIN_DURATION: 900, VALIDITY_DURATION: 365, DEFAULT_TIMEZONE: 'Europe/Paris', diff --git a/src/modules/matcher/tests/unit/domain/engine/route.completer.processor.spec.ts b/src/modules/matcher/tests/unit/domain/engine/route.completer.processor.spec.ts index 7076539..311c42d 100644 --- a/src/modules/matcher/tests/unit/domain/engine/route.completer.processor.spec.ts +++ b/src/modules/matcher/tests/unit/domain/engine/route.completer.processor.spec.ts @@ -14,7 +14,7 @@ const mockTimezoneFinder = { }; const defaultParams: IDefaultParams = { - DEFAULT_IDENTIFIER: 0, + DEFAULT_UUID: '00000000-0000-0000-0000-000000000000', MARGIN_DURATION: 900, VALIDITY_DURATION: 365, DEFAULT_TIMEZONE: 'Europe/Paris', diff --git a/src/modules/matcher/tests/unit/domain/engine/selector.abstract.spec.ts b/src/modules/matcher/tests/unit/domain/engine/selector.abstract.spec.ts index d8830cb..85302dc 100644 --- a/src/modules/matcher/tests/unit/domain/engine/selector.abstract.spec.ts +++ b/src/modules/matcher/tests/unit/domain/engine/selector.abstract.spec.ts @@ -14,7 +14,7 @@ const mockTimezoneFinder = { }; const defaultParams: IDefaultParams = { - DEFAULT_IDENTIFIER: 0, + DEFAULT_UUID: '00000000-0000-0000-0000-000000000000', MARGIN_DURATION: 900, VALIDITY_DURATION: 365, DEFAULT_TIMEZONE: 'Europe/Paris', diff --git a/src/modules/matcher/tests/unit/domain/match.usecase.spec.ts b/src/modules/matcher/tests/unit/domain/match.usecase.spec.ts index 1ca097b..d80dd1f 100644 --- a/src/modules/matcher/tests/unit/domain/match.usecase.spec.ts +++ b/src/modules/matcher/tests/unit/domain/match.usecase.spec.ts @@ -39,7 +39,7 @@ const mockTimezoneFinder = { }; const defaultParams: IDefaultParams = { - DEFAULT_IDENTIFIER: 0, + DEFAULT_UUID: '00000000-0000-0000-0000-000000000000', MARGIN_DURATION: 900, VALIDITY_DURATION: 365, DEFAULT_TIMEZONE: 'Europe/Paris', diff --git a/src/modules/matcher/tests/unit/queries/match.query.spec.ts b/src/modules/matcher/tests/unit/queries/match.query.spec.ts index 7640929..be1bfb5 100644 --- a/src/modules/matcher/tests/unit/queries/match.query.spec.ts +++ b/src/modules/matcher/tests/unit/queries/match.query.spec.ts @@ -4,9 +4,10 @@ import { IDefaultParams } from '../../../domain/types/default-params.type'; import { MatchQuery } from '../../../queries/match.query'; import { AlgorithmType } from '../../../domain/types/algorithm.enum'; import { Frequency } from '../../../../ad/domain/types/frequency.enum'; +import { Mode } from '../../../domain/types/mode.enum'; const defaultParams: IDefaultParams = { - DEFAULT_IDENTIFIER: 0, + DEFAULT_UUID: '00000000-0000-0000-0000-000000000000', MARGIN_DURATION: 900, VALIDITY_DURATION: 365, DEFAULT_TIMEZONE: 'Europe/Paris', @@ -55,6 +56,30 @@ describe('Match query', () => { mockTimezoneFinder, ); expect(matchQuery).toBeDefined(); + expect(matchQuery.mode).toBe(Mode.MATCH); + }); + + it('should create a query with publish and match mode', () => { + const matchRequest: MatchRequest = new MatchRequest(); + matchRequest.departure = '2023-04-01 12:00'; + matchRequest.waypoints = [ + { + lat: 49.440041, + lon: 1.093912, + }, + { + lat: 50.630992, + lon: 3.045432, + }, + ]; + matchRequest.mode = Mode.PUBLISH_AND_MATCH; + const matchQuery: MatchQuery = new MatchQuery( + matchRequest, + defaultParams, + mockGeorouterCreator, + mockTimezoneFinder, + ); + expect(matchQuery.mode).toBe(Mode.PUBLISH_AND_MATCH); }); it('should create a query with excluded identifiers', () => { @@ -70,8 +95,12 @@ describe('Match query', () => { lon: 3.045432, }, ]; - matchRequest.identifier = 125; - matchRequest.exclusions = [126, 127, 128]; + matchRequest.uuid = '445aa6e4-99e4-4899-9456-3be8c3ada368'; + matchRequest.exclusions = [ + 'eacf5e53-e63c-4551-860c-73f95b8a8895', + 'a4098161-13a9-4e55-8999-de134fbf89c4', + 'b18f7ffa-20b9-4a1a-89bc-e238ea8289f3', + ]; const matchQuery: MatchQuery = new MatchQuery( matchRequest, defaultParams,