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

@@ -15,6 +15,7 @@ describe('FileProtestUseCase', () => {
let mockLeagueMembershipRepo: {
getLeagueMembers: Mock;
};
beforeEach(() => {
mockProtestRepo = {
create: vi.fn(),
@@ -25,12 +26,12 @@ describe('FileProtestUseCase', () => {
mockLeagueMembershipRepo = {
getLeagueMembers: vi.fn(),
};
});
});
it('should return error when race does not exist', async () => {
const useCase = new FileProtestUseCase(mockProtestRepo as unknown as IProtestRepository,
mockRaceRepo as unknown as IRaceRepository,
mockLeagueMembershipRepo as unknown as ILeagueMembershipRepository);
const useCase = new FileProtestUseCase(mockProtestRepo as any,
mockRaceRepo as any,
mockLeagueMembershipRepo as any);
mockRaceRepo.findById.mockResolvedValue(null);
@@ -45,12 +46,12 @@ describe('FileProtestUseCase', () => {
const err = result.unwrapErr() as ApplicationErrorCode<FileProtestErrorCode, { message: string }>;
expect(err.code).toBe('RACE_NOT_FOUND');
expect(err.details?.message).toBe('Race not found');
});
});
it('should return error when protesting against self', async () => {
const useCase = new FileProtestUseCase(mockProtestRepo as unknown as IProtestRepository,
mockRaceRepo as unknown as IRaceRepository,
mockLeagueMembershipRepo as unknown as ILeagueMembershipRepository);
const useCase = new FileProtestUseCase(mockProtestRepo as any,
mockRaceRepo as any,
mockLeagueMembershipRepo as any);
mockRaceRepo.findById.mockResolvedValue({ id: 'race1', leagueId: 'league1' });
@@ -65,12 +66,12 @@ describe('FileProtestUseCase', () => {
const err = result.unwrapErr() as ApplicationErrorCode<FileProtestErrorCode, { message: string }>;
expect(err.code).toBe('SELF_PROTEST');
expect(err.details?.message).toBe('Cannot file a protest against yourself');
});
});
it('should return error when protesting driver is not an active member', async () => {
const useCase = new FileProtestUseCase(mockProtestRepo as unknown as IProtestRepository,
mockRaceRepo as unknown as IRaceRepository,
mockLeagueMembershipRepo as unknown as ILeagueMembershipRepository);
const useCase = new FileProtestUseCase(mockProtestRepo as any,
mockRaceRepo as any,
mockLeagueMembershipRepo as any);
mockRaceRepo.findById.mockResolvedValue({ id: 'race1', leagueId: 'league1' });
mockLeagueMembershipRepo.getLeagueMembers.mockResolvedValue([
@@ -88,12 +89,12 @@ describe('FileProtestUseCase', () => {
const err = result.unwrapErr() as ApplicationErrorCode<FileProtestErrorCode, { message: string }>;
expect(err.code).toBe('NOT_MEMBER');
expect(err.details?.message).toBe('Protesting driver is not an active member of this league');
});
});
it('should create protest and return protestId on success', async () => {
const useCase = new FileProtestUseCase(mockProtestRepo as unknown as IProtestRepository,
mockRaceRepo as unknown as IRaceRepository,
mockLeagueMembershipRepo as unknown as ILeagueMembershipRepository);
const useCase = new FileProtestUseCase(mockProtestRepo as any,
mockRaceRepo as any,
mockLeagueMembershipRepo as any);
mockRaceRepo.findById.mockResolvedValue({ id: 'race1', leagueId: 'league1' });
mockLeagueMembershipRepo.getLeagueMembers.mockResolvedValue([
@@ -111,21 +112,9 @@ describe('FileProtestUseCase', () => {
} as FileProtestInput);
expect(result.isOk()).toBe(true);
expect(result.unwrap()).toBeUndefined();
const presented = result.unwrap();
expect(mockProtestRepo.create).toHaveBeenCalledTimes(1);
const created = (mockProtestRepo.create as unknown as Mock).mock.calls[0]?.[0] as unknown as {
raceId: { toString(): string };
protestingDriverId: { toString(): string };
accusedDriverId: { toString(): string };
comment?: string;
proofVideoUrl: { toString(): string };
status: { toString(): string };
incident: {
lap: { toNumber(): number };
description: { toString(): string };
timeInRace?: unknown;
};
};
const created = (mockProtestRepo.create as unknown as Mock).mock.calls[0]?.[0] as any;
expect(created.raceId.toString()).toBe('race1');
expect(created.protestingDriverId.toString()).toBe('driver1');
@@ -136,16 +125,14 @@ describe('FileProtestUseCase', () => {
expect(created.incident.lap.toNumber()).toBe(5);
expect(created.incident.description.toString()).toBe('Collision');
expect(created.incident.timeInRace).toBeUndefined();
const presented = (expect(presented.protest.raceId.toString()).toBe('race1');
expect(presented.protest.raceId.toString()).toBe('race1');
expect(presented.protest.protestingDriverId.toString()).toBe('driver1');
expect(presented.protest.accusedDriverId.toString()).toBe('driver2');
expect(presented.protest.incident.lap.toNumber()).toBe(5);
expect(presented.protest.incident.description.toString()).toBe('Collision');
expect(presented.protest.incident.timeInRace).toBeUndefined();
expect(presented.protest.comment).toBe('Test comment');
expect(presented.protest.proofVideoUrl).toBeDefined();
expect(presented.protest.proofVideoUrl!.toString()).toBe('http://example.com/video');
});
});
});