From 685b63e2cc98a7f5349a3c464f0751ddf0f01968 Mon Sep 17 00:00:00 2001 From: sbriat Date: Tue, 22 Aug 2023 10:55:27 +0200 Subject: [PATCH] get query tests --- .../unit/core/get-route.query-handler.spec.ts | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/modules/geography/tests/unit/core/get-route.query-handler.spec.ts diff --git a/src/modules/geography/tests/unit/core/get-route.query-handler.spec.ts b/src/modules/geography/tests/unit/core/get-route.query-handler.spec.ts new file mode 100644 index 0000000..d9c142e --- /dev/null +++ b/src/modules/geography/tests/unit/core/get-route.query-handler.spec.ts @@ -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); + }); + + 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'); + }); + }); +});