118 lines
3.9 KiB
TypeScript
118 lines
3.9 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import { GetLeagueFullConfigUseCase } from './GetLeagueFullConfigUseCase';
|
|
import type { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
|
|
import type { ISeasonRepository } from '../../domain/repositories/ISeasonRepository';
|
|
import type { ILeagueScoringConfigRepository } from '../../domain/repositories/ILeagueScoringConfigRepository';
|
|
import type { IGameRepository } from '../../domain/repositories/IGameRepository';
|
|
import type { LeagueFullConfigOutputPort } from '../ports/output/LeagueFullConfigOutputPort';
|
|
|
|
describe('GetLeagueFullConfigUseCase', () => {
|
|
let useCase: GetLeagueFullConfigUseCase;
|
|
let leagueRepository: ILeagueRepository;
|
|
let seasonRepository: ISeasonRepository;
|
|
let leagueScoringConfigRepository: ILeagueScoringConfigRepository;
|
|
let gameRepository: IGameRepository;
|
|
|
|
beforeEach(() => {
|
|
leagueRepository = {
|
|
findById: vi.fn(),
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
} as any;
|
|
seasonRepository = {
|
|
findByLeagueId: vi.fn(),
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
} as any;
|
|
leagueScoringConfigRepository = {
|
|
findBySeasonId: vi.fn(),
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
} as any;
|
|
gameRepository = {
|
|
findById: vi.fn(),
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
} as any;
|
|
|
|
useCase = new GetLeagueFullConfigUseCase(
|
|
leagueRepository,
|
|
seasonRepository,
|
|
leagueScoringConfigRepository,
|
|
gameRepository,
|
|
);
|
|
});
|
|
|
|
it('should return league config when league exists', async () => {
|
|
const params = { leagueId: 'league-1' };
|
|
|
|
const mockLeague = {
|
|
id: 'league-1',
|
|
name: 'Test League',
|
|
description: 'A test league',
|
|
settings: {
|
|
maxDrivers: 32,
|
|
stewarding: {
|
|
decisionMode: 'admin_only',
|
|
requireDefense: false,
|
|
defenseTimeLimit: 48,
|
|
voteTimeLimit: 72,
|
|
protestDeadlineHours: 48,
|
|
stewardingClosesHours: 168,
|
|
notifyAccusedOnProtest: true,
|
|
notifyOnVoteRequired: true,
|
|
},
|
|
},
|
|
};
|
|
const mockSeasons = [{ id: 'season-1', status: 'active', gameId: 'game-1' }];
|
|
const mockScoringConfig = { id: 'config-1' };
|
|
const mockGame = { id: 'game-1' };
|
|
|
|
leagueRepository.findById.mockResolvedValue(mockLeague);
|
|
seasonRepository.findByLeagueId.mockResolvedValue(mockSeasons);
|
|
leagueScoringConfigRepository.findBySeasonId.mockResolvedValue(mockScoringConfig);
|
|
gameRepository.findById.mockResolvedValue(mockGame);
|
|
|
|
const result = await useCase.execute(params);
|
|
|
|
expect(result.isOk()).toBe(true);
|
|
const output = result.value!;
|
|
expect(output).toEqual({
|
|
league: mockLeague,
|
|
activeSeason: mockSeasons[0],
|
|
scoringConfig: mockScoringConfig,
|
|
game: mockGame,
|
|
});
|
|
});
|
|
|
|
it('should return error when league not found', async () => {
|
|
const params = { leagueId: 'league-1' };
|
|
|
|
leagueRepository.findById.mockResolvedValue(null);
|
|
|
|
const result = await useCase.execute(params);
|
|
|
|
expect(result.isErr()).toBe(true);
|
|
const error = result.unwrapErr();
|
|
expect(error.code).toBe('LEAGUE_NOT_FOUND');
|
|
expect(error.details!.message).toBe('League with id league-1 not found');
|
|
});
|
|
|
|
it('should handle no active season', async () => {
|
|
const params = { leagueId: 'league-1' };
|
|
|
|
const mockLeague = {
|
|
id: 'league-1',
|
|
name: 'Test League',
|
|
description: 'A test league',
|
|
settings: { maxDrivers: 32 },
|
|
};
|
|
|
|
leagueRepository.findById.mockResolvedValue(mockLeague);
|
|
seasonRepository.findByLeagueId.mockResolvedValue([]);
|
|
|
|
const result = await useCase.execute(params);
|
|
|
|
expect(result.isOk()).toBe(true);
|
|
const output = result.value!;
|
|
expect(output).toEqual({
|
|
league: mockLeague,
|
|
});
|
|
});
|
|
}); |