Merge branch 'refactor' into 'main'

refactor

See merge request v3/service/ad!4
This commit is contained in:
Sylvain Briat 2023-06-02 07:53:03 +00:00
commit 1b3bc5347b
31 changed files with 214 additions and 237 deletions

View File

@ -3,6 +3,5 @@ SERVICE_URL=0.0.0.0
SERVICE_PORT=5006 SERVICE_PORT=5006
SERVICE_CONFIGURATION_DOMAIN=AD SERVICE_CONFIGURATION_DOMAIN=AD
# PRISMA # PRISMA
DATABASE_URL="postgresql://mobicoop:mobicoop@localhost:5432/mobicoop-test?schema=ad" DATABASE_URL="postgresql://mobicoop:mobicoop@localhost:5432/mobicoop-test?schema=ad"

View File

@ -19,7 +19,7 @@ test:
- docker-compose -f docker-compose.ci.tools.yml -p ad-tools --env-file ci/.env.ci up -d - docker-compose -f docker-compose.ci.tools.yml -p ad-tools --env-file ci/.env.ci up -d
- sh ci/wait-up.sh - sh ci/wait-up.sh
- docker-compose -f docker-compose.ci.service.yml -p ad-service --env-file ci/.env.ci up -d - docker-compose -f docker-compose.ci.service.yml -p ad-service --env-file ci/.env.ci up -d
# - docker exec -t v3-ad-api sh -c "npm run test:integration:ci" - docker exec -t v3-ad-api sh -c "npm run test:integration:ci"
coverage: /All files[^|]*\|[^|]*\s+([\d\.]+)/ coverage: /All files[^|]*\|[^|]*\s+([\d\.]+)/
rules: rules:
- if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH || $CI_COMMIT_MESSAGE =~ /--check/ || $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH || $CI_COMMIT_MESSAGE =~ /--check/ || $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'

11
package-lock.json generated
View File

@ -26,7 +26,6 @@
"@prisma/client": "^4.13.0", "@prisma/client": "^4.13.0",
"class-transformer": "^0.5.1", "class-transformer": "^0.5.1",
"class-validator": "^0.14.0", "class-validator": "^0.14.0",
"dotenv-cli": "^7.2.1",
"ioredis": "^5.3.2", "ioredis": "^5.3.2",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"rxjs": "^7.2.0" "rxjs": "^7.2.0"
@ -41,6 +40,7 @@
"@types/supertest": "^2.0.11", "@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.0.0", "@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0", "@typescript-eslint/parser": "^5.0.0",
"dotenv-cli": "^7.2.1",
"eslint": "^8.0.1", "eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0", "eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0", "eslint-plugin-prettier": "^4.0.0",
@ -3842,6 +3842,7 @@
"version": "7.0.3", "version": "7.0.3",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
"integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==",
"dev": true,
"dependencies": { "dependencies": {
"path-key": "^3.1.0", "path-key": "^3.1.0",
"shebang-command": "^2.0.0", "shebang-command": "^2.0.0",
@ -4007,6 +4008,7 @@
"version": "7.2.1", "version": "7.2.1",
"resolved": "https://registry.npmjs.org/dotenv-cli/-/dotenv-cli-7.2.1.tgz", "resolved": "https://registry.npmjs.org/dotenv-cli/-/dotenv-cli-7.2.1.tgz",
"integrity": "sha512-ODHbGTskqRtXAzZapDPvgNuDVQApu4oKX8lZW7Y0+9hKA6le1ZJlyRS687oU9FXjOVEDU/VFV6zI125HzhM1UQ==", "integrity": "sha512-ODHbGTskqRtXAzZapDPvgNuDVQApu4oKX8lZW7Y0+9hKA6le1ZJlyRS687oU9FXjOVEDU/VFV6zI125HzhM1UQ==",
"dev": true,
"dependencies": { "dependencies": {
"cross-spawn": "^7.0.3", "cross-spawn": "^7.0.3",
"dotenv": "^16.0.0", "dotenv": "^16.0.0",
@ -5368,7 +5370,8 @@
"node_modules/isexe": { "node_modules/isexe": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==",
"dev": true
}, },
"node_modules/istanbul-lib-coverage": { "node_modules/istanbul-lib-coverage": {
"version": "3.2.0", "version": "3.2.0",
@ -6811,6 +6814,7 @@
"version": "3.1.1", "version": "3.1.1",
"resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz",
"integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==",
"dev": true,
"engines": { "engines": {
"node": ">=8" "node": ">=8"
} }
@ -7669,6 +7673,7 @@
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
"integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==",
"dev": true,
"dependencies": { "dependencies": {
"shebang-regex": "^3.0.0" "shebang-regex": "^3.0.0"
}, },
@ -7680,6 +7685,7 @@
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz",
"integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==",
"dev": true,
"engines": { "engines": {
"node": ">=8" "node": ">=8"
} }
@ -8636,6 +8642,7 @@
"version": "2.0.2", "version": "2.0.2",
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
"integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
"dev": true,
"dependencies": { "dependencies": {
"isexe": "^2.0.0" "isexe": "^2.0.0"
}, },

View File

@ -51,7 +51,6 @@
"@prisma/client": "^4.13.0", "@prisma/client": "^4.13.0",
"class-transformer": "^0.5.1", "class-transformer": "^0.5.1",
"class-validator": "^0.14.0", "class-validator": "^0.14.0",
"dotenv-cli": "^7.2.1",
"ioredis": "^5.3.2", "ioredis": "^5.3.2",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"rxjs": "^7.2.0" "rxjs": "^7.2.0"
@ -66,6 +65,7 @@
"@types/supertest": "^2.0.11", "@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.0.0", "@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0", "@typescript-eslint/parser": "^5.0.0",
"dotenv-cli": "^7.2.1",
"eslint": "^8.0.1", "eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0", "eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0", "eslint-plugin-prettier": "^4.0.0",

View File

@ -2,7 +2,8 @@
// learn more about it in the docs: https://pris.ly/d/prisma-schema // learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client { generator client {
provider = "prisma-client-js" provider = "prisma-client-js"
binaryTargets = ["linux-musl", "debian-openssl-3.0.x"]
} }
datasource db { datasource db {

View File

@ -21,16 +21,16 @@ import { DatabaseException } from '../../../database/exceptions/database.excepti
@Controller() @Controller()
export class AdController { export class AdController {
constructor( constructor(
private readonly _commandBus: CommandBus, private readonly commandBus: CommandBus,
private readonly queryBus: QueryBus, private readonly queryBus: QueryBus,
@InjectMapper() private readonly _mapper: Mapper, @InjectMapper() private readonly mapper: Mapper,
) {} ) {}
@GrpcMethod('AdsService', 'FindOneByUuid') @GrpcMethod('AdsService', 'FindOneByUuid')
async findOnebyUuid(data: FindAdByUuidRequest): Promise<AdPresenter> { async findOnebyUuid(data: FindAdByUuidRequest): Promise<AdPresenter> {
try { try {
const ad = await this.queryBus.execute(new FindAdByUuidQuery(data)); const ad = await this.queryBus.execute(new FindAdByUuidQuery(data));
return this._mapper.map(ad, Ad, AdPresenter); return this.mapper.map(ad, Ad, AdPresenter);
} catch (e) { } catch (e) {
throw new RpcException({ throw new RpcException({
code: e.code, code: e.code,
@ -42,8 +42,8 @@ export class AdController {
@GrpcMethod('AdsService', 'Create') @GrpcMethod('AdsService', 'Create')
async createAd(data: CreateAdRequest): Promise<AdPresenter> { async createAd(data: CreateAdRequest): Promise<AdPresenter> {
try { try {
const ad = await this._commandBus.execute(new CreateAdCommand(data)); const ad = await this.commandBus.execute(new CreateAdCommand(data));
return this._mapper.map(ad, Ad, AdPresenter); return this.mapper.map(ad, Ad, AdPresenter);
} catch (e) { } catch (e) {
if (e instanceof DatabaseException) { if (e instanceof DatabaseException) {
if (e.message.includes('Already exists')) { if (e.message.includes('Already exists')) {

View File

@ -6,13 +6,13 @@ import { IMessageBroker } from '../../domain/interfaces/message-broker';
@Injectable() @Injectable()
export class Messager extends IMessageBroker { export class Messager extends IMessageBroker {
constructor( constructor(
private readonly _amqpConnection: AmqpConnection, private readonly amqpConnection: AmqpConnection,
configService: ConfigService, configService: ConfigService,
) { ) {
super(configService.get<string>('RMQ_EXCHANGE')); super(configService.get<string>('RMQ_EXCHANGE'));
} }
publish(routingKey: string, message: string): void { publish(routingKey: string, message: string): void {
this._amqpConnection.publish(this.exchange, routingKey, message); this.amqpConnection.publish(this.exchange, routingKey, message);
} }
} }

View File

@ -8,7 +8,7 @@ import {
IsUUID, IsUUID,
} from 'class-validator'; } from 'class-validator';
export class AddressRequestDTO { export class AddressDTO {
@IsOptional() @IsOptional()
@IsUUID(4) @IsUUID(4)
@AutoMap() @AutoMap()

View File

@ -11,10 +11,10 @@ import {
} from 'class-validator'; } from 'class-validator';
import { Frequency } from '../types/frequency.enum'; import { Frequency } from '../types/frequency.enum';
import { Transform, Type } from 'class-transformer'; import { Transform, Type } from 'class-transformer';
import { mappingKeyToFrequency } from './validators/frequency.mapping'; import { intToFrequency } from './validators/frequency.mapping';
import { MarginDTO } from './create.margin.dto'; import { MarginDTO } from './margin.dto';
import { ScheduleDTO } from './create.schedule.dto'; import { ScheduleDTO } from './schedule.dto';
import { AddressRequestDTO } from './create.address.request'; import { AddressDTO } from './address.dto';
import { IsPunctualOrRecurrent } from './validators/decorators/is-punctual-or-recurrent.validator'; import { IsPunctualOrRecurrent } from './validators/decorators/is-punctual-or-recurrent.validator';
import { HasProperDriverSeats } from './validators/decorators/has-driver-seats.validator'; import { HasProperDriverSeats } from './validators/decorators/has-driver-seats.validator';
import { HasProperPassengerSeats } from './validators/decorators/has-passenger-seats.validator'; import { HasProperPassengerSeats } from './validators/decorators/has-passenger-seats.validator';
@ -40,7 +40,7 @@ export class CreateAdRequest {
@AutoMap() @AutoMap()
passenger?: boolean; passenger?: boolean;
@Transform(({ value }) => mappingKeyToFrequency(value), { @Transform(({ value }) => intToFrequency(value), {
toClassOnly: true, toClassOnly: true,
}) })
@IsEnum(Frequency) @IsEnum(Frequency)
@ -98,9 +98,9 @@ export class CreateAdRequest {
strict?: boolean; strict?: boolean;
@ArrayMinSize(2) @ArrayMinSize(2)
@Type(() => AddressRequestDTO) @Type(() => AddressDTO)
@HasProperPositionIndexes() @HasProperPositionIndexes()
@ValidateNested({ each: true }) @ValidateNested({ each: true })
@AutoMap() @AutoMap()
addresses: AddressRequestDTO[]; addresses: AddressDTO[];
} }

View File

@ -1,8 +1,8 @@
import { AddressRequestDTO } from '../create.address.request'; import { AddressDTO } from '../address.dto';
export function hasProperPositionIndexes(value: AddressRequestDTO[]) { export const hasProperPositionIndexes = (value: AddressDTO[]): boolean => {
if (value.every((address) => address.position === undefined)) return true; if (value.every((address) => address.position === undefined)) return true;
else if (value.every((address) => typeof address.position === 'number')) { if (value.every((address) => typeof address.position === 'number')) {
value.sort((a, b) => a.position - b.position); value.sort((a, b) => a.position - b.position);
for (let i = 1; i < value.length; i++) { for (let i = 1; i < value.length; i++) {
if (value[i - 1].position >= value[i].position) return false; if (value[i - 1].position >= value[i].position) return false;
@ -10,4 +10,4 @@ export function hasProperPositionIndexes(value: AddressRequestDTO[]) {
return true; return true;
} }
return false; return false;
} };

View File

@ -1,16 +1,16 @@
import { ValidateBy, ValidationOptions, buildMessage } from 'class-validator'; import { ValidateBy, ValidationOptions, buildMessage } from 'class-validator';
import { AddressRequestDTO } from '../../create.address.request'; import { AddressDTO } from '../../address.dto';
import { hasProperPositionIndexes } from '../address-position'; import { hasProperPositionIndexes } from '../address-position';
export function HasProperPositionIndexes( export const HasProperPositionIndexes = (
validationOptions?: ValidationOptions, validationOptions?: ValidationOptions,
): PropertyDecorator { ): PropertyDecorator =>
return ValidateBy( ValidateBy(
{ {
name: '', name: '',
constraints: [], constraints: [],
validator: { validator: {
validate: (value: AddressRequestDTO[]): boolean => validate: (value: AddressDTO[]): boolean =>
hasProperPositionIndexes(value), hasProperPositionIndexes(value),
defaultMessage: buildMessage( defaultMessage: buildMessage(
@ -22,4 +22,3 @@ export function HasProperPositionIndexes(
}, },
validationOptions, validationOptions,
); );
}

View File

@ -6,10 +6,10 @@ import {
} from 'class-validator'; } from 'class-validator';
import { hasProperDriverSeats } from '../has-driver-seats'; import { hasProperDriverSeats } from '../has-driver-seats';
export function HasProperDriverSeats( export const HasProperDriverSeats = (
validationOptions?: ValidationOptions, validationOptions?: ValidationOptions,
): PropertyDecorator { ): PropertyDecorator =>
return ValidateBy( ValidateBy(
{ {
name: '', name: '',
constraints: [], constraints: [],
@ -24,4 +24,3 @@ export function HasProperDriverSeats(
}, },
validationOptions, validationOptions,
); );
}

View File

@ -6,10 +6,10 @@ import {
} from 'class-validator'; } from 'class-validator';
import { hasProperPassengerSeats } from '../has-passenger-seats'; import { hasProperPassengerSeats } from '../has-passenger-seats';
export function HasProperPassengerSeats( export const HasProperPassengerSeats = (
validationOptions?: ValidationOptions, validationOptions?: ValidationOptions,
): PropertyDecorator { ): PropertyDecorator =>
return ValidateBy( ValidateBy(
{ {
name: '', name: '',
constraints: [], constraints: [],
@ -24,4 +24,3 @@ export function HasProperPassengerSeats(
}, },
validationOptions, validationOptions,
); );
}

View File

@ -6,10 +6,10 @@ import {
} from 'class-validator'; } from 'class-validator';
import { isPunctualOrRecurrent } from '../is-punctual-or-recurrent'; import { isPunctualOrRecurrent } from '../is-punctual-or-recurrent';
export function IsPunctualOrRecurrent( export const IsPunctualOrRecurrent = (
validationOptions?: ValidationOptions, validationOptions?: ValidationOptions,
): PropertyDecorator { ): PropertyDecorator =>
return ValidateBy( ValidateBy(
{ {
name: '', name: '',
constraints: [], constraints: [],
@ -18,11 +18,10 @@ export function IsPunctualOrRecurrent(
isPunctualOrRecurrent(args), isPunctualOrRecurrent(args),
defaultMessage: buildMessage( defaultMessage: buildMessage(
() => () =>
`the departure, from date, to date and schedule must be properly set on reccurent or punctual ad `, `the departure, from date, to date and schedule must be properly set on reccurent or punctual ad`,
validationOptions, validationOptions,
), ),
}, },
}, },
validationOptions, validationOptions,
); );
}

View File

@ -1,5 +1,6 @@
import { Frequency } from '../../types/frequency.enum'; import { Frequency } from '../../types/frequency.enum';
export const mappingKeyToFrequency = (index: number): Frequency => {
export const intToFrequency = (index: number): Frequency => {
if (index == 1) return Frequency.PUNCTUAL; if (index == 1) return Frequency.PUNCTUAL;
if (index == 2) return Frequency.RECURRENT; if (index == 2) return Frequency.RECURRENT;
return undefined; return undefined;

View File

@ -1,6 +1,6 @@
import { ValidationArguments } from 'class-validator'; import { ValidationArguments } from 'class-validator';
export function hasProperDriverSeats(args: ValidationArguments) { export const hasProperDriverSeats = (args: ValidationArguments): boolean => {
if ( if (
args.object['driver'] === true && args.object['driver'] === true &&
typeof args.object['seatsDriver'] === 'number' typeof args.object['seatsDriver'] === 'number'
@ -16,4 +16,4 @@ export function hasProperDriverSeats(args: ValidationArguments) {
) )
return true; return true;
return false; return false;
} };

View File

@ -1,12 +1,12 @@
import { ValidationArguments } from 'class-validator'; import { ValidationArguments } from 'class-validator';
export function hasProperPassengerSeats(args: ValidationArguments) { export const hasProperPassengerSeats = (args: ValidationArguments): boolean => {
if ( if (
args.object['passenger'] === true && args.object['passenger'] === true &&
typeof args.object['seatsPassenger'] === 'number' typeof args.object['seatsPassenger'] === 'number'
) )
return args.object['seatsPassenger'] > 0; return args.object['seatsPassenger'] > 0;
else if ( if (
(args.object['passenger'] === false || (args.object['passenger'] === false ||
args.object['passenger'] === null || args.object['passenger'] === null ||
args.object['passenger'] === undefined) && args.object['passenger'] === undefined) &&
@ -15,5 +15,5 @@ export function hasProperPassengerSeats(args: ValidationArguments) {
args.object['seatsPassenger'] === undefined) args.object['seatsPassenger'] === undefined)
) )
return true; return true;
else return false; return false;
} };

View File

@ -1,27 +1,16 @@
import { ValidationArguments } from 'class-validator'; import { ValidationArguments } from 'class-validator';
import { Frequency } from '../../types/frequency.enum'; import { Frequency } from '../../types/frequency.enum';
function isPunctual(args: ValidationArguments): boolean { const isPunctual = (args: ValidationArguments): boolean =>
if ( args.object['frequency'] === Frequency.PUNCTUAL &&
args.object['frequency'] === Frequency.PUNCTUAL && args.object['departure'] instanceof Date &&
args.object['departure'] instanceof Date && !Object.keys(args.object['schedule']).length;
!Object.keys(args.object['schedule']).length
)
return true;
return false;
}
function isRecurrent(args: ValidationArguments): boolean { const isRecurrent = (args: ValidationArguments): boolean =>
if ( args.object['frequency'] === Frequency.RECURRENT &&
args.object['frequency'] === Frequency.RECURRENT && args.object['fromDate'] instanceof Date &&
args.object['fromDate'] instanceof Date && args.object['toDate'] instanceof Date &&
args.object['toDate'] instanceof Date && Object.keys(args.object['schedule']).length > 0;
Object.keys(args.object['schedule']).length
)
return true;
return false;
}
export const isPunctualOrRecurrent = (args: ValidationArguments): boolean => { export const isPunctualOrRecurrent = (args: ValidationArguments): boolean =>
return isPunctual(args) || isRecurrent(args); isPunctual(args) || isRecurrent(args);
};

View File

@ -12,6 +12,7 @@ import {
} from 'class-validator'; } from 'class-validator';
import { Address } from '../entities/address'; import { Address } from '../entities/address';
import { Frequency } from '../types/frequency.enum'; import { Frequency } from '../types/frequency.enum';
export class Ad { export class Ad {
@IsUUID(4) @IsUUID(4)
@AutoMap() @AutoMap()

View File

@ -0,0 +1,35 @@
import { CreateAdRequest } from '../dtos/create-ad.request';
import { Day } from '../types/day.enum';
import { Frequency } from '../types/frequency.enum';
export class FrequencyNormaliser {
fromDateResolver(createAdRequest: CreateAdRequest): Date {
if (createAdRequest.frequency === Frequency.PUNCTUAL)
return createAdRequest.departure;
return createAdRequest.fromDate;
}
toDateResolver(createAdRequest: CreateAdRequest): Date {
if (createAdRequest.frequency === Frequency.PUNCTUAL)
return createAdRequest.departure;
return createAdRequest.toDate;
}
scheduleResolver = (
createAdRequest: CreateAdRequest,
day: number,
): string => {
if (
Object.keys(createAdRequest.schedule).length === 0 &&
createAdRequest.frequency == Frequency.PUNCTUAL &&
createAdRequest.departure.getDay() === day
)
return `${createAdRequest.departure
.getHours()
.toString()
.padStart(2, '0')}:${createAdRequest.departure
.getMinutes()
.toString()
.padStart(2, '0')}`;
return createAdRequest.schedule[Day[day]];
};
}

View File

@ -1,95 +0,0 @@
import { CreateAdRequest } from '../dtos/create-ad.request';
import { Frequency } from '../types/frequency.enum';
export class RecurrentNormaliser {
fromDateResolver(createAdRequest: CreateAdRequest): Date {
if (createAdRequest.frequency === Frequency.PUNCTUAL)
return createAdRequest.departure;
return createAdRequest.fromDate;
}
toDateResolver(createAdRequest: CreateAdRequest): Date {
if (createAdRequest.frequency === Frequency.PUNCTUAL)
return createAdRequest.departure;
return createAdRequest.toDate;
}
scheduleSunResolver(createAdRequest: CreateAdRequest): string {
if (
Object.keys(createAdRequest.schedule).length === 0 &&
createAdRequest.frequency == Frequency.PUNCTUAL &&
createAdRequest.departure.getDay() === 0
)
return `${('0' + createAdRequest.departure.getHours()).slice(-2)}:${(
'0' + createAdRequest.departure.getMinutes()
).slice(-2)}`;
return createAdRequest.schedule.sun;
}
scheduleMonResolver(createAdRequest: CreateAdRequest): string {
if (
Object.keys(createAdRequest.schedule).length === 0 &&
createAdRequest.frequency == Frequency.PUNCTUAL &&
createAdRequest.departure.getDay() === 1
) {
return `${('0' + createAdRequest.departure.getHours()).slice(-2)}:${(
'0' + createAdRequest.departure.getMinutes()
).slice(-2)}`;
}
return createAdRequest.schedule.mon;
}
scheduleTueResolver(createAdRequest: CreateAdRequest): string {
if (
Object.keys(createAdRequest.schedule).length === 0 &&
createAdRequest.frequency == Frequency.PUNCTUAL &&
createAdRequest.departure.getDay() === 2
)
return `${('0' + createAdRequest.departure.getHours()).slice(-2)}:${(
'0' + createAdRequest.departure.getMinutes()
).slice(-2)}`;
return createAdRequest.schedule.tue;
}
scheduleWedResolver(createAdRequest: CreateAdRequest): string {
if (
Object.keys(createAdRequest.schedule).length === 0 &&
createAdRequest.frequency == Frequency.PUNCTUAL &&
createAdRequest.departure.getDay() === 3
)
return `${('0' + createAdRequest.departure.getHours()).slice(-2)}:${(
'0' + createAdRequest.departure.getMinutes()
).slice(-2)}`;
return createAdRequest.schedule.wed;
}
scheduleThuResolver(createAdRequest: CreateAdRequest): string {
if (
Object.keys(createAdRequest.schedule).length === 0 &&
createAdRequest.frequency == Frequency.PUNCTUAL &&
createAdRequest.departure.getDay() === 4
)
return `${('0' + createAdRequest.departure.getHours()).slice(-2)}:${(
'0' + createAdRequest.departure.getMinutes()
).slice(-2)}`;
return createAdRequest.schedule.thu;
}
scheduleFriResolver(createAdRequest: CreateAdRequest): string {
if (
Object.keys(createAdRequest.schedule).length === 0 &&
createAdRequest.frequency == Frequency.PUNCTUAL &&
createAdRequest.departure.getDay() === 5
)
return `${('0' + createAdRequest.departure.getHours()).slice(-2)}:${(
'0' + createAdRequest.departure.getMinutes()
).slice(-2)}`;
return createAdRequest.schedule.fri;
}
scheduleSatResolver(createAdRequest: CreateAdRequest): string {
if (
Object.keys(createAdRequest.schedule).length === 0 &&
createAdRequest.frequency == Frequency.PUNCTUAL &&
createAdRequest.departure.getDay() === 6
)
return `${('0' + createAdRequest.departure.getHours()).slice(-2)}:${(
'0' + createAdRequest.departure.getMinutes()
).slice(-2)}`;
return createAdRequest.schedule.sat;
}
}

View File

@ -0,0 +1,9 @@
export enum Day {
sun = 0,
mon,
tue,
wed,
thu,
fri,
sat,
}

View File

@ -6,7 +6,6 @@ import { Messager } from '../../adapters/secondaries/messager';
import { AdsRepository } from '../../adapters/secondaries/ads.repository'; import { AdsRepository } from '../../adapters/secondaries/ads.repository';
import { CreateAdCommand } from '../../commands/create-ad.command'; import { CreateAdCommand } from '../../commands/create-ad.command';
import { CreateAdRequest } from '../dtos/create-ad.request'; import { CreateAdRequest } from '../dtos/create-ad.request';
import { IProvideParams } from '../interfaces/param-provider.interface'; import { IProvideParams } from '../interfaces/param-provider.interface';
import { DefaultParams } from '../types/default-params.type'; import { DefaultParams } from '../types/default-params.type';
import { AdCreation } from '../dtos/ad.creation'; import { AdCreation } from '../dtos/ad.creation';
@ -17,9 +16,9 @@ export class CreateAdUseCase {
private readonly defaultParams: DefaultParams; private readonly defaultParams: DefaultParams;
private ad: AdCreation; private ad: AdCreation;
constructor( constructor(
private readonly _repository: AdsRepository, private readonly repository: AdsRepository,
private readonly _messager: Messager, private readonly messager: Messager,
@InjectMapper() private readonly _mapper: Mapper, @InjectMapper() private readonly mapper: Mapper,
@Inject('ParamsProvider') @Inject('ParamsProvider')
private readonly defaultParamsProvider: IProvideParams, private readonly defaultParamsProvider: IProvideParams,
) { ) {
@ -27,7 +26,7 @@ export class CreateAdUseCase {
} }
async execute(command: CreateAdCommand): Promise<Ad> { async execute(command: CreateAdCommand): Promise<Ad> {
this.ad = this._mapper.map( this.ad = this.mapper.map(
command.createAdRequest, command.createAdRequest,
CreateAdRequest, CreateAdRequest,
AdCreation, AdCreation,
@ -35,12 +34,12 @@ export class CreateAdUseCase {
this.setDefaultSchedule(); this.setDefaultSchedule();
this.setDefaultAddressesPosition(); this.setDefaultAddressesPosition();
this.setDefaultDriverAndPassengerParameters(); this.setDefaultDriverAndPassengerParameters();
this.setDefaultDistanceMargin(); this.setDefaultStrict();
try { try {
const adCreated: Ad = await this._repository.create(this.ad); const adCreated: Ad = await this.repository.create(this.ad);
this._messager.publish('ad.create', JSON.stringify(adCreated)); this.messager.publish('ad.create', JSON.stringify(adCreated));
this._messager.publish( this.messager.publish(
'logging.ad.create.info', 'logging.ad.create.info',
JSON.stringify(adCreated), JSON.stringify(adCreated),
); );
@ -50,7 +49,7 @@ export class CreateAdUseCase {
if (error.message.includes('Already exists')) { if (error.message.includes('Already exists')) {
key = 'logging.ad.create.warning'; key = 'logging.ad.create.warning';
} }
this._messager.publish( this.messager.publish(
key, key,
JSON.stringify({ JSON.stringify({
command, command,
@ -60,7 +59,8 @@ export class CreateAdUseCase {
throw error; throw error;
} }
} }
setDefaultSchedule(): void {
private setDefaultSchedule = (): void => {
if (this.ad.monMargin === undefined) if (this.ad.monMargin === undefined)
this.ad.monMargin = this.defaultParams.MON_MARGIN; this.ad.monMargin = this.defaultParams.MON_MARGIN;
if (this.ad.tueMargin === undefined) if (this.ad.tueMargin === undefined)
@ -75,12 +75,14 @@ export class CreateAdUseCase {
this.ad.satMargin = this.defaultParams.SAT_MARGIN; this.ad.satMargin = this.defaultParams.SAT_MARGIN;
if (this.ad.sunMargin === undefined) if (this.ad.sunMargin === undefined)
this.ad.sunMargin = this.defaultParams.SUN_MARGIN; this.ad.sunMargin = this.defaultParams.SUN_MARGIN;
} };
setDefaultDistanceMargin(): void {
private setDefaultStrict = (): void => {
if (this.ad.strict === undefined) if (this.ad.strict === undefined)
this.ad.strict = this.defaultParams.STRICT; this.ad.strict = this.defaultParams.STRICT;
} };
setDefaultDriverAndPassengerParameters(): void {
private setDefaultDriverAndPassengerParameters = (): void => {
if (!this.ad.driver && !this.ad.passenger) { if (!this.ad.driver && !this.ad.passenger) {
this.ad.driver = this.defaultParams.DRIVER; this.ad.driver = this.defaultParams.DRIVER;
this.ad.seatsDriver = this.defaultParams.SEATS_PROVIDED; this.ad.seatsDriver = this.defaultParams.SEATS_PROVIDED;
@ -96,12 +98,13 @@ export class CreateAdUseCase {
this.ad.seatsPassenger = 0; this.ad.seatsPassenger = 0;
} }
} }
} };
setDefaultAddressesPosition(): void {
private setDefaultAddressesPosition = (): void => {
if (this.ad.addresses.create[0].position === undefined) { if (this.ad.addresses.create[0].position === undefined) {
for (let i = 0; i < this.ad.addresses.create.length; i++) { for (let i = 0; i < this.ad.addresses.create.length; i++) {
this.ad.addresses.create[i].position = i; this.ad.addresses.create[i].position = i;
} }
} }
} };
} }

View File

@ -5,11 +5,12 @@ import { Ad } from '../domain/entities/ad';
import { AdPresenter } from '../adapters/primaries/ad.presenter'; import { AdPresenter } from '../adapters/primaries/ad.presenter';
import { CreateAdRequest } from '../domain/dtos/create-ad.request'; import { CreateAdRequest } from '../domain/dtos/create-ad.request';
import { AdCreation } from '../domain/dtos/ad.creation'; import { AdCreation } from '../domain/dtos/ad.creation';
import { RecurrentNormaliser } from '../domain/entities/recurrent-normaliser'; import { FrequencyNormaliser } from '../domain/entities/frequency.normaliser';
import { Day } from '../domain/types/day.enum';
@Injectable() @Injectable()
export class AdProfile extends AutomapperProfile { export class AdProfile extends AutomapperProfile {
recurrentNormaliser = new RecurrentNormaliser(); frequencyNormaliser = new FrequencyNormaliser();
constructor(@InjectMapper() mapper: Mapper) { constructor(@InjectMapper() mapper: Mapper) {
super(mapper); super(mapper);
} }
@ -84,53 +85,53 @@ export class AdProfile extends AutomapperProfile {
forMember( forMember(
(destination) => destination.fromDate, (destination) => destination.fromDate,
mapFrom((source) => mapFrom((source) =>
this.recurrentNormaliser.fromDateResolver(source), this.frequencyNormaliser.fromDateResolver(source),
), ),
), ),
forMember( forMember(
(destination) => destination.toDate, (destination) => destination.toDate,
mapFrom((source) => this.recurrentNormaliser.toDateResolver(source)), mapFrom((source) => this.frequencyNormaliser.toDateResolver(source)),
), ),
forMember( forMember(
(destination) => destination.monTime, (destination) => destination.monTime,
mapFrom((source) => mapFrom((source) =>
this.recurrentNormaliser.scheduleMonResolver(source), this.frequencyNormaliser.scheduleResolver(source, Day.mon),
), ),
), ),
forMember( forMember(
(destination) => destination.tueTime, (destination) => destination.tueTime,
mapFrom((source) => mapFrom((source) =>
this.recurrentNormaliser.scheduleTueResolver(source), this.frequencyNormaliser.scheduleResolver(source, Day.tue),
), ),
), ),
forMember( forMember(
(destination) => destination.wedTime, (destination) => destination.wedTime,
mapFrom((source) => mapFrom((source) =>
this.recurrentNormaliser.scheduleWedResolver(source), this.frequencyNormaliser.scheduleResolver(source, Day.wed),
), ),
), ),
forMember( forMember(
(destination) => destination.thuTime, (destination) => destination.thuTime,
mapFrom((source) => mapFrom((source) =>
this.recurrentNormaliser.scheduleThuResolver(source), this.frequencyNormaliser.scheduleResolver(source, Day.thu),
), ),
), ),
forMember( forMember(
(destination) => destination.friTime, (destination) => destination.friTime,
mapFrom((source) => mapFrom((source) =>
this.recurrentNormaliser.scheduleFriResolver(source), this.frequencyNormaliser.scheduleResolver(source, Day.fri),
), ),
), ),
forMember( forMember(
(destination) => destination.satTime, (destination) => destination.satTime,
mapFrom((source) => mapFrom((source) =>
this.recurrentNormaliser.scheduleSatResolver(source), this.frequencyNormaliser.scheduleResolver(source, Day.sat),
), ),
), ),
forMember( forMember(
(destination) => destination.sunTime, (destination) => destination.sunTime,
mapFrom((source) => mapFrom((source) =>
this.recurrentNormaliser.scheduleSunResolver(source), this.frequencyNormaliser.scheduleResolver(source, Day.sun),
), ),
), ),
); );

View File

@ -1,7 +1,7 @@
import { Mapper, createMap } from '@automapper/core'; import { Mapper, createMap } from '@automapper/core';
import { AutomapperProfile, InjectMapper } from '@automapper/nestjs'; import { AutomapperProfile, InjectMapper } from '@automapper/nestjs';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { AddressRequestDTO } from '../domain/dtos/create.address.request'; import { AddressDTO } from '../domain/dtos/address.dto';
import { Address } from '../domain/entities/address'; import { Address } from '../domain/entities/address';
@Injectable() @Injectable()
@ -12,7 +12,7 @@ export class AdProfile extends AutomapperProfile {
override get profile() { override get profile() {
return (mapper) => { return (mapper) => {
createMap(mapper, AddressRequestDTO, Address); createMap(mapper, AddressDTO, Address);
}; };
} }
} }

View File

@ -9,11 +9,11 @@ import { classes } from '@automapper/classes';
import { Frequency } from '../../../domain/types/frequency.enum'; import { Frequency } from '../../../domain/types/frequency.enum';
import { Ad } from '../../../domain/entities/ad'; import { Ad } from '../../../domain/entities/ad';
import { AdProfile } from '../../../mappers/ad.profile'; import { AdProfile } from '../../../mappers/ad.profile';
import { AddressRequestDTO } from '../../../domain/dtos/create.address.request'; import { AddressDTO } from '../../../domain/dtos/address.dto';
import { AdCreation } from '../../../domain/dtos/ad.creation'; import { AdCreation } from '../../../domain/dtos/ad.creation';
import { Address } from 'src/modules/ad/domain/entities/address'; import { Address } from 'src/modules/ad/domain/entities/address';
const mockAddress1: AddressRequestDTO = { const mockAddress1: AddressDTO = {
position: 0, position: 0,
lon: 48.68944505415954, lon: 48.68944505415954,
lat: 6.176510296462267, lat: 6.176510296462267,
@ -23,7 +23,7 @@ const mockAddress1: AddressRequestDTO = {
postalCode: '54000', postalCode: '54000',
country: 'France', country: 'France',
}; };
const mockAddress2: AddressRequestDTO = { const mockAddress2: AddressDTO = {
position: 1, position: 1,
lon: 48.8566, lon: 48.8566,
lat: 2.3522, lat: 2.3522,
@ -31,14 +31,14 @@ const mockAddress2: AddressRequestDTO = {
postalCode: '75000', postalCode: '75000',
country: 'France', country: 'France',
}; };
const mockAddressWithoutPos1: AddressRequestDTO = { const mockAddressWithoutPos1: AddressDTO = {
lon: 43.2965, lon: 43.2965,
lat: 5.3698, lat: 5.3698,
locality: 'Marseille', locality: 'Marseille',
postalCode: '13000', postalCode: '13000',
country: 'France', country: 'France',
}; };
const mockAddressWithoutPos2: AddressRequestDTO = { const mockAddressWithoutPos2: AddressDTO = {
lon: 43.7102, lon: 43.7102,
lat: 7.262, lat: 7.262,
locality: 'Nice', locality: 'Nice',

View File

@ -1,15 +1,15 @@
import { mappingKeyToFrequency } from '../../../domain/dtos/validators/frequency.mapping'; import { intToFrequency } from '../../../domain/dtos/validators/frequency.mapping';
import { Frequency } from '../../../domain/types/frequency.enum'; import { Frequency } from '../../../domain/types/frequency.enum';
describe('frequency mapping function ', () => { describe('frequency mapping function ', () => {
it('should return punctual', () => { it('should return punctual', () => {
expect(mappingKeyToFrequency(1)).toBe(Frequency.PUNCTUAL); expect(intToFrequency(1)).toBe(Frequency.PUNCTUAL);
}); });
it('should return recurent', () => { it('should return recurent', () => {
expect(mappingKeyToFrequency(2)).toBe(Frequency.RECURRENT); expect(intToFrequency(2)).toBe(Frequency.RECURRENT);
}); });
it('should return undefined', () => { it('should return undefined', () => {
expect(mappingKeyToFrequency(0)).toBeUndefined(); expect(intToFrequency(0)).toBeUndefined();
expect(mappingKeyToFrequency(3)).toBeUndefined(); expect(intToFrequency(3)).toBeUndefined();
}); });
}); });

View File

@ -1,7 +1,7 @@
import { AddressRequestDTO } from '../../../domain/dtos/create.address.request'; import { AddressDTO } from '../../../domain/dtos/address.dto';
import { hasProperPositionIndexes } from '../../../domain/dtos/validators/address-position'; import { hasProperPositionIndexes } from '../../../domain/dtos/validators/address-position';
describe('addresses position validators', () => { describe('addresses position validators', () => {
const mockAddress1: AddressRequestDTO = { const mockAddress1: AddressDTO = {
lon: 48.68944505415954, lon: 48.68944505415954,
lat: 6.176510296462267, lat: 6.176510296462267,
houseNumber: '5', houseNumber: '5',
@ -10,7 +10,7 @@ describe('addresses position validators', () => {
postalCode: '54000', postalCode: '54000',
country: 'France', country: 'France',
}; };
const mockAddress2: AddressRequestDTO = { const mockAddress2: AddressDTO = {
lon: 48.8566, lon: 48.8566,
lat: 2.3522, lat: 2.3522,
locality: 'Paris', locality: 'Paris',
@ -18,7 +18,7 @@ describe('addresses position validators', () => {
country: 'France', country: 'France',
}; };
const mockAddress3: AddressRequestDTO = { const mockAddress3: AddressDTO = {
lon: 49.2628, lon: 49.2628,
lat: 4.0347, lat: 4.0347,
locality: 'Reims', locality: 'Reims',

View File

@ -1,9 +1,11 @@
import { Day } from '../../../domain/types/day.enum';
import { CreateAdRequest } from '../../../domain/dtos/create-ad.request'; import { CreateAdRequest } from '../../../domain/dtos/create-ad.request';
import { ScheduleDTO } from '../../../domain/dtos/create.schedule.dto'; import { ScheduleDTO } from '../../../domain/dtos/schedule.dto';
import { RecurrentNormaliser } from '../../../domain/entities/recurrent-normaliser'; import { FrequencyNormaliser } from '../../../domain/entities/frequency.normaliser';
import { Frequency } from '../../../domain/types/frequency.enum'; import { Frequency } from '../../../domain/types/frequency.enum';
describe('recurrent normalizer transformer for punctual ad ', () => { describe('recurrent normalizer transformer for punctual ad ', () => {
const recurrentNormaliser = new RecurrentNormaliser(); const recurrentNormaliser = new FrequencyNormaliser();
it('should transform punctual ad into recurrent ad ', () => { it('should transform punctual ad into recurrent ad ', () => {
const punctualAd: CreateAdRequest = { const punctualAd: CreateAdRequest = {
userUuid: '', userUuid: '',
@ -18,13 +20,27 @@ describe('recurrent normalizer transformer for punctual ad ', () => {
expect(recurrentNormaliser.toDateResolver(punctualAd)).toBe( expect(recurrentNormaliser.toDateResolver(punctualAd)).toBe(
punctualAd.departure, punctualAd.departure,
); );
expect(recurrentNormaliser.scheduleMonResolver(punctualAd)).toBeUndefined(); expect(
expect(recurrentNormaliser.scheduleTueResolver(punctualAd)).toBeUndefined(); recurrentNormaliser.scheduleResolver(punctualAd, Day.mon),
expect(recurrentNormaliser.scheduleWedResolver(punctualAd)).toBe('12:39'); ).toBeUndefined();
expect(recurrentNormaliser.scheduleThuResolver(punctualAd)).toBeUndefined(); expect(
expect(recurrentNormaliser.scheduleFriResolver(punctualAd)).toBeUndefined(); recurrentNormaliser.scheduleResolver(punctualAd, Day.tue),
expect(recurrentNormaliser.scheduleSatResolver(punctualAd)).toBeUndefined(); ).toBeUndefined();
expect(recurrentNormaliser.scheduleSunResolver(punctualAd)).toBeUndefined(); expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.wed)).toBe(
'12:39',
);
expect(
recurrentNormaliser.scheduleResolver(punctualAd, Day.thu),
).toBeUndefined();
expect(
recurrentNormaliser.scheduleResolver(punctualAd, Day.fri),
).toBeUndefined();
expect(
recurrentNormaliser.scheduleResolver(punctualAd, Day.sat),
).toBeUndefined();
expect(
recurrentNormaliser.scheduleResolver(punctualAd, Day.sun),
).toBeUndefined();
}); });
it('should leave recurrent ad as is', () => { it('should leave recurrent ad as is', () => {
const recurrentAd: CreateAdRequest = { const recurrentAd: CreateAdRequest = {
@ -44,25 +60,25 @@ describe('recurrent normalizer transformer for punctual ad ', () => {
expect(recurrentNormaliser.toDateResolver(recurrentAd)).toBe( expect(recurrentNormaliser.toDateResolver(recurrentAd)).toBe(
recurrentAd.departure, recurrentAd.departure,
); );
expect(recurrentNormaliser.scheduleMonResolver(recurrentAd)).toBe( expect(recurrentNormaliser.scheduleResolver(recurrentAd, Day.mon)).toBe(
recurrentAd.schedule.mon, recurrentAd.schedule.mon,
); );
expect(recurrentNormaliser.scheduleTueResolver(recurrentAd)).toBe( expect(recurrentNormaliser.scheduleResolver(recurrentAd, Day.tue)).toBe(
recurrentAd.schedule.tue, recurrentAd.schedule.tue,
); );
expect(recurrentNormaliser.scheduleWedResolver(recurrentAd)).toBe( expect(recurrentNormaliser.scheduleResolver(recurrentAd, Day.wed)).toBe(
recurrentAd.schedule.wed, recurrentAd.schedule.wed,
); );
expect(recurrentNormaliser.scheduleThuResolver(recurrentAd)).toBe( expect(recurrentNormaliser.scheduleResolver(recurrentAd, Day.thu)).toBe(
recurrentAd.schedule.thu, recurrentAd.schedule.thu,
); );
expect(recurrentNormaliser.scheduleFriResolver(recurrentAd)).toBe( expect(recurrentNormaliser.scheduleResolver(recurrentAd, Day.fri)).toBe(
recurrentAd.schedule.fri, recurrentAd.schedule.fri,
); );
expect(recurrentNormaliser.scheduleSatResolver(recurrentAd)).toBe( expect(recurrentNormaliser.scheduleResolver(recurrentAd, Day.sat)).toBe(
recurrentAd.schedule.sat, recurrentAd.schedule.sat,
); );
expect(recurrentNormaliser.scheduleSunResolver(recurrentAd)).toBe( expect(recurrentNormaliser.scheduleResolver(recurrentAd, Day.sun)).toBe(
recurrentAd.schedule.sun, recurrentAd.schedule.sun,
); );
}); });
@ -75,18 +91,32 @@ describe('recurrent normalizer transformer for punctual ad ', () => {
addresses: [], addresses: [],
}; };
punctualAd.departure = new Date('05-01-2023 '); punctualAd.departure = new Date('05-01-2023 ');
expect(recurrentNormaliser.scheduleMonResolver(punctualAd)).toBe('00:00'); expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.mon)).toBe(
'00:00',
);
punctualAd.departure = new Date('05-02-2023 06:32:45'); punctualAd.departure = new Date('05-02-2023 06:32:45');
expect(recurrentNormaliser.scheduleTueResolver(punctualAd)).toBe('06:32'); expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.tue)).toBe(
'06:32',
);
punctualAd.departure = new Date('05-03-2023 10:21'); punctualAd.departure = new Date('05-03-2023 10:21');
expect(recurrentNormaliser.scheduleWedResolver(punctualAd)).toBe('10:21'); expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.wed)).toBe(
'10:21',
);
punctualAd.departure = new Date('05-04-2023 11:06:00'); punctualAd.departure = new Date('05-04-2023 11:06:00');
expect(recurrentNormaliser.scheduleThuResolver(punctualAd)).toBe('11:06'); expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.thu)).toBe(
'11:06',
);
punctualAd.departure = new Date('05-05-2023 05:20'); punctualAd.departure = new Date('05-05-2023 05:20');
expect(recurrentNormaliser.scheduleFriResolver(punctualAd)).toBe('05:20'); expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.fri)).toBe(
'05:20',
);
punctualAd.departure = new Date('05-06-2023'); punctualAd.departure = new Date('05-06-2023');
expect(recurrentNormaliser.scheduleSatResolver(punctualAd)).toBe('00:00'); expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.sat)).toBe(
'00:00',
);
punctualAd.departure = new Date('05-07-2023'); punctualAd.departure = new Date('05-07-2023');
expect(recurrentNormaliser.scheduleSunResolver(punctualAd)).toBe('00:00'); expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.sun)).toBe(
'00:00',
);
}); });
}); });