add default timezone

This commit is contained in:
sbriat 2023-04-12 08:47:38 +02:00
parent b90db67ed0
commit c396da77fc
7 changed files with 96 additions and 65 deletions

View File

@ -4,6 +4,12 @@ SERVICE_PORT=5005
SERVICE_CONFIGURATION_DOMAIN=MATCHER
HEALTH_SERVICE_PORT=6005
# DEFAULT CONFIGURATION
DEFAULT_IDENTIFIER=0
MARGIN_DURATION=900
VALIDITY_DURATION=365
DEFAULT_TIMEZONE=Europe/Paris
# PRISMA
DATABASE_URL="postgresql://mobicoop:mobicoop@v3-db:5432/mobicoop?schema=matcher"

View File

@ -13,6 +13,7 @@ export class DefaultParamsProvider {
),
MARGIN_DURATION: parseInt(this.configService.get('MARGIN_DURATION')),
VALIDITY_DURATION: parseInt(this.configService.get('VALIDITY_DURATION')),
DEFAULT_TIMEZONE: this.configService.get('DEFAULT_TIMEZONE'),
};
}
}

View File

@ -11,20 +11,21 @@ export class Geography {
waypoints: Array<Waypoint>;
originType: PointType;
destinationType: PointType;
timeZones: Array<string>;
timezones: Array<string>;
driverRoute: Route;
passengerRoute: Route;
constructor(geographyRequest: IRequestGeography) {
constructor(geographyRequest: IRequestGeography, defaultTimezone: string) {
this._geographyRequest = geographyRequest;
this.waypoints = [];
this.originType = PointType.OTHER;
this.destinationType = PointType.OTHER;
this.timezones = [defaultTimezone];
}
init() {
this._validateWaypoints();
this._setTimeZones();
this._setTimezones();
}
_validateWaypoints() {
@ -45,8 +46,8 @@ export class Geography {
});
}
_setTimeZones() {
this.timeZones = find(
_setTimezones() {
this.timezones = find(
this._geographyRequest.waypoints[0].lat,
this._geographyRequest.waypoints[0].lon,
);

View File

@ -2,4 +2,5 @@ export type IDefaultParams = {
DEFAULT_IDENTIFIER: number;
MARGIN_DURATION: number;
VALIDITY_DURATION: number;
DEFAULT_TIMEZONE: string;
};

View File

@ -60,7 +60,10 @@ export class MatchQuery {
}
_setGeography() {
this.geography = new Geography(this._matchRequest);
this.geography = new Geography(
this._matchRequest,
this._defaultParams.DEFAULT_TIMEZONE,
);
this.geography.init();
}

View File

@ -2,7 +2,8 @@ import { Geography } from '../../domain/entities/geography';
describe('Geography entity', () => {
it('should be defined', () => {
const geography = new Geography({
const geography = new Geography(
{
waypoints: [
{
lat: 49.440041,
@ -13,13 +14,16 @@ describe('Geography entity', () => {
lon: 3.045432,
},
],
});
},
'Europe/Paris',
);
expect(geography).toBeDefined();
});
describe('init', () => {
it('should initialize a geography request', () => {
const geography = new Geography({
const geography = new Geography(
{
waypoints: [
{
lat: 49.440041,
@ -30,29 +34,38 @@ describe('Geography entity', () => {
lon: 3.045432,
},
],
});
},
'Europe/Paris',
);
geography.init();
expect(geography.waypoints.length).toBe(2);
});
it('should throw an exception if waypoints are empty', () => {
const geography = new Geography({
const geography = new Geography(
{
waypoints: [],
});
},
'Europe/Paris',
);
expect(() => geography.init()).toThrow();
});
it('should throw an exception if only one waypoint is provided', () => {
const geography = new Geography({
const geography = new Geography(
{
waypoints: [
{
lat: 49.440041,
lon: 1.093912,
},
],
});
},
'Europe/Paris',
);
expect(() => geography.init()).toThrow();
});
it('should throw an exception if a waypoint has invalid longitude', () => {
const geography = new Geography({
const geography = new Geography(
{
waypoints: [
{
lat: 49.440041,
@ -63,11 +76,14 @@ describe('Geography entity', () => {
lon: 3.045432,
},
],
});
},
'Europe/Paris',
);
expect(() => geography.init()).toThrow();
});
it('should throw an exception if a waypoint has invalid latitude', () => {
const geography = new Geography({
const geography = new Geography(
{
waypoints: [
{
lat: 49.440041,
@ -78,7 +94,9 @@ describe('Geography entity', () => {
lon: 3.045432,
},
],
});
},
'Europe/Paris',
);
expect(() => geography.init()).toThrow();
});
});

View File

@ -18,6 +18,7 @@ const defaultParams: IDefaultParams = {
DEFAULT_IDENTIFIER: 0,
MARGIN_DURATION: 900,
VALIDITY_DURATION: 365,
DEFAULT_TIMEZONE: 'Europe/Paris',
};
describe('MatchUseCase', () => {