WIP create adresses
This commit is contained in:
		
							parent
							
								
									393105d525
								
							
						
					
					
						commit
						cac8e90c9b
					
				| 
						 | 
				
			
			@ -25,7 +25,6 @@ export class AdController {
 | 
			
		|||
  @GrpcMethod('AdsService', 'FindOneByUuid')
 | 
			
		||||
  async findOnebyUuid(data: FindAdByUuidRequest): Promise<AdPresenter> {
 | 
			
		||||
    try {
 | 
			
		||||
      console.log('ici');
 | 
			
		||||
      const ad = await this.queryBus.execute(new FindAdByUuidQuery(data));
 | 
			
		||||
      return this._mapper.map(ad, Ad, AdPresenter);
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1 +1,133 @@
 | 
			
		|||
export class CreateAdRequest {}
 | 
			
		||||
import { AutoMap } from '@automapper/classes';
 | 
			
		||||
import {
 | 
			
		||||
  IsOptional,
 | 
			
		||||
  IsString,
 | 
			
		||||
  IsBoolean,
 | 
			
		||||
  IsDate,
 | 
			
		||||
  IsInt,
 | 
			
		||||
  MinLength,
 | 
			
		||||
} from 'class-validator';
 | 
			
		||||
import { FrequencyType } from '../entities/frequencyEnum';
 | 
			
		||||
import { Address } from '../entities/address';
 | 
			
		||||
 | 
			
		||||
export class CreateAdRequest {
 | 
			
		||||
  @IsString()
 | 
			
		||||
  @IsOptional()
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  uuid?: string;
 | 
			
		||||
 | 
			
		||||
  @IsString()
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  userUuid: string;
 | 
			
		||||
 | 
			
		||||
  //@ValidateIf(o => o.passenger? false : true )
 | 
			
		||||
  @IsBoolean()
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  driver: boolean;
 | 
			
		||||
 | 
			
		||||
  //@ValidateIf(o => o.driver? false : true )
 | 
			
		||||
  @IsBoolean()
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  passenger?: boolean;
 | 
			
		||||
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  frequency: FrequencyType;
 | 
			
		||||
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  fromDate: Date;
 | 
			
		||||
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  toDate: Date;
 | 
			
		||||
 | 
			
		||||
  @IsDate()
 | 
			
		||||
  @IsOptional()
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  monTime: Date;
 | 
			
		||||
 | 
			
		||||
  @IsDate()
 | 
			
		||||
  @IsOptional()
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  tueTime: Date;
 | 
			
		||||
 | 
			
		||||
  @IsDate()
 | 
			
		||||
  @IsOptional()
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  wedTime: Date;
 | 
			
		||||
 | 
			
		||||
  @IsDate()
 | 
			
		||||
  @IsOptional()
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  thuTime: Date;
 | 
			
		||||
 | 
			
		||||
  @IsDate()
 | 
			
		||||
  @IsOptional()
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  friTime: Date;
 | 
			
		||||
 | 
			
		||||
  @IsDate()
 | 
			
		||||
  @IsOptional()
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  satTime: Date;
 | 
			
		||||
 | 
			
		||||
  @IsDate()
 | 
			
		||||
  @IsOptional()
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  sunTime: Date;
 | 
			
		||||
 | 
			
		||||
  @IsInt()
 | 
			
		||||
  @IsOptional()
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  Margin: number;
 | 
			
		||||
 | 
			
		||||
  @IsInt()
 | 
			
		||||
  @IsOptional()
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  tueMargin: number;
 | 
			
		||||
 | 
			
		||||
  @IsInt()
 | 
			
		||||
  @IsOptional()
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  wedMargin: number;
 | 
			
		||||
 | 
			
		||||
  @IsInt()
 | 
			
		||||
  @IsOptional()
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  thuMargin: number;
 | 
			
		||||
 | 
			
		||||
  @IsInt()
 | 
			
		||||
  @IsOptional()
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  friMargin: number;
 | 
			
		||||
 | 
			
		||||
  @IsInt()
 | 
			
		||||
  @IsOptional()
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  satMargin: number;
 | 
			
		||||
 | 
			
		||||
  @IsInt()
 | 
			
		||||
  @IsOptional()
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  sunMargin: number;
 | 
			
		||||
 | 
			
		||||
  //@ValidateIf(o => o.passenger? false : true )
 | 
			
		||||
  @IsInt()
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  seatsDriver?: number;
 | 
			
		||||
 | 
			
		||||
  //@ValidateIf(o => o.driver? false : true )
 | 
			
		||||
  @IsInt()
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  seatsPassenger?: number;
 | 
			
		||||
 | 
			
		||||
  @IsDate()
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  createdAt: Date;
 | 
			
		||||
 | 
			
		||||
  @IsDate()
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  updatedAt: Date;
 | 
			
		||||
 | 
			
		||||
  @MinLength(2)
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  addresses: Array<Address>;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,34 @@
 | 
			
		|||
import { AutoMap } from '@automapper/classes';
 | 
			
		||||
import { AddressType } from './addressEnum';
 | 
			
		||||
 | 
			
		||||
export class Address {
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  uuid?: string;
 | 
			
		||||
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  position: number;
 | 
			
		||||
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  lon: number;
 | 
			
		||||
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  lat: number;
 | 
			
		||||
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  houseNumber?: string;
 | 
			
		||||
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  street?: string;
 | 
			
		||||
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  locality: string;
 | 
			
		||||
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  postalCode: string;
 | 
			
		||||
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  country: string;
 | 
			
		||||
 | 
			
		||||
  @AutoMap()
 | 
			
		||||
  type: AddressType;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,7 @@
 | 
			
		|||
export enum AddressType {
 | 
			
		||||
  HOUSE_NUMBER = 'HOUSE_NUMBER',
 | 
			
		||||
  STREET_ADDRESS = 'STREET_ADDRESS',
 | 
			
		||||
  LOCALITY = 'LOCALITY',
 | 
			
		||||
  VENUE = 'VENUE',
 | 
			
		||||
  OTHER = 'OTHER',
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,4 @@
 | 
			
		|||
export enum FrequencyType {
 | 
			
		||||
  PUNCTUAL = 'PUNCTUAL',
 | 
			
		||||
  RECURRENT = 'RECURRENT',
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,52 +1,72 @@
 | 
			
		|||
import { classes } from '@automapper/classes';
 | 
			
		||||
import { AutomapperModule } from '@automapper/nestjs';
 | 
			
		||||
import { Ad } from '../../domain/entities/ad';
 | 
			
		||||
import { Test, TestingModule } from '@nestjs/testing';
 | 
			
		||||
import { CreateAdUseCase } from '../../domain/usecases/create-ad.usecase';
 | 
			
		||||
import { CreateAdRequest } from '../../domain/dtos/create-ad.request';
 | 
			
		||||
import { Address } from '../../domain/entities/address';
 | 
			
		||||
import { Messager } from '../../adapters/secondaries/messager';
 | 
			
		||||
import { AdsRepository } from '../../adapters/secondaries/ads.repository';
 | 
			
		||||
import { CreateAdCommand } from '../../commands/create-ad.command';
 | 
			
		||||
import { AddressType } from '../../domain/entities/addressEnum';
 | 
			
		||||
import { AutomapperModule } from '@automapper/nestjs';
 | 
			
		||||
import { classes } from '@automapper/classes';
 | 
			
		||||
import { FrequencyType } from '../../domain/entities/frequencyEnum';
 | 
			
		||||
 | 
			
		||||
const mockAddress1: Address = {
 | 
			
		||||
  position: 0,
 | 
			
		||||
  lon: '48.68944505415954',
 | 
			
		||||
  lat: '6.176510296462267',
 | 
			
		||||
  houseNumber: 5,
 | 
			
		||||
  lon: 48.68944505415954,
 | 
			
		||||
  lat: 6.176510296462267,
 | 
			
		||||
  houseNumber: '5',
 | 
			
		||||
  street: 'Avenue Foch',
 | 
			
		||||
  locality: 'Nancy',
 | 
			
		||||
  postalCode: '75000',
 | 
			
		||||
  country: 'France',
 | 
			
		||||
  type: 'HOUSE_NUMBER',
 | 
			
		||||
  type: AddressType.HOUSE_NUMBER,
 | 
			
		||||
};
 | 
			
		||||
const mockAddress2: Address = {
 | 
			
		||||
  position: 1,
 | 
			
		||||
  lon: '48.8566',
 | 
			
		||||
  lat: '2.3522',
 | 
			
		||||
  lon: 48.8566,
 | 
			
		||||
  lat: 2.3522,
 | 
			
		||||
  locality: 'Paris',
 | 
			
		||||
  postalCode: '75000',
 | 
			
		||||
  country: 'France',
 | 
			
		||||
  type: 'LOCALITY',
 | 
			
		||||
  type: AddressType.LOCALITY,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const newAdRequest: CreateAdRequest = {
 | 
			
		||||
  userUuid: 'a83e804a-e910-4c10-917f-5274533022b0',
 | 
			
		||||
  userUuid: '113e0000-0000-4000-a000-000000000000',
 | 
			
		||||
  driver: true,
 | 
			
		||||
  passenger: false,
 | 
			
		||||
  frequency: 'RECURRENT',
 | 
			
		||||
  frequency: FrequencyType.RECURRENT,
 | 
			
		||||
  fromDate: new Date('01-05-2023'),
 | 
			
		||||
  toDate: new Date('20-08-2023'),
 | 
			
		||||
  tueTime: new Date(''),
 | 
			
		||||
  wedTime: new Date(''),
 | 
			
		||||
  seatsPassenger: 2,
 | 
			
		||||
  adresses: [mockAddress1],
 | 
			
		||||
  adresses: [mockAddress1, mockAddress2],
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const mockMessager = {
 | 
			
		||||
  publish: jest.fn().mockImplementation(),
 | 
			
		||||
};
 | 
			
		||||
const mockAdRepository = {
 | 
			
		||||
  findOneByUuid: jest
 | 
			
		||||
    .fn()
 | 
			
		||||
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
 | 
			
		||||
    .mockImplementationOnce((command?: CreateAdCommand) => {
 | 
			
		||||
      return Promise.resolve({
 | 
			
		||||
        ...newAdRequest,
 | 
			
		||||
        uuid: 'ad000000-0000-4000-a000-000000000000',
 | 
			
		||||
      });
 | 
			
		||||
    })
 | 
			
		||||
    .mockImplementation(() => {
 | 
			
		||||
      throw new Error('Already exists');
 | 
			
		||||
    }),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
describe('CreateAdUseCase', () => {
 | 
			
		||||
  it('should be defined', () => {});
 | 
			
		||||
  let createAdUseCase: CreateAdUseCase;
 | 
			
		||||
  beforeAll(async () => {
 | 
			
		||||
    const module: TestingModule = await Test.createTestingModule({
 | 
			
		||||
      imports: [],
 | 
			
		||||
      imports: [AutomapperModule.forRoot({ strategyInitializer: classes() })],
 | 
			
		||||
      providers: [
 | 
			
		||||
        {
 | 
			
		||||
          provide: AdsRepository,
 | 
			
		||||
| 
						 | 
				
			
			@ -62,6 +82,10 @@ describe('CreateAdUseCase', () => {
 | 
			
		|||
 | 
			
		||||
    createAdUseCase = module.get<CreateAdUseCase>(CreateAdUseCase);
 | 
			
		||||
  });
 | 
			
		||||
  it('should be defined', () => {
 | 
			
		||||
    expect(createAdUseCase).toBeDefined();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  describe('execution', () => {
 | 
			
		||||
    it('should create an new ad', () => {});
 | 
			
		||||
    it('should throw an error if the ad already exists', () => {});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,7 +18,7 @@ const mockAdRepository = {
 | 
			
		|||
      return Promise.resolve(mockAd);
 | 
			
		||||
    })
 | 
			
		||||
    .mockImplementation(() => {
 | 
			
		||||
      return Promise.resolve(undefined);
 | 
			
		||||
      return Promise.resolve(null);
 | 
			
		||||
    }),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue