website refactor
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { describe, it, expect, vi, Mock } from 'vitest';
|
||||
|
||||
import { describe, it, expect, vi, 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';
|
||||
@@ -75,7 +74,7 @@ type CreateSeasonErrorCode = ApplicationErrorCode<'LEAGUE_NOT_FOUND' | 'VALIDATI
|
||||
|
||||
describe('CreateSeasonForLeagueUseCase', () => {
|
||||
const mockLeagueFindById = vi.fn();
|
||||
const mockLeagueRepo: ILeagueRepository = {
|
||||
const mockLeagueRepo: any = {
|
||||
findById: mockLeagueFindById,
|
||||
findAll: vi.fn(),
|
||||
findByOwnerId: vi.fn(),
|
||||
@@ -88,7 +87,7 @@ describe('CreateSeasonForLeagueUseCase', () => {
|
||||
|
||||
const mockSeasonFindById = vi.fn();
|
||||
const mockSeasonAdd = vi.fn();
|
||||
const mockSeasonRepo: ISeasonRepository = {
|
||||
const mockSeasonRepo: any = {
|
||||
findById: mockSeasonFindById,
|
||||
findByLeagueId: vi.fn(),
|
||||
create: vi.fn(),
|
||||
@@ -98,11 +97,8 @@ describe('CreateSeasonForLeagueUseCase', () => {
|
||||
listActiveByLeague: vi.fn(),
|
||||
};
|
||||
|
||||
let output: { present: Mock } ;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
output = { present: vi.fn() } as unknown as typeof output;
|
||||
});
|
||||
|
||||
it('creates a planned Season for an existing league with config-derived props', async () => {
|
||||
@@ -125,8 +121,6 @@ describe('CreateSeasonForLeagueUseCase', () => {
|
||||
strategy: 'dropWorstN',
|
||||
n: 2,
|
||||
},
|
||||
// Intentionally omit seasonStartDate / raceStartTime to avoid schedule derivation,
|
||||
// focusing this test on scoring/drop/stewarding/maxDrivers mapping.
|
||||
timings: {
|
||||
qualifyingMinutes: 10,
|
||||
mainRaceMinutes: 30,
|
||||
@@ -141,13 +135,13 @@ describe('CreateSeasonForLeagueUseCase', () => {
|
||||
config,
|
||||
};
|
||||
|
||||
const result: Result<void, CreateSeasonErrorCode> = await useCase.execute(command);
|
||||
const result = await useCase.execute(command);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
const presented = result.unwrap();
|
||||
|
||||
const presented = (expect(presented?.season).toBeInstanceOf(Season);
|
||||
expect(presented?.league.id).toBe('league-1');
|
||||
expect(presented.season).toBeInstanceOf(Season);
|
||||
expect(presented.league.id).toBe('league-1');
|
||||
});
|
||||
|
||||
it('clones configuration from a source season when sourceSeasonId is provided', async () => {
|
||||
@@ -172,15 +166,15 @@ describe('CreateSeasonForLeagueUseCase', () => {
|
||||
sourceSeasonId: 'source-season',
|
||||
};
|
||||
|
||||
const result: Result<void, CreateSeasonErrorCode> = await useCase.execute(command);
|
||||
const result = await useCase.execute(command);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
const presented = result.unwrap();
|
||||
|
||||
const presented = (expect(presented?.season.maxDrivers).toBe(40);
|
||||
expect(presented.season.maxDrivers).toBe(40);
|
||||
});
|
||||
|
||||
it('returns error when league not found and does not call output', async () => {
|
||||
it('returns error when league not found', async () => {
|
||||
mockLeagueFindById.mockResolvedValue(null);
|
||||
|
||||
const useCase = new CreateSeasonForLeagueUseCase(mockLeagueRepo, mockSeasonRepo);
|
||||
@@ -191,15 +185,15 @@ describe('CreateSeasonForLeagueUseCase', () => {
|
||||
gameId: 'iracing',
|
||||
};
|
||||
|
||||
const result: Result<void, CreateSeasonErrorCode> = await useCase.execute(command);
|
||||
const result = await useCase.execute(command);
|
||||
|
||||
expect(result.isErr()).toBe(true);
|
||||
const error = result.unwrapErr();
|
||||
expect(error.code).toBe('LEAGUE_NOT_FOUND');
|
||||
expect(error.details?.message).toBe('League not found: missing-league');
|
||||
});
|
||||
});
|
||||
|
||||
it('returns validation error when source season is missing and does not call output', async () => {
|
||||
it('returns validation error when source season is missing', async () => {
|
||||
mockLeagueFindById.mockResolvedValue({ id: 'league-1' });
|
||||
mockSeasonFindById.mockResolvedValue(undefined);
|
||||
|
||||
@@ -212,11 +206,11 @@ describe('CreateSeasonForLeagueUseCase', () => {
|
||||
sourceSeasonId: 'missing-source',
|
||||
};
|
||||
|
||||
const result: Result<void, CreateSeasonErrorCode> = await useCase.execute(command);
|
||||
const result = await useCase.execute(command);
|
||||
|
||||
expect(result.isErr()).toBe(true);
|
||||
const error = result.unwrapErr();
|
||||
expect(error.code).toBe('VALIDATION_ERROR');
|
||||
expect(error.details?.message).toBe('Source Season not found: missing-source');
|
||||
});
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user