website refactor

This commit is contained in:
2026-01-16 15:20:25 +01:00
parent 7e02fc3ea5
commit 37b1aa626c
325 changed files with 2167 additions and 2782 deletions

View File

@@ -8,7 +8,7 @@ import {
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { SeasonRepository } from '../../domain/repositories/SeasonRepository';
import type { LeagueRepository } from '../../domain/repositories/LeagueRepository';
import { Season } from '../../domain/entities/season';
import { Season } from '../../domain/entities/season/Season';
import { League } from '../../domain/entities/League';
describe('GetLeagueSeasonsUseCase', () => {
@@ -18,7 +18,7 @@ describe('GetLeagueSeasonsUseCase', () => {
};
let leagueRepository: {
findById: Mock;
};
exists: Mock;
};
beforeEach(() => {
@@ -28,15 +28,14 @@ describe('GetLeagueSeasonsUseCase', () => {
leagueRepository = {
findById: vi.fn(),
exists: vi.fn(),
};
};
useCase = new GetLeagueSeasonsUseCase(seasonRepository as unknown as ISeasonRepository,
leagueRepository as unknown as ILeagueRepository);
useCase = new GetLeagueSeasonsUseCase(leagueRepository as any,
seasonRepository as any);
});
it('should present seasons with correct isParallelActive flags on success', async () => {
it('should return seasons with correct isParallelActive flags on success', async () => {
const leagueId = 'league-1';
const league = League.create({
id: leagueId,
@@ -64,24 +63,24 @@ describe('GetLeagueSeasonsUseCase', () => {
}),
];
leagueRepository.exists.mockResolvedValue(true);
leagueRepository.findById.mockResolvedValue(league);
seasonRepository.findByLeagueId.mockResolvedValue(seasons);
const result = await useCase.execute({ leagueId } satisfies GetLeagueSeasonsInput);
expect(result.isOk()).toBe(true);
expect(result.unwrap()).toBeUndefined();
const presented = result.unwrap();
const presented = expect(presented?.league).toBe(league);
expect(presented?.seasons).toHaveLength(2);
expect(presented.seasons).toHaveLength(2);
expect(presented?.seasons[0]?.season).toBe(seasons[0]);
expect(presented?.seasons[0]?.isPrimary).toBe(false);
expect(presented?.seasons[0]?.isParallelActive).toBe(false);
expect(presented.seasons[0]?.season).toBe(seasons[0]);
expect(presented.seasons[0]?.isPrimary).toBe(true);
expect(presented.seasons[0]?.isParallelActive).toBe(false);
expect(presented?.seasons[1]?.season).toBe(seasons[1]);
expect(presented?.seasons[1]?.isPrimary).toBe(false);
expect(presented?.seasons[1]?.isParallelActive).toBe(false);
expect(presented.seasons[1]?.season).toBe(seasons[1]);
expect(presented.seasons[1]?.isPrimary).toBe(false);
expect(presented.seasons[1]?.isParallelActive).toBe(false);
});
it('should set isParallelActive true for active seasons when multiple active', async () => {
@@ -110,23 +109,24 @@ describe('GetLeagueSeasonsUseCase', () => {
}),
];
leagueRepository.exists.mockResolvedValue(true);
leagueRepository.findById.mockResolvedValue(league);
seasonRepository.findByLeagueId.mockResolvedValue(seasons);
const result = await useCase.execute({ leagueId } satisfies GetLeagueSeasonsInput);
expect(result.isOk()).toBe(true);
expect(result.unwrap()).toBeUndefined();
const presented = result.unwrap();
const presented = expect(presented?.seasons).toHaveLength(2);
expect(presented?.seasons[0]?.isParallelActive).toBe(true);
expect(presented?.seasons[1]?.isParallelActive).toBe(true);
expect(presented.seasons).toHaveLength(2);
expect(presented.seasons[0]?.isParallelActive).toBe(true);
expect(presented.seasons[1]?.isParallelActive).toBe(true);
});
it('should return LEAGUE_NOT_FOUND error when league does not exist', async () => {
const leagueId = 'missing-league';
leagueRepository.findById.mockResolvedValue(null);
leagueRepository.exists.mockResolvedValue(false);
const result = await useCase.execute({ leagueId } satisfies GetLeagueSeasonsInput);
@@ -138,13 +138,13 @@ describe('GetLeagueSeasonsUseCase', () => {
expect(err.code).toBe('LEAGUE_NOT_FOUND');
expect(err.details.message).toBe('League not found');
});
});
it('should return REPOSITORY_ERROR when repository throws', async () => {
const leagueId = 'league-1';
const errorMessage = 'DB error';
leagueRepository.findById.mockRejectedValue(new Error(errorMessage));
leagueRepository.exists.mockRejectedValue(new Error(errorMessage));
const result = await useCase.execute({ leagueId } satisfies GetLeagueSeasonsInput);
@@ -156,5 +156,5 @@ describe('GetLeagueSeasonsUseCase', () => {
expect(err.code).toBe('REPOSITORY_ERROR');
expect(err.details.message).toBe(errorMessage);
});
});
});
});