website refactor

This commit is contained in:
2026-01-16 18:21:06 +01:00
parent 2f53727702
commit 095885544b
146 changed files with 970 additions and 524 deletions

View File

@@ -1,15 +1,12 @@
import { describe, it, expect, vi, Mock, beforeEach } from 'vitest';
import { describe, it, expect, vi, type Mock, beforeEach } from 'vitest';
import { Season } from '@core/racing/domain/entities/season/Season';
import type { SeasonRepository } from '@core/racing/domain/repositories/SeasonRepository';
import type { LeagueRepository } from '@core/racing/domain/repositories/LeagueRepository';
import {
CreateSeasonForLeagueUseCase,
type CreateSeasonForLeagueInput,
type CreateSeasonForLeagueResult,
type LeagueConfigFormModel,
} from '@core/racing/application/use-cases/CreateSeasonForLeagueUseCase';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import { Result } from '@core/shared/domain/Result';
function createLeagueConfigFormModel(overrides?: Partial<LeagueConfigFormModel>): LeagueConfigFormModel {
return {
@@ -68,13 +65,18 @@ function createLeagueConfigFormModel(overrides?: Partial<LeagueConfigFormModel>)
};
}
type CreateSeasonErrorCode = ApplicationErrorCode<'LEAGUE_NOT_FOUND' | 'VALIDATION_ERROR' | 'REPOSITORY_ERROR'> & {
details?: { message: string };
};
describe('CreateSeasonForLeagueUseCase', () => {
const mockLeagueFindById = vi.fn();
const mockLeagueRepo: any = {
const mockLeagueRepo: {
findById: Mock;
findAll: Mock;
findByOwnerId: Mock;
create: Mock;
update: Mock;
delete: Mock;
exists: Mock;
searchByName: Mock;
} = {
findById: mockLeagueFindById,
findAll: vi.fn(),
findByOwnerId: vi.fn(),
@@ -87,7 +89,15 @@ describe('CreateSeasonForLeagueUseCase', () => {
const mockSeasonFindById = vi.fn();
const mockSeasonAdd = vi.fn();
const mockSeasonRepo: any = {
const mockSeasonRepo: {
findById: Mock;
findByLeagueId: Mock;
create: Mock;
add: Mock;
update: Mock;
listByLeague: Mock;
listActiveByLeague: Mock;
} = {
findById: mockSeasonFindById,
findByLeagueId: vi.fn(),
create: vi.fn(),
@@ -105,7 +115,10 @@ describe('CreateSeasonForLeagueUseCase', () => {
mockLeagueFindById.mockResolvedValue({ id: 'league-1' });
mockSeasonAdd.mockResolvedValue(undefined);
const useCase = new CreateSeasonForLeagueUseCase(mockLeagueRepo, mockSeasonRepo);
const useCase = new CreateSeasonForLeagueUseCase(
mockLeagueRepo as unknown as LeagueRepository,
mockSeasonRepo as unknown as SeasonRepository
);
const config = createLeagueConfigFormModel({
basics: {
@@ -157,7 +170,10 @@ describe('CreateSeasonForLeagueUseCase', () => {
mockSeasonFindById.mockResolvedValue(sourceSeason);
mockSeasonAdd.mockResolvedValue(undefined);
const useCase = new CreateSeasonForLeagueUseCase(mockLeagueRepo, mockSeasonRepo);
const useCase = new CreateSeasonForLeagueUseCase(
mockLeagueRepo as unknown as LeagueRepository,
mockSeasonRepo as unknown as SeasonRepository
);
const command: CreateSeasonForLeagueInput = {
leagueId: 'league-1',
@@ -177,7 +193,10 @@ describe('CreateSeasonForLeagueUseCase', () => {
it('returns error when league not found', async () => {
mockLeagueFindById.mockResolvedValue(null);
const useCase = new CreateSeasonForLeagueUseCase(mockLeagueRepo, mockSeasonRepo);
const useCase = new CreateSeasonForLeagueUseCase(
mockLeagueRepo as unknown as LeagueRepository,
mockSeasonRepo as unknown as SeasonRepository
);
const command: CreateSeasonForLeagueInput = {
leagueId: 'missing-league',
@@ -197,7 +216,10 @@ describe('CreateSeasonForLeagueUseCase', () => {
mockLeagueFindById.mockResolvedValue({ id: 'league-1' });
mockSeasonFindById.mockResolvedValue(undefined);
const useCase = new CreateSeasonForLeagueUseCase(mockLeagueRepo, mockSeasonRepo);
const useCase = new CreateSeasonForLeagueUseCase(
mockLeagueRepo as unknown as LeagueRepository,
mockSeasonRepo as unknown as SeasonRepository
);
const command: CreateSeasonForLeagueInput = {
leagueId: 'league-1',