diff --git a/src/modules/ad/tests/integration/ad.fixtures.ts b/src/modules/ad/tests/integration/ad.fixtures.ts new file mode 100644 index 0000000..a28ea37 --- /dev/null +++ b/src/modules/ad/tests/integration/ad.fixtures.ts @@ -0,0 +1,62 @@ +import { CreateAdProps, Frequency } from '@modules/ad/core/domain/ad.types'; +import { PointProps } from '@modules/ad/core/domain/value-objects/point.value-object'; +import { ScheduleItemProps } from '@modules/ad/core/domain/value-objects/schedule-item.value-object'; + +export const Nice: PointProps = { + lat: 43.7102, + lon: 7.262, +}; + +export const Marseille: PointProps = { + lat: 43.2965, + lon: 5.3698, +}; + +export const SaintRaphael: PointProps = { + lat: 43.4268, + lon: 6.769, +}; + +export const Toulon: PointProps = { + lat: 43.1167, + lon: 5.95, +}; + +export function wednesday(time: string): ScheduleItemProps { + return { day: 3, time: time, margin: 900 }; +} + +export function weekdays(time: string): ScheduleItemProps[] { + return [1, 2, 3, 4, 5].map((day) => ({ + day: day, + time: time, + margin: 900, + })); +} + +export function NiceMarseille( + frequency: Frequency, + dates: string[], + schedule: ScheduleItemProps[], +): CreateAdProps { + return { + id: 'b4b56444-f8d3-4110-917c-e37bba77f383', + driver: true, + passenger: false, + frequency: frequency, + fromDate: dates[0], + toDate: dates[1], + schedule: schedule, + seatsProposed: 3, + seatsRequested: 1, + strict: false, + waypoints: [Nice, Marseille], + points: [Nice, SaintRaphael, Toulon, Marseille], + driverDuration: 7668, + driverDistance: 199000, + passengerDuration: 7668, + passengerDistance: 199000, + fwdAzimuth: 273, + backAzimuth: 93, + }; +} diff --git a/src/modules/ad/tests/integration/ad.repository.spec.ts b/src/modules/ad/tests/integration/ad.repository.spec.ts index 8cac004..8a5722d 100644 --- a/src/modules/ad/tests/integration/ad.repository.spec.ts +++ b/src/modules/ad/tests/integration/ad.repository.spec.ts @@ -1,7 +1,8 @@ import { AdEntity } from '@modules/ad/core/domain/ad.entity'; -import { CreateAdProps, Frequency } from '@modules/ad/core/domain/ad.types'; +import { Frequency } from '@modules/ad/core/domain/ad.types'; import { AdRepository } from '@modules/ad/infrastructure/ad.repository'; import { PrismaService } from '@modules/ad/infrastructure/prisma.service'; +import { NiceMarseille, wednesday, weekdays } from './ad.fixtures'; import { integrationTestingModule } from './integration.setup'; describe('Ad Repository', () => { @@ -24,60 +25,12 @@ describe('Ad Repository', () => { it('should create a punctual ad', async () => { const beforeCount = await prismaService.ad.count(); - const createAdProps: CreateAdProps = { - id: 'b4b56444-f8d3-4110-917c-e37bba77f383', - driver: true, - passenger: false, - frequency: Frequency.PUNCTUAL, - fromDate: '2023-02-01', - toDate: '2023-02-01', - schedule: [ - { - day: 3, - time: '12:05', - margin: 900, - }, - ], - seatsProposed: 3, - seatsRequested: 1, - strict: false, - waypoints: [ - { - lon: 43.7102, - lat: 7.262, - }, - { - lon: 43.2965, - lat: 5.3698, - }, - ], - points: [ - { - lon: 7.262, - lat: 43.7102, - }, - { - lon: 6.797838, - lat: 43.547031, - }, - { - lon: 6.18535, - lat: 43.407517, - }, - { - lon: 5.3698, - lat: 43.2965, - }, - ], - driverDuration: 7668, - driverDistance: 199000, - passengerDuration: 7668, - passengerDistance: 199000, - fwdAzimuth: 273, - backAzimuth: 93, - }; - - const adToCreate: AdEntity = AdEntity.create(createAdProps); + const createAdProps = NiceMarseille( + Frequency.PUNCTUAL, + ['2023-02-01', '2023-02-01'], + [wednesday('08:30')], + ); + const adToCreate = AdEntity.create(createAdProps); await adRepository.insertExtra(adToCreate, 'ad'); const afterCount = await prismaService.ad.count(); @@ -88,80 +41,13 @@ describe('Ad Repository', () => { it('should create a recurrent ad', async () => { const beforeCount = await prismaService.ad.count(); - const createAdProps: CreateAdProps = { - id: 'b4b56444-f8d3-4110-917c-e37bba77f383', - driver: true, - passenger: false, - frequency: Frequency.RECURRENT, - fromDate: '2023-02-01', - toDate: '2024-01-31', - schedule: [ - { - day: 1, - time: '08:00', - margin: 900, - }, - { - day: 2, - time: '08:00', - margin: 900, - }, - { - day: 3, - time: '09:00', - margin: 900, - }, - { - day: 4, - time: '08:00', - margin: 900, - }, - { - day: 5, - time: '08:00', - margin: 900, - }, - ], - seatsProposed: 3, - seatsRequested: 1, - strict: false, - waypoints: [ - { - lon: 43.7102, - lat: 7.262, - }, - { - lon: 43.2965, - lat: 5.3698, - }, - ], - points: [ - { - lon: 7.262, - lat: 43.7102, - }, - { - lon: 6.797838, - lat: 43.547031, - }, - { - lon: 6.18535, - lat: 43.407517, - }, - { - lon: 5.3698, - lat: 43.2965, - }, - ], - driverDuration: 7668, - driverDistance: 199000, - passengerDuration: 7668, - passengerDistance: 199000, - fwdAzimuth: 273, - backAzimuth: 93, - }; + const createAdProps = NiceMarseille( + Frequency.RECURRENT, + ['2023-02-01', '2024-01-31'], + weekdays('08:30'), + ); - const adToCreate: AdEntity = AdEntity.create(createAdProps); + const adToCreate = AdEntity.create(createAdProps); await adRepository.insertExtra(adToCreate, 'ad'); const afterCount = await prismaService.ad.count();