Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m51s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
74 lines
2.0 KiB
TypeScript
74 lines
2.0 KiB
TypeScript
import { InMemoryLeaderboardsRepository } from './InMemoryLeaderboardsRepository';
|
|
import { LeaderboardDriverData, LeaderboardTeamData } from '../../../../core/leaderboards/application/ports/LeaderboardsRepository';
|
|
|
|
describe('InMemoryLeaderboardsRepository', () => {
|
|
let repository: InMemoryLeaderboardsRepository;
|
|
|
|
beforeEach(() => {
|
|
repository = new InMemoryLeaderboardsRepository();
|
|
});
|
|
|
|
describe('drivers', () => {
|
|
it('should return empty array when no drivers exist', async () => {
|
|
// When
|
|
const result = await repository.findAllDrivers();
|
|
|
|
// Then
|
|
expect(result).toEqual([]);
|
|
});
|
|
|
|
it('should add and find all drivers', async () => {
|
|
// Given
|
|
const driver: LeaderboardDriverData = {
|
|
id: 'd1',
|
|
name: 'Driver 1',
|
|
rating: 1500,
|
|
raceCount: 10,
|
|
teamId: 't1',
|
|
teamName: 'Team 1',
|
|
};
|
|
repository.addDriver(driver);
|
|
|
|
// When
|
|
const result = await repository.findAllDrivers();
|
|
|
|
// Then
|
|
expect(result).toEqual([driver]);
|
|
});
|
|
|
|
it('should find drivers by team id', async () => {
|
|
// Given
|
|
const d1: LeaderboardDriverData = { id: 'd1', name: 'D1', rating: 1500, raceCount: 10, teamId: 't1', teamName: 'T1' };
|
|
const d2: LeaderboardDriverData = { id: 'd2', name: 'D2', rating: 1400, raceCount: 5, teamId: 't2', teamName: 'T2' };
|
|
repository.addDriver(d1);
|
|
repository.addDriver(d2);
|
|
|
|
// When
|
|
const result = await repository.findDriversByTeamId('t1');
|
|
|
|
// Then
|
|
expect(result).toEqual([d1]);
|
|
});
|
|
});
|
|
|
|
describe('teams', () => {
|
|
it('should add and find all teams', async () => {
|
|
// Given
|
|
const team: LeaderboardTeamData = {
|
|
id: 't1',
|
|
name: 'Team 1',
|
|
rating: 3000,
|
|
memberCount: 2,
|
|
raceCount: 20,
|
|
};
|
|
repository.addTeam(team);
|
|
|
|
// When
|
|
const result = await repository.findAllTeams();
|
|
|
|
// Then
|
|
expect(result).toEqual([team]);
|
|
});
|
|
});
|
|
});
|