basic match query

This commit is contained in:
sbriat 2023-08-25 10:37:32 +02:00
parent a98e5b3c83
commit effe51b9a2
3 changed files with 38 additions and 9 deletions

View File

@ -116,4 +116,12 @@ export class MatchRequestDto {
@Min(0)
@Max(1)
maxDetourDurationRatio?: number;
@IsOptional()
@IsInt()
page?: number;
@IsOptional()
@IsInt()
perPage?: number;
}

View File

@ -25,7 +25,7 @@ export class MatchGrpcController {
data: matches,
page: 1,
perPage: 5,
total: 1,
total: matches.length,
};
} catch (e) {
throw new RpcException({

View File

@ -1,8 +1,10 @@
import { RpcExceptionCode } from '@mobicoop/ddd-library';
import { Frequency } from '@modules/matcher/core/domain/match.types';
import { MatchRequestDto } from '@modules/matcher/interface/grpc-controllers/dtos/match.request.dto';
import { WaypointDto } from '@modules/matcher/interface/grpc-controllers/dtos/waypoint.dto';
import { MatchGrpcController } from '@modules/matcher/interface/grpc-controllers/match.grpc-controller';
import { QueryBus } from '@nestjs/cqrs';
import { RpcException } from '@nestjs/microservices';
import { Test, TestingModule } from '@nestjs/testing';
const originWaypoint: WaypointDto = {
@ -38,14 +40,19 @@ const punctualMatchRequestDto: MatchRequestDto = {
};
const mockQueryBus = {
execute: jest.fn().mockImplementation(() => [
{
adId: 1,
},
{
adId: 2,
},
]),
execute: jest
.fn()
.mockImplementationOnce(() => [
{
adId: 1,
},
{
adId: 2,
},
])
.mockImplementationOnce(() => {
throw new Error();
}),
};
describe('Match Grpc Controller', () => {
@ -74,9 +81,23 @@ describe('Match Grpc Controller', () => {
});
it('should return matches', async () => {
jest.spyOn(mockQueryBus, 'execute');
const matchPaginatedResponseDto = await matchGrpcController.match(
punctualMatchRequestDto,
);
expect(matchPaginatedResponseDto.data).toHaveLength(2);
expect(mockQueryBus.execute).toHaveBeenCalledTimes(1);
});
it('should throw a generic RpcException', async () => {
jest.spyOn(mockQueryBus, 'execute');
expect.assertions(3);
try {
await matchGrpcController.match(punctualMatchRequestDto);
} catch (e: any) {
expect(e).toBeInstanceOf(RpcException);
expect(e.error.code).toBe(RpcExceptionCode.UNKNOWN);
}
expect(mockQueryBus.execute).toHaveBeenCalledTimes(1);
});
});