mirror of
https://gitlab.com/mobicoop/v3/service/matcher.git
synced 2026-01-01 04:32:41 +00:00
fixed bad ad mapping
This commit is contained in:
@@ -5,11 +5,9 @@ import {
|
||||
} from '@modules/ad/ad.di-tokens';
|
||||
import { AdMapper } from '@modules/ad/ad.mapper';
|
||||
import { RouteProviderPort } from '@modules/ad/core/application/ports/route-provider.port';
|
||||
import { AdEntity } from '@modules/ad/core/domain/ad.entity';
|
||||
import { Frequency } from '@modules/ad/core/domain/ad.types';
|
||||
import {
|
||||
AdReadModel,
|
||||
AdRepository,
|
||||
} from '@modules/ad/infrastructure/ad.repository';
|
||||
import { AdRepository } from '@modules/ad/infrastructure/ad.repository';
|
||||
import { PrismaService } from '@modules/ad/infrastructure/prisma.service';
|
||||
import { DirectionEncoderPort } from '@modules/geography/core/application/ports/direction-encoder.port';
|
||||
import { EventEmitterModule } from '@nestjs/event-emitter';
|
||||
@@ -21,7 +19,58 @@ const mockMessagePublisher = {
|
||||
|
||||
const mockDirectionEncoder: DirectionEncoderPort = {
|
||||
encode: jest.fn(),
|
||||
decode: jest.fn(),
|
||||
decode: jest
|
||||
.fn()
|
||||
.mockImplementationOnce(() => [
|
||||
{
|
||||
lon: 6.1765102,
|
||||
lat: 48.689445,
|
||||
},
|
||||
{
|
||||
lon: 2.3522,
|
||||
lat: 48.8566,
|
||||
},
|
||||
])
|
||||
.mockImplementationOnce(() => [
|
||||
{
|
||||
lon: 6.1765109,
|
||||
lat: 48.689455,
|
||||
},
|
||||
{
|
||||
lon: 2.3598,
|
||||
lat: 48.8589,
|
||||
},
|
||||
])
|
||||
.mockImplementationOnce(() => [
|
||||
{
|
||||
lon: 6.1765102,
|
||||
lat: 48.689445,
|
||||
},
|
||||
{
|
||||
lon: 2.3522,
|
||||
lat: 48.8566,
|
||||
},
|
||||
])
|
||||
.mockImplementationOnce(() => [
|
||||
{
|
||||
lon: 6.1765102,
|
||||
lat: 48.689445,
|
||||
},
|
||||
{
|
||||
lon: 2.3522,
|
||||
lat: 48.8566,
|
||||
},
|
||||
])
|
||||
.mockImplementationOnce(() => [
|
||||
{
|
||||
lon: 6.1765102,
|
||||
lat: 48.689445,
|
||||
},
|
||||
{
|
||||
lon: 2.3522,
|
||||
lat: 48.8566,
|
||||
},
|
||||
]),
|
||||
};
|
||||
|
||||
const mockRouteProvider: RouteProviderPort = {
|
||||
@@ -43,7 +92,7 @@ const mockPrismaService = {
|
||||
seatsProposed: 3,
|
||||
seatsRequested: 1,
|
||||
strict: false,
|
||||
ddriverDistance: 350000,
|
||||
driverDistance: 350000,
|
||||
driverDuration: 14400,
|
||||
passengerDistance: 350000,
|
||||
passengerDuration: 14400,
|
||||
@@ -52,9 +101,12 @@ const mockPrismaService = {
|
||||
createdAt: new Date('2023-06-20T17:05:00Z'),
|
||||
updatedAt: new Date('2023-06-20T17:05:00Z'),
|
||||
waypoints: 'LINESTRING(6.1765102 48.689445,2.3522 48.8566)',
|
||||
scheduleItemUuid: 'b6bfac1f-e62e-4622-9641-a3475e15fc00',
|
||||
day: 3,
|
||||
time: new Date('2023-06-21T07:05:00Z'),
|
||||
margin: 900,
|
||||
scheduleItemCreatedAt: new Date('2023-06-20T17:05:00Z'),
|
||||
scheduleItemUpdatedAt: new Date('2023-06-20T17:05:00Z'),
|
||||
},
|
||||
{
|
||||
uuid: '84af18ff-8779-4cac-9651-1ed5ab0713c4',
|
||||
@@ -66,7 +118,7 @@ const mockPrismaService = {
|
||||
seatsProposed: 3,
|
||||
seatsRequested: 1,
|
||||
strict: false,
|
||||
ddriverDistance: 349000,
|
||||
driverDistance: 349000,
|
||||
driverDuration: 14300,
|
||||
passengerDistance: 350000,
|
||||
passengerDuration: 14400,
|
||||
@@ -75,9 +127,12 @@ const mockPrismaService = {
|
||||
createdAt: new Date('2023-06-18T14:16:10Z'),
|
||||
updatedAt: new Date('2023-06-18T14:16:10Z'),
|
||||
waypoints: 'LINESTRING(6.1765109 48.689455,2.3598 48.8589)',
|
||||
scheduleItemUuid: '01524541-2044-49dc-8be6-1a3ccdc653b0',
|
||||
day: 3,
|
||||
time: new Date('2023-06-21T07:14:00Z'),
|
||||
margin: 900,
|
||||
scheduleItemCreatedAt: new Date('2023-06-18T14:16:10Z'),
|
||||
scheduleItemUpdatedAt: new Date('2023-06-18T14:16:10Z'),
|
||||
},
|
||||
];
|
||||
})
|
||||
@@ -93,7 +148,7 @@ const mockPrismaService = {
|
||||
seatsProposed: 3,
|
||||
seatsRequested: 1,
|
||||
strict: false,
|
||||
ddriverDistance: 350000,
|
||||
driverDistance: 350000,
|
||||
driverDuration: 14400,
|
||||
passengerDistance: 350000,
|
||||
passengerDuration: 14400,
|
||||
@@ -102,9 +157,12 @@ const mockPrismaService = {
|
||||
createdAt: new Date('2023-06-20T17:05:00Z'),
|
||||
updatedAt: new Date('2023-06-20T17:05:00Z'),
|
||||
waypoints: 'LINESTRING(6.1765102 48.689445,2.3522 48.8566)',
|
||||
scheduleItemUuid: '1387b34f-8ab1-46e0-8d0f-803af0f40f28',
|
||||
day: 3,
|
||||
time: new Date('2023-06-21T07:05:00Z'),
|
||||
margin: 900,
|
||||
scheduleItemCreatedAt: new Date('2023-06-20T17:05:00Z'),
|
||||
scheduleItemUpdatedAt: new Date('2023-06-20T17:05:00Z'),
|
||||
},
|
||||
{
|
||||
uuid: 'cc260669-1c6d-441f-80a5-19cd59afb777',
|
||||
@@ -116,7 +174,7 @@ const mockPrismaService = {
|
||||
seatsProposed: 3,
|
||||
seatsRequested: 1,
|
||||
strict: false,
|
||||
ddriverDistance: 350000,
|
||||
driverDistance: 350000,
|
||||
driverDuration: 14400,
|
||||
passengerDistance: 350000,
|
||||
passengerDuration: 14400,
|
||||
@@ -125,9 +183,12 @@ const mockPrismaService = {
|
||||
createdAt: new Date('2023-06-20T17:05:00Z'),
|
||||
updatedAt: new Date('2023-06-20T17:05:00Z'),
|
||||
waypoints: 'LINESTRING(6.1765102 48.689445,2.3522 48.8566)',
|
||||
scheduleItemUuid: '1fa88104-c50b-4f10-b8ce-389df765f3a6',
|
||||
day: 4,
|
||||
time: new Date('2023-06-21T07:15:00Z'),
|
||||
margin: 900,
|
||||
scheduleItemCreatedAt: new Date('2023-06-20T17:05:00Z'),
|
||||
scheduleItemUpdatedAt: new Date('2023-06-20T17:05:00Z'),
|
||||
},
|
||||
{
|
||||
uuid: 'cc260669-1c6d-441f-80a5-19cd59afb777',
|
||||
@@ -139,7 +200,7 @@ const mockPrismaService = {
|
||||
seatsProposed: 3,
|
||||
seatsRequested: 1,
|
||||
strict: false,
|
||||
ddriverDistance: 350000,
|
||||
driverDistance: 350000,
|
||||
driverDuration: 14400,
|
||||
passengerDistance: 350000,
|
||||
passengerDuration: 14400,
|
||||
@@ -148,9 +209,12 @@ const mockPrismaService = {
|
||||
createdAt: new Date('2023-06-20T17:05:00Z'),
|
||||
updatedAt: new Date('2023-06-20T17:05:00Z'),
|
||||
waypoints: 'LINESTRING(6.1765102 48.689445,2.3522 48.8566)',
|
||||
scheduleItemUuid: '760bb1bb-256b-4e79-9d82-6d13011118f1',
|
||||
day: 5,
|
||||
time: new Date('2023-06-21T07:16:00Z'),
|
||||
margin: 900,
|
||||
scheduleItemCreatedAt: new Date('2023-06-20T17:05:00Z'),
|
||||
scheduleItemUpdatedAt: new Date('2023-06-20T17:05:00Z'),
|
||||
},
|
||||
];
|
||||
})
|
||||
@@ -194,22 +258,22 @@ describe('Ad repository', () => {
|
||||
});
|
||||
|
||||
it('should get candidates if query returns punctual Ads', async () => {
|
||||
const candidates: AdReadModel[] = await adRepository.getCandidates(
|
||||
const candidates: AdEntity[] = await adRepository.getCandidateAds(
|
||||
'somePunctualQueryString',
|
||||
);
|
||||
expect(candidates.length).toBe(2);
|
||||
});
|
||||
|
||||
it('should get candidates if query returns recurrent Ads', async () => {
|
||||
const candidates: AdReadModel[] = await adRepository.getCandidates(
|
||||
const candidates: AdEntity[] = await adRepository.getCandidateAds(
|
||||
'someRecurrentQueryString',
|
||||
);
|
||||
expect(candidates.length).toBe(1);
|
||||
expect(candidates[0].schedule.length).toBe(3);
|
||||
expect(candidates[0].getProps().schedule.length).toBe(3);
|
||||
});
|
||||
|
||||
it('should return an empty array of candidates if query does not return Ads', async () => {
|
||||
const candidates: AdReadModel[] = await adRepository.getCandidates(
|
||||
const candidates: AdEntity[] = await adRepository.getCandidateAds(
|
||||
'someQueryString',
|
||||
);
|
||||
expect(candidates.length).toBe(0);
|
||||
|
||||
Reference in New Issue
Block a user