import { CreateAdRequest } from '../../../domain/dtos/create-ad.request'; import { PointType } from '../../../../geography/domain/types/point-type.enum'; import { CreateAdUseCase } from '../../../domain/usecases/create-ad.usecase'; import { Test, TestingModule } from '@nestjs/testing'; import { AutomapperModule } from '@automapper/nestjs'; import { classes } from '@automapper/classes'; import { AdRepository } from '../../../adapters/secondaries/ad.repository'; import { CreateAdCommand } from '../../../commands/create-ad.command'; import { Ad } from '../../../domain/entities/ad'; import { AdProfile } from '../../../mappers/ad.profile'; const mockAdRepository = {}; const createAdRequest: CreateAdRequest = { uuid: '77c55dfc-c28b-4026-942e-f94e95401fb1', driver: true, passenger: false, frequency: 2, fromDate: '2023-04-26', toDate: '2024-04-25', monTime: '07:00', tueTime: '07:00', wedTime: '07:00', thuTime: '07:00', friTime: '07:00', satTime: null, sunTime: null, monMargin: 900, tueMargin: 900, wedMargin: 900, thuMargin: 900, friMargin: 900, satMargin: 900, sunMargin: 900, originType: PointType.OTHER, destinationType: PointType.OTHER, seatsDriver: 3, seatsPassenger: 1, createdAt: '2023-04-01 12:45', updatedAt: '2023-04-01 12:45', waypoints: [ { lon: 6, lat: 45 }, { lon: 6.5, lat: 45.5 }, ], }; describe('CreateAdUseCase', () => { let createAdUseCase: CreateAdUseCase; beforeAll(async () => { const module: TestingModule = await Test.createTestingModule({ imports: [AutomapperModule.forRoot({ strategyInitializer: classes() })], providers: [ { provide: AdRepository, useValue: mockAdRepository, }, AdProfile, CreateAdUseCase, ], }).compile(); createAdUseCase = module.get(CreateAdUseCase); }); it('should be defined', () => { expect(createAdUseCase).toBeDefined(); }); describe('execute', () => { it('should create an ad', async () => { const ad = await createAdUseCase.execute( new CreateAdCommand(createAdRequest), ); expect(ad).toBeInstanceOf(Ad); }); // it('should throw an exception when error occurs', async () => { // await expect( // createAdUseCase.execute( // new MatchQuery( // matchRequest, // defaultParams, // mockGeorouterCreator, // mockTimezoneFinder, // ), // ), // ).rejects.toBeInstanceOf(MatcherException); // }); }); });