71 lines
1.7 KiB
TypeScript
71 lines
1.7 KiB
TypeScript
import { Role } from '@modules/geography/core/domain/route.types';
|
|
import { GetRouteController } from '@modules/geography/interface/controllers/get-route.controller';
|
|
import { RouteMapper } from '@modules/geography/route.mapper';
|
|
import { QueryBus } from '@nestjs/cqrs';
|
|
import { Test, TestingModule } from '@nestjs/testing';
|
|
|
|
const mockQueryBus = {
|
|
execute: jest.fn(),
|
|
};
|
|
|
|
const mockRouteMapper = {
|
|
toPersistence: jest.fn(),
|
|
toDomain: jest.fn(),
|
|
toResponse: jest.fn(),
|
|
};
|
|
|
|
describe('Get Route Controller', () => {
|
|
let getRouteController: GetRouteController;
|
|
|
|
beforeAll(async () => {
|
|
const module: TestingModule = await Test.createTestingModule({
|
|
providers: [
|
|
{
|
|
provide: QueryBus,
|
|
useValue: mockQueryBus,
|
|
},
|
|
{
|
|
provide: RouteMapper,
|
|
useValue: mockRouteMapper,
|
|
},
|
|
GetRouteController,
|
|
],
|
|
}).compile();
|
|
|
|
getRouteController = module.get<GetRouteController>(GetRouteController);
|
|
});
|
|
|
|
afterEach(async () => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
it('should be defined', () => {
|
|
expect(getRouteController).toBeDefined();
|
|
});
|
|
|
|
it('should get a route', async () => {
|
|
jest.spyOn(mockQueryBus, 'execute');
|
|
await getRouteController.get({
|
|
roles: [Role.DRIVER],
|
|
waypoints: [
|
|
{
|
|
position: 0,
|
|
lon: 48.689445,
|
|
lat: 6.17651,
|
|
},
|
|
{
|
|
position: 1,
|
|
lon: 48.8566,
|
|
lat: 2.3522,
|
|
},
|
|
],
|
|
georouterSettings: {
|
|
points: true,
|
|
detailedDistance: false,
|
|
detailedDuration: false,
|
|
},
|
|
});
|
|
expect(mockQueryBus.execute).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|