add time converter to match module

This commit is contained in:
sbriat 2023-05-03 10:57:27 +02:00
parent a6f7476599
commit 0d407216bc
20 changed files with 137 additions and 19 deletions

View File

@ -151,7 +151,14 @@ export class Time {
private setSchedule = (): void => { private setSchedule = (): void => {
Object.keys(this.timeRequest.schedule).map((day) => { Object.keys(this.timeRequest.schedule).map((day) => {
this.schedule[day] = this.timeRequest.schedule[day]; this.schedule[day] = this.timeConverter.toUtcDate(
new Date(
`${this.fromDate.getFullYear()}-${this.fromDate.getMonth()}-${this.fromDate.getDate()} ${
this.timeRequest.schedule[day]
}`,
),
this.timeRequest.timezone,
);
}); });
}; };

View File

@ -93,6 +93,7 @@ export class MatchQuery {
this.matchRequest, this.matchRequest,
this.defaultParams.MARGIN_DURATION, this.defaultParams.MARGIN_DURATION,
this.defaultParams.VALIDITY_DURATION, this.defaultParams.VALIDITY_DURATION,
this.timeConverter,
); );
this.time.init(); this.time.init();
}; };

View File

@ -66,7 +66,7 @@ const mockGeorouter = {
}; };
const mockTimezoneFinder = { const mockTimezoneFinder = {
timezones: jest.fn().mockImplementation(), timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
}; };
describe('Geography entity', () => { describe('Geography entity', () => {

View File

@ -2,6 +2,9 @@ import { Time } from '../../../../domain/entities/ecosystem/time';
const MARGIN_DURATION = 900; const MARGIN_DURATION = 900;
const VALIDITY_DURATION = 365; const VALIDITY_DURATION = 365;
const mockTimeConverter = {
toUtcDate: jest.fn(),
};
describe('Time entity', () => { describe('Time entity', () => {
it('should be defined', () => { it('should be defined', () => {
@ -11,6 +14,7 @@ describe('Time entity', () => {
}, },
MARGIN_DURATION, MARGIN_DURATION,
VALIDITY_DURATION, VALIDITY_DURATION,
mockTimeConverter,
); );
expect(time).toBeDefined(); expect(time).toBeDefined();
}); });
@ -23,6 +27,7 @@ describe('Time entity', () => {
}, },
MARGIN_DURATION, MARGIN_DURATION,
VALIDITY_DURATION, VALIDITY_DURATION,
mockTimeConverter,
); );
time.init(); time.init();
expect(time.fromDate.getFullYear()).toBe( expect(time.fromDate.getFullYear()).toBe(
@ -37,6 +42,7 @@ describe('Time entity', () => {
}, },
MARGIN_DURATION, MARGIN_DURATION,
VALIDITY_DURATION, VALIDITY_DURATION,
mockTimeConverter,
); );
time.init(); time.init();
expect(time.marginDurations['tue']).toBe(300); expect(time.marginDurations['tue']).toBe(300);
@ -51,6 +57,7 @@ describe('Time entity', () => {
}, },
MARGIN_DURATION, MARGIN_DURATION,
VALIDITY_DURATION, VALIDITY_DURATION,
mockTimeConverter,
); );
time.init(); time.init();
expect(time.marginDurations['tue']).toBe(900); expect(time.marginDurations['tue']).toBe(900);
@ -67,6 +74,7 @@ describe('Time entity', () => {
}, },
MARGIN_DURATION, MARGIN_DURATION,
VALIDITY_DURATION, VALIDITY_DURATION,
mockTimeConverter,
); );
time.init(); time.init();
expect(time.marginDurations['tue']).toBe(500); expect(time.marginDurations['tue']).toBe(500);
@ -82,6 +90,7 @@ describe('Time entity', () => {
}, },
MARGIN_DURATION, MARGIN_DURATION,
VALIDITY_DURATION, VALIDITY_DURATION,
mockTimeConverter,
); );
time.init(); time.init();
expect(time.fromDate.getFullYear()).toBe( expect(time.fromDate.getFullYear()).toBe(
@ -89,7 +98,12 @@ describe('Time entity', () => {
); );
}); });
it('should throw an exception if no date is provided', () => { it('should throw an exception if no date is provided', () => {
const time = new Time({}, MARGIN_DURATION, VALIDITY_DURATION); const time = new Time(
{},
MARGIN_DURATION,
VALIDITY_DURATION,
mockTimeConverter,
);
expect(() => time.init()).toThrow(); expect(() => time.init()).toThrow();
}); });
it('should throw an exception if punctual date is invalid', () => { it('should throw an exception if punctual date is invalid', () => {
@ -99,6 +113,7 @@ describe('Time entity', () => {
}, },
MARGIN_DURATION, MARGIN_DURATION,
VALIDITY_DURATION, VALIDITY_DURATION,
mockTimeConverter,
); );
expect(() => time.init()).toThrow(); expect(() => time.init()).toThrow();
}); });
@ -109,6 +124,7 @@ describe('Time entity', () => {
}, },
MARGIN_DURATION, MARGIN_DURATION,
VALIDITY_DURATION, VALIDITY_DURATION,
mockTimeConverter,
); );
expect(() => time.init()).toThrow(); expect(() => time.init()).toThrow();
}); });
@ -120,6 +136,7 @@ describe('Time entity', () => {
}, },
MARGIN_DURATION, MARGIN_DURATION,
VALIDITY_DURATION, VALIDITY_DURATION,
mockTimeConverter,
); );
expect(() => time.init()).toThrow(); expect(() => time.init()).toThrow();
}); });
@ -131,6 +148,7 @@ describe('Time entity', () => {
}, },
MARGIN_DURATION, MARGIN_DURATION,
VALIDITY_DURATION, VALIDITY_DURATION,
mockTimeConverter,
); );
expect(() => time.init()).toThrow(); expect(() => time.init()).toThrow();
}); });
@ -142,6 +160,7 @@ describe('Time entity', () => {
}, },
MARGIN_DURATION, MARGIN_DURATION,
VALIDITY_DURATION, VALIDITY_DURATION,
mockTimeConverter,
); );
expect(() => time.init()).toThrow(); expect(() => time.init()).toThrow();
}); });
@ -154,6 +173,7 @@ describe('Time entity', () => {
}, },
MARGIN_DURATION, MARGIN_DURATION,
VALIDITY_DURATION, VALIDITY_DURATION,
mockTimeConverter,
); );
expect(() => time.init()).toThrow(); expect(() => time.init()).toThrow();
}); });
@ -168,6 +188,7 @@ describe('Time entity', () => {
}, },
MARGIN_DURATION, MARGIN_DURATION,
VALIDITY_DURATION, VALIDITY_DURATION,
mockTimeConverter,
); );
expect(() => time.init()).toThrow(); expect(() => time.init()).toThrow();
}); });
@ -180,6 +201,7 @@ describe('Time entity', () => {
}, },
MARGIN_DURATION, MARGIN_DURATION,
VALIDITY_DURATION, VALIDITY_DURATION,
mockTimeConverter,
); );
expect(() => time.init()).toThrow(); expect(() => time.init()).toThrow();
}); });

View File

@ -10,7 +10,11 @@ const mockGeorouterCreator = {
}; };
const mockTimezoneFinder = { const mockTimezoneFinder = {
timezones: jest.fn().mockImplementation(), timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
};
const mockTimeConverter = {
toUtcDate: jest.fn(),
}; };
const defaultParams: IDefaultParams = { const defaultParams: IDefaultParams = {
@ -51,6 +55,7 @@ const matchQuery: MatchQuery = new MatchQuery(
defaultParams, defaultParams,
mockGeorouterCreator, mockGeorouterCreator,
mockTimezoneFinder, mockTimezoneFinder,
mockTimeConverter,
); );
describe('AlgorithmFactoryCreator', () => { describe('AlgorithmFactoryCreator', () => {

View File

@ -12,7 +12,11 @@ const mockGeorouterCreator = {
}; };
const mockTimezoneFinder = { const mockTimezoneFinder = {
timezones: jest.fn().mockImplementation(), timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
};
const mockTimeConverter = {
toUtcDate: jest.fn(),
}; };
const defaultParams: IDefaultParams = { const defaultParams: IDefaultParams = {
@ -53,6 +57,7 @@ const matchQuery: MatchQuery = new MatchQuery(
defaultParams, defaultParams,
mockGeorouterCreator, mockGeorouterCreator,
mockTimezoneFinder, mockTimezoneFinder,
mockTimeConverter,
); );
class FakeSelector extends Selector { class FakeSelector extends Selector {

View File

@ -10,7 +10,11 @@ const mockGeorouterCreator = {
}; };
const mockTimezoneFinder = { const mockTimezoneFinder = {
timezones: jest.fn().mockImplementation(), timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
};
const mockTimeConverter = {
toUtcDate: jest.fn(),
}; };
const defaultParams: IDefaultParams = { const defaultParams: IDefaultParams = {
@ -51,6 +55,7 @@ const matchQuery: MatchQuery = new MatchQuery(
defaultParams, defaultParams,
mockGeorouterCreator, mockGeorouterCreator,
mockTimezoneFinder, mockTimezoneFinder,
mockTimeConverter,
); );
describe('ClassicAlgorithmFactory', () => { describe('ClassicAlgorithmFactory', () => {

View File

@ -10,7 +10,11 @@ const mockGeorouterCreator = {
}; };
const mockTimezoneFinder = { const mockTimezoneFinder = {
timezones: jest.fn().mockImplementation(), timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
};
const mockTimeConverter = {
toUtcDate: jest.fn(),
}; };
const defaultParams: IDefaultParams = { const defaultParams: IDefaultParams = {
@ -51,6 +55,7 @@ const matchQuery: MatchQuery = new MatchQuery(
defaultParams, defaultParams,
mockGeorouterCreator, mockGeorouterCreator,
mockTimezoneFinder, mockTimezoneFinder,
mockTimeConverter,
); );
describe('ClassicGeoFilter', () => { describe('ClassicGeoFilter', () => {

View File

@ -10,7 +10,11 @@ const mockGeorouterCreator = {
}; };
const mockTimezoneFinder = { const mockTimezoneFinder = {
timezones: jest.fn().mockImplementation(), timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
};
const mockTimeConverter = {
toUtcDate: jest.fn(),
}; };
const defaultParams: IDefaultParams = { const defaultParams: IDefaultParams = {
@ -51,6 +55,7 @@ const matchQuery: MatchQuery = new MatchQuery(
defaultParams, defaultParams,
mockGeorouterCreator, mockGeorouterCreator,
mockTimezoneFinder, mockTimezoneFinder,
mockTimeConverter,
); );
describe('ClassicTimeFilter', () => { describe('ClassicTimeFilter', () => {

View File

@ -10,7 +10,11 @@ const mockGeorouterCreator = {
}; };
const mockTimezoneFinder = { const mockTimezoneFinder = {
timezones: jest.fn().mockImplementation(), timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
};
const mockTimeConverter = {
toUtcDate: jest.fn(),
}; };
const defaultParams: IDefaultParams = { const defaultParams: IDefaultParams = {
@ -51,6 +55,7 @@ const matchQuery: MatchQuery = new MatchQuery(
defaultParams, defaultParams,
mockGeorouterCreator, mockGeorouterCreator,
mockTimezoneFinder, mockTimezoneFinder,
mockTimeConverter,
); );
describe('ClassicWaypointCompleter', () => { describe('ClassicWaypointCompleter', () => {

View File

@ -10,7 +10,11 @@ const mockGeorouterCreator = {
}; };
const mockTimezoneFinder = { const mockTimezoneFinder = {
timezones: jest.fn().mockImplementation(), timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
};
const mockTimeConverter = {
toUtcDate: jest.fn(),
}; };
const defaultParams: IDefaultParams = { const defaultParams: IDefaultParams = {
@ -51,6 +55,7 @@ const matchQuery: MatchQuery = new MatchQuery(
defaultParams, defaultParams,
mockGeorouterCreator, mockGeorouterCreator,
mockTimezoneFinder, mockTimezoneFinder,
mockTimeConverter,
); );
describe('ClassicSelector', () => { describe('ClassicSelector', () => {

View File

@ -10,7 +10,11 @@ const mockGeorouterCreator = {
}; };
const mockTimezoneFinder = { const mockTimezoneFinder = {
timezones: jest.fn().mockImplementation(), timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
};
const mockTimeConverter = {
toUtcDate: jest.fn(),
}; };
const defaultParams: IDefaultParams = { const defaultParams: IDefaultParams = {
@ -51,6 +55,7 @@ const matchQuery: MatchQuery = new MatchQuery(
defaultParams, defaultParams,
mockGeorouterCreator, mockGeorouterCreator,
mockTimezoneFinder, mockTimezoneFinder,
mockTimeConverter,
); );
class FakeCompleter extends Completer { class FakeCompleter extends Completer {

View File

@ -10,7 +10,11 @@ const mockGeorouterCreator = {
}; };
const mockTimezoneFinder = { const mockTimezoneFinder = {
timezones: jest.fn().mockImplementation(), timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
};
const mockTimeConverter = {
toUtcDate: jest.fn(),
}; };
const defaultParams: IDefaultParams = { const defaultParams: IDefaultParams = {
@ -51,6 +55,7 @@ const matchQuery: MatchQuery = new MatchQuery(
defaultParams, defaultParams,
mockGeorouterCreator, mockGeorouterCreator,
mockTimezoneFinder, mockTimezoneFinder,
mockTimeConverter,
); );
class FakeFilter extends Filter { class FakeFilter extends Filter {

View File

@ -10,7 +10,11 @@ const mockGeorouterCreator = {
}; };
const mockTimezoneFinder = { const mockTimezoneFinder = {
timezones: jest.fn().mockImplementation(), timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
};
const mockTimeConverter = {
toUtcDate: jest.fn(),
}; };
const defaultParams: IDefaultParams = { const defaultParams: IDefaultParams = {
@ -51,6 +55,7 @@ const matchQuery: MatchQuery = new MatchQuery(
defaultParams, defaultParams,
mockGeorouterCreator, mockGeorouterCreator,
mockTimezoneFinder, mockTimezoneFinder,
mockTimeConverter,
); );
describe('JourneyCompleter', () => { describe('JourneyCompleter', () => {

View File

@ -22,7 +22,11 @@ const mockGeorouterCreator = {
}; };
const mockTimezoneFinder = { const mockTimezoneFinder = {
timezones: jest.fn().mockImplementation(), timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
};
const mockTimeConverter = {
toUtcDate: jest.fn(),
}; };
const defaultParams: IDefaultParams = { const defaultParams: IDefaultParams = {
@ -63,6 +67,7 @@ const matchQuery: MatchQuery = new MatchQuery(
defaultParams, defaultParams,
mockGeorouterCreator, mockGeorouterCreator,
mockTimezoneFinder, mockTimezoneFinder,
mockTimeConverter,
); );
describe('Matcher', () => { describe('Matcher', () => {

View File

@ -10,7 +10,11 @@ const mockGeorouterCreator = {
}; };
const mockTimezoneFinder = { const mockTimezoneFinder = {
timezones: jest.fn().mockImplementation(), timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
};
const mockTimeConverter = {
toUtcDate: jest.fn().mockImplementation(),
}; };
const defaultParams: IDefaultParams = { const defaultParams: IDefaultParams = {
@ -51,6 +55,7 @@ const matchQuery: MatchQuery = new MatchQuery(
defaultParams, defaultParams,
mockGeorouterCreator, mockGeorouterCreator,
mockTimezoneFinder, mockTimezoneFinder,
mockTimeConverter,
); );
class FakeProcessor extends Processor { class FakeProcessor extends Processor {

View File

@ -10,7 +10,11 @@ const mockGeorouterCreator = {
}; };
const mockTimezoneFinder = { const mockTimezoneFinder = {
timezones: jest.fn().mockImplementation(), timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
};
const mockTimeConverter = {
toUtcDate: jest.fn(),
}; };
const defaultParams: IDefaultParams = { const defaultParams: IDefaultParams = {
@ -51,6 +55,7 @@ const matchQuery: MatchQuery = new MatchQuery(
defaultParams, defaultParams,
mockGeorouterCreator, mockGeorouterCreator,
mockTimezoneFinder, mockTimezoneFinder,
mockTimeConverter,
); );
describe('RouteCompleter', () => { describe('RouteCompleter', () => {

View File

@ -10,7 +10,11 @@ const mockGeorouterCreator = {
}; };
const mockTimezoneFinder = { const mockTimezoneFinder = {
timezones: jest.fn().mockImplementation(), timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
};
const mockTimeConverter = {
toUtcDate: jest.fn(),
}; };
const defaultParams: IDefaultParams = { const defaultParams: IDefaultParams = {
@ -51,6 +55,7 @@ const matchQuery: MatchQuery = new MatchQuery(
defaultParams, defaultParams,
mockGeorouterCreator, mockGeorouterCreator,
mockTimezoneFinder, mockTimezoneFinder,
mockTimeConverter,
); );
class FakeSelector extends Selector { class FakeSelector extends Selector {

View File

@ -35,7 +35,11 @@ const mockGeorouterCreator = {
}; };
const mockTimezoneFinder = { const mockTimezoneFinder = {
timezones: jest.fn().mockImplementation(), timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
};
const mockTimeConverter = {
toUtcDate: jest.fn(),
}; };
const defaultParams: IDefaultParams = { const defaultParams: IDefaultParams = {
@ -106,6 +110,7 @@ describe('MatchUseCase', () => {
defaultParams, defaultParams,
mockGeorouterCreator, mockGeorouterCreator,
mockTimezoneFinder, mockTimezoneFinder,
mockTimeConverter,
), ),
); );
expect(matches.total).toBe(3); expect(matches.total).toBe(3);
@ -119,6 +124,7 @@ describe('MatchUseCase', () => {
defaultParams, defaultParams,
mockGeorouterCreator, mockGeorouterCreator,
mockTimezoneFinder, mockTimezoneFinder,
mockTimeConverter,
), ),
), ),
).rejects.toBeInstanceOf(MatcherException); ).rejects.toBeInstanceOf(MatcherException);

View File

@ -32,7 +32,11 @@ const mockGeorouterCreator = {
}; };
const mockTimezoneFinder = { const mockTimezoneFinder = {
timezones: jest.fn().mockImplementation(), timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
};
const mockTimeConverter = {
toUtcDate: jest.fn(),
}; };
describe('Match query', () => { describe('Match query', () => {
@ -54,6 +58,7 @@ describe('Match query', () => {
defaultParams, defaultParams,
mockGeorouterCreator, mockGeorouterCreator,
mockTimezoneFinder, mockTimezoneFinder,
mockTimeConverter,
); );
expect(matchQuery).toBeDefined(); expect(matchQuery).toBeDefined();
expect(matchQuery.mode).toBe(Mode.MATCH); expect(matchQuery.mode).toBe(Mode.MATCH);
@ -78,6 +83,7 @@ describe('Match query', () => {
defaultParams, defaultParams,
mockGeorouterCreator, mockGeorouterCreator,
mockTimezoneFinder, mockTimezoneFinder,
mockTimeConverter,
); );
expect(matchQuery.mode).toBe(Mode.PUBLISH_AND_MATCH); expect(matchQuery.mode).toBe(Mode.PUBLISH_AND_MATCH);
}); });
@ -106,6 +112,7 @@ describe('Match query', () => {
defaultParams, defaultParams,
mockGeorouterCreator, mockGeorouterCreator,
mockTimezoneFinder, mockTimezoneFinder,
mockTimeConverter,
); );
expect(matchQuery.exclusions.length).toBe(4); expect(matchQuery.exclusions.length).toBe(4);
}); });
@ -129,6 +136,7 @@ describe('Match query', () => {
defaultParams, defaultParams,
mockGeorouterCreator, mockGeorouterCreator,
mockTimezoneFinder, mockTimezoneFinder,
mockTimeConverter,
); );
expect(matchQuery.roles).toEqual([Role.DRIVER]); expect(matchQuery.roles).toEqual([Role.DRIVER]);
}); });
@ -152,6 +160,7 @@ describe('Match query', () => {
defaultParams, defaultParams,
mockGeorouterCreator, mockGeorouterCreator,
mockTimezoneFinder, mockTimezoneFinder,
mockTimeConverter,
); );
expect(matchQuery.roles).toEqual([Role.PASSENGER]); expect(matchQuery.roles).toEqual([Role.PASSENGER]);
}); });
@ -176,6 +185,7 @@ describe('Match query', () => {
defaultParams, defaultParams,
mockGeorouterCreator, mockGeorouterCreator,
mockTimezoneFinder, mockTimezoneFinder,
mockTimeConverter,
); );
expect(matchQuery.roles.length).toBe(2); expect(matchQuery.roles.length).toBe(2);
expect(matchQuery.roles).toContain(Role.PASSENGER); expect(matchQuery.roles).toContain(Role.PASSENGER);
@ -202,6 +212,7 @@ describe('Match query', () => {
defaultParams, defaultParams,
mockGeorouterCreator, mockGeorouterCreator,
mockTimezoneFinder, mockTimezoneFinder,
mockTimeConverter,
); );
expect(matchQuery.requirement.seatsDriver).toBe(1); expect(matchQuery.requirement.seatsDriver).toBe(1);
expect(matchQuery.requirement.seatsPassenger).toBe(2); expect(matchQuery.requirement.seatsPassenger).toBe(2);
@ -234,6 +245,7 @@ describe('Match query', () => {
defaultParams, defaultParams,
mockGeorouterCreator, mockGeorouterCreator,
mockTimezoneFinder, mockTimezoneFinder,
mockTimeConverter,
); );
expect(matchQuery.algorithmSettings.algorithmType).toBe( expect(matchQuery.algorithmSettings.algorithmType).toBe(
AlgorithmType.CLASSIC, AlgorithmType.CLASSIC,