add time converter to match module
This commit is contained in:
parent
a6f7476599
commit
0d407216bc
|
@ -151,7 +151,14 @@ export class Time {
|
|||
|
||||
private setSchedule = (): void => {
|
||||
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,
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -93,6 +93,7 @@ export class MatchQuery {
|
|||
this.matchRequest,
|
||||
this.defaultParams.MARGIN_DURATION,
|
||||
this.defaultParams.VALIDITY_DURATION,
|
||||
this.timeConverter,
|
||||
);
|
||||
this.time.init();
|
||||
};
|
||||
|
|
|
@ -66,7 +66,7 @@ const mockGeorouter = {
|
|||
};
|
||||
|
||||
const mockTimezoneFinder = {
|
||||
timezones: jest.fn().mockImplementation(),
|
||||
timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
|
||||
};
|
||||
|
||||
describe('Geography entity', () => {
|
||||
|
|
|
@ -2,6 +2,9 @@ import { Time } from '../../../../domain/entities/ecosystem/time';
|
|||
|
||||
const MARGIN_DURATION = 900;
|
||||
const VALIDITY_DURATION = 365;
|
||||
const mockTimeConverter = {
|
||||
toUtcDate: jest.fn(),
|
||||
};
|
||||
|
||||
describe('Time entity', () => {
|
||||
it('should be defined', () => {
|
||||
|
@ -11,6 +14,7 @@ describe('Time entity', () => {
|
|||
},
|
||||
MARGIN_DURATION,
|
||||
VALIDITY_DURATION,
|
||||
mockTimeConverter,
|
||||
);
|
||||
expect(time).toBeDefined();
|
||||
});
|
||||
|
@ -23,6 +27,7 @@ describe('Time entity', () => {
|
|||
},
|
||||
MARGIN_DURATION,
|
||||
VALIDITY_DURATION,
|
||||
mockTimeConverter,
|
||||
);
|
||||
time.init();
|
||||
expect(time.fromDate.getFullYear()).toBe(
|
||||
|
@ -37,6 +42,7 @@ describe('Time entity', () => {
|
|||
},
|
||||
MARGIN_DURATION,
|
||||
VALIDITY_DURATION,
|
||||
mockTimeConverter,
|
||||
);
|
||||
time.init();
|
||||
expect(time.marginDurations['tue']).toBe(300);
|
||||
|
@ -51,6 +57,7 @@ describe('Time entity', () => {
|
|||
},
|
||||
MARGIN_DURATION,
|
||||
VALIDITY_DURATION,
|
||||
mockTimeConverter,
|
||||
);
|
||||
time.init();
|
||||
expect(time.marginDurations['tue']).toBe(900);
|
||||
|
@ -67,6 +74,7 @@ describe('Time entity', () => {
|
|||
},
|
||||
MARGIN_DURATION,
|
||||
VALIDITY_DURATION,
|
||||
mockTimeConverter,
|
||||
);
|
||||
time.init();
|
||||
expect(time.marginDurations['tue']).toBe(500);
|
||||
|
@ -82,6 +90,7 @@ describe('Time entity', () => {
|
|||
},
|
||||
MARGIN_DURATION,
|
||||
VALIDITY_DURATION,
|
||||
mockTimeConverter,
|
||||
);
|
||||
time.init();
|
||||
expect(time.fromDate.getFullYear()).toBe(
|
||||
|
@ -89,7 +98,12 @@ describe('Time entity', () => {
|
|||
);
|
||||
});
|
||||
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();
|
||||
});
|
||||
it('should throw an exception if punctual date is invalid', () => {
|
||||
|
@ -99,6 +113,7 @@ describe('Time entity', () => {
|
|||
},
|
||||
MARGIN_DURATION,
|
||||
VALIDITY_DURATION,
|
||||
mockTimeConverter,
|
||||
);
|
||||
expect(() => time.init()).toThrow();
|
||||
});
|
||||
|
@ -109,6 +124,7 @@ describe('Time entity', () => {
|
|||
},
|
||||
MARGIN_DURATION,
|
||||
VALIDITY_DURATION,
|
||||
mockTimeConverter,
|
||||
);
|
||||
expect(() => time.init()).toThrow();
|
||||
});
|
||||
|
@ -120,6 +136,7 @@ describe('Time entity', () => {
|
|||
},
|
||||
MARGIN_DURATION,
|
||||
VALIDITY_DURATION,
|
||||
mockTimeConverter,
|
||||
);
|
||||
expect(() => time.init()).toThrow();
|
||||
});
|
||||
|
@ -131,6 +148,7 @@ describe('Time entity', () => {
|
|||
},
|
||||
MARGIN_DURATION,
|
||||
VALIDITY_DURATION,
|
||||
mockTimeConverter,
|
||||
);
|
||||
expect(() => time.init()).toThrow();
|
||||
});
|
||||
|
@ -142,6 +160,7 @@ describe('Time entity', () => {
|
|||
},
|
||||
MARGIN_DURATION,
|
||||
VALIDITY_DURATION,
|
||||
mockTimeConverter,
|
||||
);
|
||||
expect(() => time.init()).toThrow();
|
||||
});
|
||||
|
@ -154,6 +173,7 @@ describe('Time entity', () => {
|
|||
},
|
||||
MARGIN_DURATION,
|
||||
VALIDITY_DURATION,
|
||||
mockTimeConverter,
|
||||
);
|
||||
expect(() => time.init()).toThrow();
|
||||
});
|
||||
|
@ -168,6 +188,7 @@ describe('Time entity', () => {
|
|||
},
|
||||
MARGIN_DURATION,
|
||||
VALIDITY_DURATION,
|
||||
mockTimeConverter,
|
||||
);
|
||||
expect(() => time.init()).toThrow();
|
||||
});
|
||||
|
@ -180,6 +201,7 @@ describe('Time entity', () => {
|
|||
},
|
||||
MARGIN_DURATION,
|
||||
VALIDITY_DURATION,
|
||||
mockTimeConverter,
|
||||
);
|
||||
expect(() => time.init()).toThrow();
|
||||
});
|
||||
|
|
|
@ -10,7 +10,11 @@ const mockGeorouterCreator = {
|
|||
};
|
||||
|
||||
const mockTimezoneFinder = {
|
||||
timezones: jest.fn().mockImplementation(),
|
||||
timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
|
||||
};
|
||||
|
||||
const mockTimeConverter = {
|
||||
toUtcDate: jest.fn(),
|
||||
};
|
||||
|
||||
const defaultParams: IDefaultParams = {
|
||||
|
@ -51,6 +55,7 @@ const matchQuery: MatchQuery = new MatchQuery(
|
|||
defaultParams,
|
||||
mockGeorouterCreator,
|
||||
mockTimezoneFinder,
|
||||
mockTimeConverter,
|
||||
);
|
||||
|
||||
describe('AlgorithmFactoryCreator', () => {
|
||||
|
|
|
@ -12,7 +12,11 @@ const mockGeorouterCreator = {
|
|||
};
|
||||
|
||||
const mockTimezoneFinder = {
|
||||
timezones: jest.fn().mockImplementation(),
|
||||
timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
|
||||
};
|
||||
|
||||
const mockTimeConverter = {
|
||||
toUtcDate: jest.fn(),
|
||||
};
|
||||
|
||||
const defaultParams: IDefaultParams = {
|
||||
|
@ -53,6 +57,7 @@ const matchQuery: MatchQuery = new MatchQuery(
|
|||
defaultParams,
|
||||
mockGeorouterCreator,
|
||||
mockTimezoneFinder,
|
||||
mockTimeConverter,
|
||||
);
|
||||
|
||||
class FakeSelector extends Selector {
|
||||
|
|
|
@ -10,7 +10,11 @@ const mockGeorouterCreator = {
|
|||
};
|
||||
|
||||
const mockTimezoneFinder = {
|
||||
timezones: jest.fn().mockImplementation(),
|
||||
timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
|
||||
};
|
||||
|
||||
const mockTimeConverter = {
|
||||
toUtcDate: jest.fn(),
|
||||
};
|
||||
|
||||
const defaultParams: IDefaultParams = {
|
||||
|
@ -51,6 +55,7 @@ const matchQuery: MatchQuery = new MatchQuery(
|
|||
defaultParams,
|
||||
mockGeorouterCreator,
|
||||
mockTimezoneFinder,
|
||||
mockTimeConverter,
|
||||
);
|
||||
|
||||
describe('ClassicAlgorithmFactory', () => {
|
||||
|
|
|
@ -10,7 +10,11 @@ const mockGeorouterCreator = {
|
|||
};
|
||||
|
||||
const mockTimezoneFinder = {
|
||||
timezones: jest.fn().mockImplementation(),
|
||||
timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
|
||||
};
|
||||
|
||||
const mockTimeConverter = {
|
||||
toUtcDate: jest.fn(),
|
||||
};
|
||||
|
||||
const defaultParams: IDefaultParams = {
|
||||
|
@ -51,6 +55,7 @@ const matchQuery: MatchQuery = new MatchQuery(
|
|||
defaultParams,
|
||||
mockGeorouterCreator,
|
||||
mockTimezoneFinder,
|
||||
mockTimeConverter,
|
||||
);
|
||||
|
||||
describe('ClassicGeoFilter', () => {
|
||||
|
|
|
@ -10,7 +10,11 @@ const mockGeorouterCreator = {
|
|||
};
|
||||
|
||||
const mockTimezoneFinder = {
|
||||
timezones: jest.fn().mockImplementation(),
|
||||
timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
|
||||
};
|
||||
|
||||
const mockTimeConverter = {
|
||||
toUtcDate: jest.fn(),
|
||||
};
|
||||
|
||||
const defaultParams: IDefaultParams = {
|
||||
|
@ -51,6 +55,7 @@ const matchQuery: MatchQuery = new MatchQuery(
|
|||
defaultParams,
|
||||
mockGeorouterCreator,
|
||||
mockTimezoneFinder,
|
||||
mockTimeConverter,
|
||||
);
|
||||
|
||||
describe('ClassicTimeFilter', () => {
|
||||
|
|
|
@ -10,7 +10,11 @@ const mockGeorouterCreator = {
|
|||
};
|
||||
|
||||
const mockTimezoneFinder = {
|
||||
timezones: jest.fn().mockImplementation(),
|
||||
timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
|
||||
};
|
||||
|
||||
const mockTimeConverter = {
|
||||
toUtcDate: jest.fn(),
|
||||
};
|
||||
|
||||
const defaultParams: IDefaultParams = {
|
||||
|
@ -51,6 +55,7 @@ const matchQuery: MatchQuery = new MatchQuery(
|
|||
defaultParams,
|
||||
mockGeorouterCreator,
|
||||
mockTimezoneFinder,
|
||||
mockTimeConverter,
|
||||
);
|
||||
|
||||
describe('ClassicWaypointCompleter', () => {
|
||||
|
|
|
@ -10,7 +10,11 @@ const mockGeorouterCreator = {
|
|||
};
|
||||
|
||||
const mockTimezoneFinder = {
|
||||
timezones: jest.fn().mockImplementation(),
|
||||
timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
|
||||
};
|
||||
|
||||
const mockTimeConverter = {
|
||||
toUtcDate: jest.fn(),
|
||||
};
|
||||
|
||||
const defaultParams: IDefaultParams = {
|
||||
|
@ -51,6 +55,7 @@ const matchQuery: MatchQuery = new MatchQuery(
|
|||
defaultParams,
|
||||
mockGeorouterCreator,
|
||||
mockTimezoneFinder,
|
||||
mockTimeConverter,
|
||||
);
|
||||
|
||||
describe('ClassicSelector', () => {
|
||||
|
|
|
@ -10,7 +10,11 @@ const mockGeorouterCreator = {
|
|||
};
|
||||
|
||||
const mockTimezoneFinder = {
|
||||
timezones: jest.fn().mockImplementation(),
|
||||
timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
|
||||
};
|
||||
|
||||
const mockTimeConverter = {
|
||||
toUtcDate: jest.fn(),
|
||||
};
|
||||
|
||||
const defaultParams: IDefaultParams = {
|
||||
|
@ -51,6 +55,7 @@ const matchQuery: MatchQuery = new MatchQuery(
|
|||
defaultParams,
|
||||
mockGeorouterCreator,
|
||||
mockTimezoneFinder,
|
||||
mockTimeConverter,
|
||||
);
|
||||
|
||||
class FakeCompleter extends Completer {
|
||||
|
|
|
@ -10,7 +10,11 @@ const mockGeorouterCreator = {
|
|||
};
|
||||
|
||||
const mockTimezoneFinder = {
|
||||
timezones: jest.fn().mockImplementation(),
|
||||
timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
|
||||
};
|
||||
|
||||
const mockTimeConverter = {
|
||||
toUtcDate: jest.fn(),
|
||||
};
|
||||
|
||||
const defaultParams: IDefaultParams = {
|
||||
|
@ -51,6 +55,7 @@ const matchQuery: MatchQuery = new MatchQuery(
|
|||
defaultParams,
|
||||
mockGeorouterCreator,
|
||||
mockTimezoneFinder,
|
||||
mockTimeConverter,
|
||||
);
|
||||
|
||||
class FakeFilter extends Filter {
|
||||
|
|
|
@ -10,7 +10,11 @@ const mockGeorouterCreator = {
|
|||
};
|
||||
|
||||
const mockTimezoneFinder = {
|
||||
timezones: jest.fn().mockImplementation(),
|
||||
timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
|
||||
};
|
||||
|
||||
const mockTimeConverter = {
|
||||
toUtcDate: jest.fn(),
|
||||
};
|
||||
|
||||
const defaultParams: IDefaultParams = {
|
||||
|
@ -51,6 +55,7 @@ const matchQuery: MatchQuery = new MatchQuery(
|
|||
defaultParams,
|
||||
mockGeorouterCreator,
|
||||
mockTimezoneFinder,
|
||||
mockTimeConverter,
|
||||
);
|
||||
|
||||
describe('JourneyCompleter', () => {
|
||||
|
|
|
@ -22,7 +22,11 @@ const mockGeorouterCreator = {
|
|||
};
|
||||
|
||||
const mockTimezoneFinder = {
|
||||
timezones: jest.fn().mockImplementation(),
|
||||
timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
|
||||
};
|
||||
|
||||
const mockTimeConverter = {
|
||||
toUtcDate: jest.fn(),
|
||||
};
|
||||
|
||||
const defaultParams: IDefaultParams = {
|
||||
|
@ -63,6 +67,7 @@ const matchQuery: MatchQuery = new MatchQuery(
|
|||
defaultParams,
|
||||
mockGeorouterCreator,
|
||||
mockTimezoneFinder,
|
||||
mockTimeConverter,
|
||||
);
|
||||
|
||||
describe('Matcher', () => {
|
||||
|
|
|
@ -10,7 +10,11 @@ const mockGeorouterCreator = {
|
|||
};
|
||||
|
||||
const mockTimezoneFinder = {
|
||||
timezones: jest.fn().mockImplementation(),
|
||||
timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
|
||||
};
|
||||
|
||||
const mockTimeConverter = {
|
||||
toUtcDate: jest.fn().mockImplementation(),
|
||||
};
|
||||
|
||||
const defaultParams: IDefaultParams = {
|
||||
|
@ -51,6 +55,7 @@ const matchQuery: MatchQuery = new MatchQuery(
|
|||
defaultParams,
|
||||
mockGeorouterCreator,
|
||||
mockTimezoneFinder,
|
||||
mockTimeConverter,
|
||||
);
|
||||
|
||||
class FakeProcessor extends Processor {
|
||||
|
|
|
@ -10,7 +10,11 @@ const mockGeorouterCreator = {
|
|||
};
|
||||
|
||||
const mockTimezoneFinder = {
|
||||
timezones: jest.fn().mockImplementation(),
|
||||
timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
|
||||
};
|
||||
|
||||
const mockTimeConverter = {
|
||||
toUtcDate: jest.fn(),
|
||||
};
|
||||
|
||||
const defaultParams: IDefaultParams = {
|
||||
|
@ -51,6 +55,7 @@ const matchQuery: MatchQuery = new MatchQuery(
|
|||
defaultParams,
|
||||
mockGeorouterCreator,
|
||||
mockTimezoneFinder,
|
||||
mockTimeConverter,
|
||||
);
|
||||
|
||||
describe('RouteCompleter', () => {
|
||||
|
|
|
@ -10,7 +10,11 @@ const mockGeorouterCreator = {
|
|||
};
|
||||
|
||||
const mockTimezoneFinder = {
|
||||
timezones: jest.fn().mockImplementation(),
|
||||
timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
|
||||
};
|
||||
|
||||
const mockTimeConverter = {
|
||||
toUtcDate: jest.fn(),
|
||||
};
|
||||
|
||||
const defaultParams: IDefaultParams = {
|
||||
|
@ -51,6 +55,7 @@ const matchQuery: MatchQuery = new MatchQuery(
|
|||
defaultParams,
|
||||
mockGeorouterCreator,
|
||||
mockTimezoneFinder,
|
||||
mockTimeConverter,
|
||||
);
|
||||
|
||||
class FakeSelector extends Selector {
|
||||
|
|
|
@ -35,7 +35,11 @@ const mockGeorouterCreator = {
|
|||
};
|
||||
|
||||
const mockTimezoneFinder = {
|
||||
timezones: jest.fn().mockImplementation(),
|
||||
timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
|
||||
};
|
||||
|
||||
const mockTimeConverter = {
|
||||
toUtcDate: jest.fn(),
|
||||
};
|
||||
|
||||
const defaultParams: IDefaultParams = {
|
||||
|
@ -106,6 +110,7 @@ describe('MatchUseCase', () => {
|
|||
defaultParams,
|
||||
mockGeorouterCreator,
|
||||
mockTimezoneFinder,
|
||||
mockTimeConverter,
|
||||
),
|
||||
);
|
||||
expect(matches.total).toBe(3);
|
||||
|
@ -119,6 +124,7 @@ describe('MatchUseCase', () => {
|
|||
defaultParams,
|
||||
mockGeorouterCreator,
|
||||
mockTimezoneFinder,
|
||||
mockTimeConverter,
|
||||
),
|
||||
),
|
||||
).rejects.toBeInstanceOf(MatcherException);
|
||||
|
|
|
@ -32,7 +32,11 @@ const mockGeorouterCreator = {
|
|||
};
|
||||
|
||||
const mockTimezoneFinder = {
|
||||
timezones: jest.fn().mockImplementation(),
|
||||
timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
|
||||
};
|
||||
|
||||
const mockTimeConverter = {
|
||||
toUtcDate: jest.fn(),
|
||||
};
|
||||
|
||||
describe('Match query', () => {
|
||||
|
@ -54,6 +58,7 @@ describe('Match query', () => {
|
|||
defaultParams,
|
||||
mockGeorouterCreator,
|
||||
mockTimezoneFinder,
|
||||
mockTimeConverter,
|
||||
);
|
||||
expect(matchQuery).toBeDefined();
|
||||
expect(matchQuery.mode).toBe(Mode.MATCH);
|
||||
|
@ -78,6 +83,7 @@ describe('Match query', () => {
|
|||
defaultParams,
|
||||
mockGeorouterCreator,
|
||||
mockTimezoneFinder,
|
||||
mockTimeConverter,
|
||||
);
|
||||
expect(matchQuery.mode).toBe(Mode.PUBLISH_AND_MATCH);
|
||||
});
|
||||
|
@ -106,6 +112,7 @@ describe('Match query', () => {
|
|||
defaultParams,
|
||||
mockGeorouterCreator,
|
||||
mockTimezoneFinder,
|
||||
mockTimeConverter,
|
||||
);
|
||||
expect(matchQuery.exclusions.length).toBe(4);
|
||||
});
|
||||
|
@ -129,6 +136,7 @@ describe('Match query', () => {
|
|||
defaultParams,
|
||||
mockGeorouterCreator,
|
||||
mockTimezoneFinder,
|
||||
mockTimeConverter,
|
||||
);
|
||||
expect(matchQuery.roles).toEqual([Role.DRIVER]);
|
||||
});
|
||||
|
@ -152,6 +160,7 @@ describe('Match query', () => {
|
|||
defaultParams,
|
||||
mockGeorouterCreator,
|
||||
mockTimezoneFinder,
|
||||
mockTimeConverter,
|
||||
);
|
||||
expect(matchQuery.roles).toEqual([Role.PASSENGER]);
|
||||
});
|
||||
|
@ -176,6 +185,7 @@ describe('Match query', () => {
|
|||
defaultParams,
|
||||
mockGeorouterCreator,
|
||||
mockTimezoneFinder,
|
||||
mockTimeConverter,
|
||||
);
|
||||
expect(matchQuery.roles.length).toBe(2);
|
||||
expect(matchQuery.roles).toContain(Role.PASSENGER);
|
||||
|
@ -202,6 +212,7 @@ describe('Match query', () => {
|
|||
defaultParams,
|
||||
mockGeorouterCreator,
|
||||
mockTimezoneFinder,
|
||||
mockTimeConverter,
|
||||
);
|
||||
expect(matchQuery.requirement.seatsDriver).toBe(1);
|
||||
expect(matchQuery.requirement.seatsPassenger).toBe(2);
|
||||
|
@ -234,6 +245,7 @@ describe('Match query', () => {
|
|||
defaultParams,
|
||||
mockGeorouterCreator,
|
||||
mockTimezoneFinder,
|
||||
mockTimeConverter,
|
||||
);
|
||||
expect(matchQuery.algorithmSettings.algorithmType).toBe(
|
||||
AlgorithmType.CLASSIC,
|
||||
|
|
Loading…
Reference in New Issue