improve tests

This commit is contained in:
sbriat 2023-04-12 11:47:02 +02:00
parent c396da77fc
commit b7822cf88f
3 changed files with 160 additions and 0 deletions

View File

@ -91,6 +91,7 @@
".module.ts",
".request.ts",
".presenter.ts",
".profile.ts",
".exception.ts",
"main.ts"
],
@ -107,6 +108,7 @@
".module.ts",
".request.ts",
".presenter.ts",
".profile.ts",
".exception.ts",
"main.ts"
],

View File

@ -0,0 +1,47 @@
import { Test, TestingModule } from '@nestjs/testing';
import { RedisConfigurationRepository } from '../../adapters/secondaries/redis-configuration.repository';
import { getRedisToken } from '@liaoliaots/nestjs-redis';
const mockRedis = {
get: jest.fn().mockResolvedValue('myValue'),
set: jest.fn().mockImplementation(),
del: jest.fn().mockImplementation(),
};
describe('RedisConfigurationRepository', () => {
let redisConfigurationRepository: RedisConfigurationRepository;
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
{
provide: getRedisToken('default'),
useValue: mockRedis,
},
RedisConfigurationRepository,
],
}).compile();
redisConfigurationRepository = module.get<RedisConfigurationRepository>(
RedisConfigurationRepository,
);
});
it('should be defined', () => {
expect(redisConfigurationRepository).toBeDefined();
});
describe('interact', () => {
it('should get a value', async () => {
expect(await redisConfigurationRepository.get('myKey')).toBe('myValue');
});
it('should set a value', async () => {
expect(
await redisConfigurationRepository.set('myKey', 'myValue'),
).toBeUndefined();
});
it('should delete a value', async () => {
expect(await redisConfigurationRepository.del('myKey')).toBeUndefined();
});
});
});

View File

@ -0,0 +1,111 @@
import { MatchRequest } from '../../domain/dtos/match.request';
import { Role } from '../../domain/entities/role.enum';
import { IDefaultParams } from '../../domain/interfaces/default-params.type';
import { MatchQuery } from '../../queries/match.query';
const defaultParams: IDefaultParams = {
DEFAULT_IDENTIFIER: 0,
MARGIN_DURATION: 900,
VALIDITY_DURATION: 365,
DEFAULT_TIMEZONE: 'Europe/Paris',
};
describe('Match query', () => {
it('should be defined', () => {
const matchRequest: MatchRequest = new MatchRequest();
matchRequest.departure = '2023-04-01 12:00';
matchRequest.waypoints = [
{
lat: 49.440041,
lon: 1.093912,
},
{
lat: 50.630992,
lon: 3.045432,
},
];
const matchQuery: MatchQuery = new MatchQuery(matchRequest, defaultParams);
expect(matchQuery).toBeDefined();
});
describe('init', () => {
it('should create a query with excluded identifiers', () => {
const matchRequest: MatchRequest = new MatchRequest();
matchRequest.departure = '2023-04-01 12:00';
matchRequest.waypoints = [
{
lat: 49.440041,
lon: 1.093912,
},
{
lat: 50.630992,
lon: 3.045432,
},
];
matchRequest.identifier = 125;
matchRequest.exclusions = [126, 127, 128];
const matchQuery: MatchQuery = new MatchQuery(
matchRequest,
defaultParams,
);
expect(matchQuery.exclusions.length).toBe(4);
});
});
it('should create a query with driver role only', () => {
const matchRequest: MatchRequest = new MatchRequest();
matchRequest.departure = '2023-04-01 12:00';
matchRequest.waypoints = [
{
lat: 49.440041,
lon: 1.093912,
},
{
lat: 50.630992,
lon: 3.045432,
},
];
matchRequest.driver = true;
const matchQuery: MatchQuery = new MatchQuery(matchRequest, defaultParams);
expect(matchQuery.roles).toEqual([Role.DRIVER]);
});
it('should create a query with passenger role only', () => {
const matchRequest: MatchRequest = new MatchRequest();
matchRequest.departure = '2023-04-01 12:00';
matchRequest.waypoints = [
{
lat: 49.440041,
lon: 1.093912,
},
{
lat: 50.630992,
lon: 3.045432,
},
];
matchRequest.passenger = true;
const matchQuery: MatchQuery = new MatchQuery(matchRequest, defaultParams);
expect(matchQuery.roles).toEqual([Role.PASSENGER]);
});
it('should create a query with driver and passenger roles', () => {
const matchRequest: MatchRequest = new MatchRequest();
matchRequest.departure = '2023-04-01 12:00';
matchRequest.waypoints = [
{
lat: 49.440041,
lon: 1.093912,
},
{
lat: 50.630992,
lon: 3.045432,
},
];
matchRequest.passenger = true;
matchRequest.driver = true;
const matchQuery: MatchQuery = new MatchQuery(matchRequest, defaultParams);
expect(matchQuery.roles.length).toBe(2);
expect(matchQuery.roles).toContain(Role.PASSENGER);
expect(matchQuery.roles).toContain(Role.DRIVER);
});
});