integration tests
This commit is contained in:
parent
7d2cf31a5e
commit
635a52c77d
|
@ -1,4 +1,10 @@
|
||||||
import { AD_MESSAGE_PUBLISHER, AD_REPOSITORY } from '@modules/ad/ad.di-tokens';
|
import {
|
||||||
|
AD_MESSAGE_PUBLISHER,
|
||||||
|
AD_REPOSITORY,
|
||||||
|
OUTPUT_DATETIME_TRANSFORMER,
|
||||||
|
TIMEZONE_FINDER,
|
||||||
|
TIME_CONVERTER,
|
||||||
|
} from '@modules/ad/ad.di-tokens';
|
||||||
import { AdMapper } from '@modules/ad/ad.mapper';
|
import { AdMapper } from '@modules/ad/ad.mapper';
|
||||||
import { AdEntity } from '@modules/ad/core/domain/ad.entity';
|
import { AdEntity } from '@modules/ad/core/domain/ad.entity';
|
||||||
import {
|
import {
|
||||||
|
@ -7,7 +13,10 @@ import {
|
||||||
Frequency,
|
Frequency,
|
||||||
} from '@modules/ad/core/domain/ad.types';
|
} from '@modules/ad/core/domain/ad.types';
|
||||||
import { AdRepository } from '@modules/ad/infrastructure/ad.repository';
|
import { AdRepository } from '@modules/ad/infrastructure/ad.repository';
|
||||||
|
import { OutputDateTimeTransformer } from '@modules/ad/infrastructure/output-datetime-transformer';
|
||||||
import { PrismaService } from '@modules/ad/infrastructure/prisma.service';
|
import { PrismaService } from '@modules/ad/infrastructure/prisma.service';
|
||||||
|
import { TimeConverter } from '@modules/ad/infrastructure/time-converter';
|
||||||
|
import { TimezoneFinder } from '@modules/ad/infrastructure/timezone-finder';
|
||||||
import { ConfigModule } from '@nestjs/config';
|
import { ConfigModule } from '@nestjs/config';
|
||||||
import { EventEmitterModule } from '@nestjs/event-emitter';
|
import { EventEmitterModule } from '@nestjs/event-emitter';
|
||||||
import { Test } from '@nestjs/testing';
|
import { Test } from '@nestjs/testing';
|
||||||
|
@ -30,6 +39,9 @@ describe('Ad Repository', () => {
|
||||||
const baseUuid = {
|
const baseUuid = {
|
||||||
uuid: 'be459a29-7a41-4c0b-b371-abe90bfb6f00',
|
uuid: 'be459a29-7a41-4c0b-b371-abe90bfb6f00',
|
||||||
};
|
};
|
||||||
|
const baseScheduleUuid = {
|
||||||
|
uuid: 'bad5e786-3b15-4e51-a8fc-926fa9327ff1',
|
||||||
|
};
|
||||||
const baseOriginWaypointUuid = {
|
const baseOriginWaypointUuid = {
|
||||||
uuid: 'bad5e786-3b15-4e51-a8fc-926fa9327ff1',
|
uuid: 'bad5e786-3b15-4e51-a8fc-926fa9327ff1',
|
||||||
};
|
};
|
||||||
|
@ -50,20 +62,11 @@ describe('Ad Repository', () => {
|
||||||
frequency: `'PUNCTUAL'`,
|
frequency: `'PUNCTUAL'`,
|
||||||
fromDate: `'2023-01-01'`,
|
fromDate: `'2023-01-01'`,
|
||||||
toDate: `'2023-01-01'`,
|
toDate: `'2023-01-01'`,
|
||||||
monTime: 'NULL',
|
};
|
||||||
tueTime: 'NULL',
|
const schedulePunctualAd = {
|
||||||
wedTime: 'NULL',
|
day: 0,
|
||||||
thuTime: 'NULL',
|
time: `'07:00'`,
|
||||||
friTime: 'NULL',
|
margin: 900,
|
||||||
satTime: 'NULL',
|
|
||||||
sunTime: `'2023-01-01T07:00:00Z'`,
|
|
||||||
monMargin: 900,
|
|
||||||
tueMargin: 900,
|
|
||||||
wedMargin: 900,
|
|
||||||
thuMargin: 900,
|
|
||||||
friMargin: 900,
|
|
||||||
satMargin: 900,
|
|
||||||
sunMargin: 900,
|
|
||||||
};
|
};
|
||||||
const originWaypoint = {
|
const originWaypoint = {
|
||||||
position: 0,
|
position: 0,
|
||||||
|
@ -92,6 +95,11 @@ describe('Ad Repository', () => {
|
||||||
for (let i = 0; i < nbToCreate; i++) {
|
for (let i = 0; i < nbToCreate; i++) {
|
||||||
adToCreate.uuid = getSeed(i, baseUuid.uuid);
|
adToCreate.uuid = getSeed(i, baseUuid.uuid);
|
||||||
await executeInsertCommand('ad', adToCreate);
|
await executeInsertCommand('ad', adToCreate);
|
||||||
|
await executeInsertCommand('schedule_item', {
|
||||||
|
uuid: getSeed(i, baseScheduleUuid.uuid),
|
||||||
|
adUuid: adToCreate.uuid,
|
||||||
|
...schedulePunctualAd,
|
||||||
|
});
|
||||||
await executeInsertCommand('waypoint', {
|
await executeInsertCommand('waypoint', {
|
||||||
uuid: getSeed(i, baseOriginWaypointUuid.uuid),
|
uuid: getSeed(i, baseOriginWaypointUuid.uuid),
|
||||||
adUuid: adToCreate.uuid,
|
adUuid: adToCreate.uuid,
|
||||||
|
@ -124,10 +132,26 @@ describe('Ad Repository', () => {
|
||||||
providers: [
|
providers: [
|
||||||
PrismaService,
|
PrismaService,
|
||||||
AdMapper,
|
AdMapper,
|
||||||
|
{
|
||||||
|
provide: AD_REPOSITORY,
|
||||||
|
useClass: AdRepository,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
provide: AD_MESSAGE_PUBLISHER,
|
provide: AD_MESSAGE_PUBLISHER,
|
||||||
useValue: mockMessagePublisher,
|
useValue: mockMessagePublisher,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
provide: TIMEZONE_FINDER,
|
||||||
|
useClass: TimezoneFinder,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provide: TIME_CONVERTER,
|
||||||
|
useClass: TimeConverter,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provide: OUTPUT_DATETIME_TRANSFORMER,
|
||||||
|
useClass: OutputDateTimeTransformer,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
// disable logging
|
// disable logging
|
||||||
|
@ -151,6 +175,7 @@ describe('Ad Repository', () => {
|
||||||
await createPunctualDriverAds(1);
|
await createPunctualDriverAds(1);
|
||||||
const result = await adRepository.findOneById(baseUuid.uuid, {
|
const result = await adRepository.findOneById(baseUuid.uuid, {
|
||||||
waypoints: true,
|
waypoints: true,
|
||||||
|
schedule: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result.id).toBe(baseUuid.uuid);
|
expect(result.id).toBe(baseUuid.uuid);
|
||||||
|
@ -158,7 +183,7 @@ describe('Ad Repository', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('create', () => {
|
describe('create', () => {
|
||||||
it('should create an ad', async () => {
|
it('should create a punctual ad', async () => {
|
||||||
const beforeCount = await prismaService.ad.count();
|
const beforeCount = await prismaService.ad.count();
|
||||||
|
|
||||||
const createAdProps: CreateAdProps = {
|
const createAdProps: CreateAdProps = {
|
||||||
|
@ -170,7 +195,9 @@ describe('Ad Repository', () => {
|
||||||
toDate: '2023-02-01',
|
toDate: '2023-02-01',
|
||||||
schedule: [
|
schedule: [
|
||||||
{
|
{
|
||||||
|
day: 3,
|
||||||
time: '12:05',
|
time: '12:05',
|
||||||
|
margin: 900,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
seatsProposed: 3,
|
seatsProposed: 3,
|
||||||
|
@ -224,19 +251,92 @@ describe('Ad Repository', () => {
|
||||||
expect(afterCount - beforeCount).toBe(1);
|
expect(afterCount - beforeCount).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
// it('should throw a UniqueConstraintException if ad already exists', async () => {
|
it('should create a recurrent ad', async () => {
|
||||||
// await prismaService.ad.create({
|
const beforeCount = await prismaService.ad.count();
|
||||||
// data: {
|
|
||||||
// uuid: uuid,
|
|
||||||
// password: bcrypt.hashSync(`password`, 10),
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
|
|
||||||
// const authenticationToCreate: AuthenticationEntity =
|
const createAdProps: CreateAdProps = {
|
||||||
// await AuthenticationEntity.create(createAuthenticationProps);
|
userId: 'b4b56444-f8d3-4110-917c-e37bba77f383',
|
||||||
// await expect(
|
driver: true,
|
||||||
// authenticationRepository.insert(authenticationToCreate),
|
passenger: false,
|
||||||
// ).rejects.toBeInstanceOf(UniqueConstraintException);
|
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: [
|
||||||
|
{
|
||||||
|
position: 0,
|
||||||
|
address: {
|
||||||
|
locality: 'Nice',
|
||||||
|
postalCode: '06000',
|
||||||
|
country: 'France',
|
||||||
|
coordinates: {
|
||||||
|
lon: 43.7102,
|
||||||
|
lat: 7.262,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
position: 1,
|
||||||
|
address: {
|
||||||
|
locality: 'Marseille',
|
||||||
|
postalCode: '13000',
|
||||||
|
country: 'France',
|
||||||
|
coordinates: {
|
||||||
|
lon: 43.2965,
|
||||||
|
lat: 5.3698,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const defaultAdProps: DefaultAdProps = {
|
||||||
|
driver: false,
|
||||||
|
passenger: true,
|
||||||
|
marginDuration: 900,
|
||||||
|
seatsProposed: 3,
|
||||||
|
seatsRequested: 1,
|
||||||
|
strict: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
const adToCreate: AdEntity = AdEntity.create(
|
||||||
|
createAdProps,
|
||||||
|
defaultAdProps,
|
||||||
|
);
|
||||||
|
await adRepository.insert(adToCreate);
|
||||||
|
|
||||||
|
const afterCount = await prismaService.ad.count();
|
||||||
|
|
||||||
|
expect(afterCount - beforeCount).toBe(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue