get query tests

This commit is contained in:
sbriat 2023-08-22 10:55:27 +02:00
parent 571699a66c
commit 685b63e2cc
1 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,65 @@
import { GeorouterPort } from '@modules/geography/core/application/ports/georouter.port';
import { GetRouteQuery } from '@modules/geography/core/application/queries/get-route/get-route.query';
import { GetRouteQueryHandler } from '@modules/geography/core/application/queries/get-route/get-route.query-handler';
import { Waypoint } from '@modules/geography/core/application/types/waypoint.type';
import { RouteEntity } from '@modules/geography/core/domain/route.entity';
import { Role } from '@modules/geography/core/domain/route.types';
import { GEOROUTER } from '@modules/geography/geography.di-tokens';
import { Test, TestingModule } from '@nestjs/testing';
const originWaypoint: Waypoint = {
position: 0,
lon: 48.689445,
lat: 6.17651,
};
const destinationWaypoint: Waypoint = {
position: 1,
lon: 48.8566,
lat: 2.3522,
};
const mockGeorouter: GeorouterPort = {
routes: jest.fn(),
};
describe('Get route query handler', () => {
let getRoutequeryHandler: GetRouteQueryHandler;
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
{
provide: GEOROUTER,
useValue: mockGeorouter,
},
GetRouteQueryHandler,
],
}).compile();
getRoutequeryHandler =
module.get<GetRouteQueryHandler>(GetRouteQueryHandler);
});
it('should be defined', () => {
expect(getRoutequeryHandler).toBeDefined();
});
describe('execution', () => {
it('should get a route for a driver only', async () => {
const getRoutequery = new GetRouteQuery(
[Role.DRIVER],
[originWaypoint, destinationWaypoint],
{
detailedDistance: false,
detailedDuration: false,
points: true,
},
);
RouteEntity.create = jest.fn().mockReturnValue({
id: '047a6ecf-23d4-4d3e-877c-3225d560a8da',
});
const result = await getRoutequeryHandler.execute(getRoutequery);
expect(result.id).toBe('047a6ecf-23d4-4d3e-877c-3225d560a8da');
});
});
});