get route controller tests
This commit is contained in:
parent
14d2486c1b
commit
52a1a815e6
|
@ -3,7 +3,7 @@ import { RouteResponseDto } from '../dtos/route.response.dto';
|
||||||
import { GetRouteRequestDto } from './dtos/get-route.request.dto';
|
import { GetRouteRequestDto } from './dtos/get-route.request.dto';
|
||||||
import { RouteEntity } from '@modules/geography/core/domain/route.entity';
|
import { RouteEntity } from '@modules/geography/core/domain/route.entity';
|
||||||
import { GetRouteQuery } from '@modules/geography/core/application/queries/get-route/get-route.query';
|
import { GetRouteQuery } from '@modules/geography/core/application/queries/get-route/get-route.query';
|
||||||
import { RouteMapper } from '@modules/geography/geography.mapper';
|
import { RouteMapper } from '@modules/geography/route.mapper';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -14,13 +14,9 @@ export class GetRouteController {
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async get(data: GetRouteRequestDto): Promise<RouteResponseDto> {
|
async get(data: GetRouteRequestDto): Promise<RouteResponseDto> {
|
||||||
try {
|
const route: RouteEntity = await this.queryBus.execute(
|
||||||
const route: RouteEntity = await this.queryBus.execute(
|
new GetRouteQuery(data.roles, data.waypoints, data.georouterSettings),
|
||||||
new GetRouteQuery(data.roles, data.waypoints, data.georouterSettings),
|
);
|
||||||
);
|
return this.mapper.toResponse(route);
|
||||||
return this.mapper.toResponse(route);
|
|
||||||
} catch (e) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue