wip league admin tools
This commit is contained in:
@@ -17,6 +17,10 @@ describe('GetLeagueScheduleUseCase', () => {
|
||||
let leagueRepository: {
|
||||
findById: Mock;
|
||||
};
|
||||
let seasonRepository: {
|
||||
findById: Mock;
|
||||
findByLeagueId: Mock;
|
||||
};
|
||||
let raceRepository: {
|
||||
findByLeagueId: Mock;
|
||||
};
|
||||
@@ -27,6 +31,10 @@ describe('GetLeagueScheduleUseCase', () => {
|
||||
leagueRepository = {
|
||||
findById: vi.fn(),
|
||||
};
|
||||
seasonRepository = {
|
||||
findById: vi.fn(),
|
||||
findByLeagueId: vi.fn(),
|
||||
};
|
||||
raceRepository = {
|
||||
findByLeagueId: vi.fn(),
|
||||
};
|
||||
@@ -42,6 +50,7 @@ describe('GetLeagueScheduleUseCase', () => {
|
||||
|
||||
useCase = new GetLeagueScheduleUseCase(
|
||||
leagueRepository as unknown as ILeagueRepository,
|
||||
seasonRepository as any,
|
||||
raceRepository as unknown as IRaceRepository,
|
||||
logger,
|
||||
output,
|
||||
@@ -60,6 +69,9 @@ describe('GetLeagueScheduleUseCase', () => {
|
||||
});
|
||||
|
||||
leagueRepository.findById.mockResolvedValue(league);
|
||||
seasonRepository.findByLeagueId.mockResolvedValue([
|
||||
{ id: 'season-1', leagueId, status: { isActive: () => true } },
|
||||
]);
|
||||
raceRepository.findByLeagueId.mockResolvedValue([race]);
|
||||
|
||||
const input: GetLeagueScheduleInput = { leagueId };
|
||||
@@ -69,19 +81,74 @@ describe('GetLeagueScheduleUseCase', () => {
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
const presented =
|
||||
output.present.mock.calls[0]?.[0] as GetLeagueScheduleResult;
|
||||
const presented = output.present.mock.calls[0]?.[0] as GetLeagueScheduleResult;
|
||||
|
||||
expect(presented.league).toBe(league);
|
||||
expect(presented.seasonId).toBe('season-1');
|
||||
expect(presented.published).toBe(false);
|
||||
expect(presented.races).toHaveLength(1);
|
||||
expect(presented.races[0]?.race).toBe(race);
|
||||
});
|
||||
|
||||
it('should scope schedule by seasonId (no season bleed)', async () => {
|
||||
const leagueId = 'league-1';
|
||||
const league = { id: leagueId } as unknown as League;
|
||||
|
||||
const janRace = Race.create({
|
||||
id: 'race-jan',
|
||||
leagueId,
|
||||
scheduledAt: new Date('2025-01-10T20:00:00Z'),
|
||||
track: 'Track Jan',
|
||||
car: 'Car Jan',
|
||||
});
|
||||
|
||||
const febRace = Race.create({
|
||||
id: 'race-feb',
|
||||
leagueId,
|
||||
scheduledAt: new Date('2025-02-10T20:00:00Z'),
|
||||
track: 'Track Feb',
|
||||
car: 'Car Feb',
|
||||
});
|
||||
|
||||
leagueRepository.findById.mockResolvedValue(league);
|
||||
seasonRepository.findById.mockImplementation(async (id: string) => {
|
||||
if (id === 'season-jan') {
|
||||
return { id, leagueId, startDate: new Date('2025-01-01T00:00:00Z'), endDate: new Date('2025-01-31T23:59:59Z') };
|
||||
}
|
||||
if (id === 'season-feb') {
|
||||
return { id, leagueId, startDate: new Date('2025-02-01T00:00:00Z'), endDate: new Date('2025-02-28T23:59:59Z') };
|
||||
}
|
||||
return null;
|
||||
});
|
||||
raceRepository.findByLeagueId.mockResolvedValue([janRace, febRace]);
|
||||
|
||||
// Season 1 covers January
|
||||
const resultSeason1 = await useCase.execute({ leagueId, seasonId: 'season-jan' } as any);
|
||||
expect(resultSeason1.isOk()).toBe(true);
|
||||
|
||||
const presented1 = output.present.mock.calls.at(-1)?.[0] as any;
|
||||
expect(presented1.seasonId).toBe('season-jan');
|
||||
expect(presented1.published).toBe(false);
|
||||
expect((presented1.races as GetLeagueScheduleResult['races']).map(r => r.race.id)).toEqual(['race-jan']);
|
||||
|
||||
// Season 2 covers February
|
||||
const resultSeason2 = await useCase.execute({ leagueId, seasonId: 'season-feb' } as any);
|
||||
expect(resultSeason2.isOk()).toBe(true);
|
||||
|
||||
const presented2 = output.present.mock.calls.at(-1)?.[0] as any;
|
||||
expect(presented2.seasonId).toBe('season-feb');
|
||||
expect(presented2.published).toBe(false);
|
||||
expect((presented2.races as GetLeagueScheduleResult['races']).map(r => r.race.id)).toEqual(['race-feb']);
|
||||
});
|
||||
|
||||
it('should present empty schedule when no races exist', async () => {
|
||||
const leagueId = 'league-1';
|
||||
const league = { id: leagueId } as unknown as League;
|
||||
|
||||
leagueRepository.findById.mockResolvedValue(league);
|
||||
seasonRepository.findByLeagueId.mockResolvedValue([
|
||||
{ id: 'season-1', leagueId, status: { isActive: () => true } },
|
||||
]);
|
||||
raceRepository.findByLeagueId.mockResolvedValue([]);
|
||||
|
||||
const input: GetLeagueScheduleInput = { leagueId };
|
||||
@@ -95,6 +162,7 @@ describe('GetLeagueScheduleUseCase', () => {
|
||||
output.present.mock.calls[0]?.[0] as GetLeagueScheduleResult;
|
||||
|
||||
expect(presented.league).toBe(league);
|
||||
expect(presented.published).toBe(false);
|
||||
expect(presented.races).toHaveLength(0);
|
||||
});
|
||||
|
||||
@@ -123,6 +191,9 @@ describe('GetLeagueScheduleUseCase', () => {
|
||||
const repositoryError = new Error('DB down');
|
||||
|
||||
leagueRepository.findById.mockResolvedValue(league);
|
||||
seasonRepository.findByLeagueId.mockResolvedValue([
|
||||
{ id: 'season-1', leagueId, status: { isActive: () => true } },
|
||||
]);
|
||||
raceRepository.findByLeagueId.mockRejectedValue(repositoryError);
|
||||
|
||||
const input: GetLeagueScheduleInput = { leagueId };
|
||||
|
||||
Reference in New Issue
Block a user