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,5 +1,10 @@
import { beforeEach, describe, expect, it, Mock, vi } from 'vitest';
import { ApplyPenaltyUseCase } from './ApplyPenaltyUseCase';
import { PenaltyRepository } from '../../domain/repositories/PenaltyRepository';
import { ProtestRepository } from '../../domain/repositories/ProtestRepository';
import { RaceRepository } from '../../domain/repositories/RaceRepository';
import { LeagueMembershipRepository } from '../../domain/repositories/LeagueMembershipRepository';
import type { Logger } from '@core/shared/domain/Logger';
describe('ApplyPenaltyUseCase', () => {
let mockPenaltyRepo: {
@@ -43,11 +48,13 @@ describe('ApplyPenaltyUseCase', () => {
});
it('should return error when race does not exist', async () => {
const useCase = new ApplyPenaltyUseCase(mockPenaltyRepo as any,
mockProtestRepo as any,
mockRaceRepo as any,
mockLeagueMembershipRepo as any,
mockLogger as any);
const useCase = new ApplyPenaltyUseCase(
mockPenaltyRepo as unknown as PenaltyRepository,
mockProtestRepo as unknown as ProtestRepository,
mockRaceRepo as unknown as RaceRepository,
mockLeagueMembershipRepo as unknown as LeagueMembershipRepository,
mockLogger as unknown as Logger
);
mockRaceRepo.findById.mockResolvedValue(null);
@@ -65,11 +72,13 @@ describe('ApplyPenaltyUseCase', () => {
});
it('should return error when steward does not have authority', async () => {
const useCase = new ApplyPenaltyUseCase(mockPenaltyRepo as any,
mockProtestRepo as any,
mockRaceRepo as any,
mockLeagueMembershipRepo as any,
mockLogger as any);
const useCase = new ApplyPenaltyUseCase(
mockPenaltyRepo as unknown as PenaltyRepository,
mockProtestRepo as unknown as ProtestRepository,
mockRaceRepo as unknown as RaceRepository,
mockLeagueMembershipRepo as unknown as LeagueMembershipRepository,
mockLogger as unknown as Logger
);
mockRaceRepo.findById.mockResolvedValue({ id: 'race1', leagueId: 'league1' });
@@ -95,11 +104,13 @@ describe('ApplyPenaltyUseCase', () => {
});
it('should return error when protest does not exist', async () => {
const useCase = new ApplyPenaltyUseCase(mockPenaltyRepo as any,
mockProtestRepo as any,
mockRaceRepo as any,
mockLeagueMembershipRepo as any,
mockLogger as any);
const useCase = new ApplyPenaltyUseCase(
mockPenaltyRepo as unknown as PenaltyRepository,
mockProtestRepo as unknown as ProtestRepository,
mockRaceRepo as unknown as RaceRepository,
mockLeagueMembershipRepo as unknown as LeagueMembershipRepository,
mockLogger as unknown as Logger
);
mockRaceRepo.findById.mockResolvedValue({ id: 'race1', leagueId: 'league1' });
@@ -127,11 +138,13 @@ describe('ApplyPenaltyUseCase', () => {
});
it('should return error when protest is not upheld', async () => {
const useCase = new ApplyPenaltyUseCase(mockPenaltyRepo as any,
mockProtestRepo as any,
mockRaceRepo as any,
mockLeagueMembershipRepo as any,
mockLogger as any);
const useCase = new ApplyPenaltyUseCase(
mockPenaltyRepo as unknown as PenaltyRepository,
mockProtestRepo as unknown as ProtestRepository,
mockRaceRepo as unknown as RaceRepository,
mockLeagueMembershipRepo as unknown as LeagueMembershipRepository,
mockLogger as unknown as Logger
);
mockRaceRepo.findById.mockResolvedValue({ id: 'race1', leagueId: 'league1' });
@@ -159,11 +172,13 @@ describe('ApplyPenaltyUseCase', () => {
});
it('should return error when protest is not for this race', async () => {
const useCase = new ApplyPenaltyUseCase(mockPenaltyRepo as any,
mockProtestRepo as any,
mockRaceRepo as any,
mockLeagueMembershipRepo as any,
mockLogger as any);
const useCase = new ApplyPenaltyUseCase(
mockPenaltyRepo as unknown as PenaltyRepository,
mockProtestRepo as unknown as ProtestRepository,
mockRaceRepo as unknown as RaceRepository,
mockLeagueMembershipRepo as unknown as LeagueMembershipRepository,
mockLogger as unknown as Logger
);
mockRaceRepo.findById.mockResolvedValue({ id: 'race1', leagueId: 'league1' });
@@ -191,11 +206,13 @@ describe('ApplyPenaltyUseCase', () => {
});
it('should create penalty and return result on success', async () => {
const useCase = new ApplyPenaltyUseCase(mockPenaltyRepo as any,
mockProtestRepo as any,
mockRaceRepo as any,
mockLeagueMembershipRepo as any,
mockLogger as any);
const useCase = new ApplyPenaltyUseCase(
mockPenaltyRepo as unknown as PenaltyRepository,
mockProtestRepo as unknown as ProtestRepository,
mockRaceRepo as unknown as RaceRepository,
mockLeagueMembershipRepo as unknown as LeagueMembershipRepository,
mockLogger as unknown as Logger
);
mockRaceRepo.findById.mockResolvedValue({ id: 'race1', leagueId: 'league1' });
@@ -223,7 +240,7 @@ describe('ApplyPenaltyUseCase', () => {
expect(presented.penaltyId).toBeDefined();
expect(mockPenaltyRepo.create).toHaveBeenCalledTimes(1);
const createdPenalty = (mockPenaltyRepo.create as Mock).mock.calls[0]?.[0] as any;
const createdPenalty = (mockPenaltyRepo.create as Mock).mock.calls[0]?.[0] as Penalty;
type ToStringable = { toString(): string };
const asString = (value: unknown): string => {