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

@@ -5,11 +5,10 @@ import {
type GetLeagueOwnerSummaryResult,
type GetLeagueOwnerSummaryErrorCode,
} from './GetLeagueOwnerSummaryUseCase';
import { DriverRepository } from '../../domain/repositories/DriverRepository';
import { LeagueRepository } from '../../domain/repositories/LeagueRepository';
import { Driver } from '../../domain/entities/Driver';
import { League } from '../../domain/entities/League';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
describe('GetLeagueOwnerSummaryUseCase', () => {
let useCase: GetLeagueOwnerSummaryUseCase;
let leagueRepository: {
@@ -18,6 +17,14 @@ describe('GetLeagueOwnerSummaryUseCase', () => {
let driverRepository: {
findById: Mock;
};
let leagueMembershipRepository: {
getLeagueMembers: Mock;
};
let standingRepository: {
findByDriverIdAndLeagueId: Mock;
findByLeagueId: Mock;
};
beforeEach(() => {
leagueRepository = {
findById: vi.fn(),
@@ -25,8 +32,19 @@ describe('GetLeagueOwnerSummaryUseCase', () => {
driverRepository = {
findById: vi.fn(),
};
useCase = new GetLeagueOwnerSummaryUseCase(leagueRepository as unknown as ILeagueRepository,
driverRepository as unknown as IDriverRepository);
leagueMembershipRepository = {
getLeagueMembers: vi.fn(),
};
standingRepository = {
findByDriverIdAndLeagueId: vi.fn(),
findByLeagueId: vi.fn(),
};
useCase = new GetLeagueOwnerSummaryUseCase(
leagueRepository as any,
driverRepository as any,
leagueMembershipRepository as any,
standingRepository as any
);
});
it('should return owner summary when league and owner exist', async () => {
@@ -48,15 +66,17 @@ describe('GetLeagueOwnerSummaryUseCase', () => {
leagueRepository.findById.mockResolvedValue(league);
driverRepository.findById.mockResolvedValue(driver);
leagueMembershipRepository.getLeagueMembers.mockResolvedValue([]);
standingRepository.findByDriverIdAndLeagueId.mockResolvedValue(null);
const result = await useCase.execute({ leagueId } as GetLeagueOwnerSummaryInput);
expect(result.isOk()).toBe(true);
expect(result.unwrap()).toBeUndefined();
const presented = expect(presented?.league).toBe(league);
expect(presented?.owner).toBe(driver);
expect(presented?.rating).toBe(0);
expect(presented?.rank).toBe(0);
const presented = result.unwrap();
expect(presented.league).toBe(league);
expect(presented.owner).toBe(driver);
expect(presented.rating).toBeNull();
expect(presented.rank).toBeNull();
});
it('should return error when league does not exist', async () => {
@@ -73,7 +93,7 @@ describe('GetLeagueOwnerSummaryUseCase', () => {
>;
expect(errorResult.code).toBe('LEAGUE_NOT_FOUND');
expect(errorResult.details.message).toBe('League not found');
});
});
it('should return error when owner does not exist', async () => {
const leagueId = 'league-1';
@@ -98,7 +118,7 @@ describe('GetLeagueOwnerSummaryUseCase', () => {
>;
expect(errorResult.code).toBe('OWNER_NOT_FOUND');
expect(errorResult.details.message).toBe('League owner not found');
});
});
it('should return repository error when repository throws', async () => {
const leagueId = 'league-1';
@@ -115,5 +135,5 @@ describe('GetLeagueOwnerSummaryUseCase', () => {
expect(errorResult.code).toBe('REPOSITORY_ERROR');
expect(errorResult.details.message).toBe('DB failure');
});
});
});