move static data

This commit is contained in:
2025-12-26 00:20:53 +01:00
parent c977defd6a
commit b6cbb81388
63 changed files with 1482 additions and 418 deletions

View File

@@ -9,8 +9,9 @@ describe('PenaltyService', () => {
beforeEach(() => {
mockApiClient = {
getRacePenalties: vi.fn(),
getPenaltyTypesReference: vi.fn(),
applyPenalty: vi.fn(),
} as Mocked<PenaltiesApiClient>;
} as unknown as Mocked<PenaltiesApiClient>;
service = new PenaltyService(mockApiClient);
});
@@ -23,9 +24,10 @@ describe('PenaltyService', () => {
{ id: 'penalty-1', driverId: 'driver-1', type: 'time', value: 5, reason: 'Incident' },
{ id: 'penalty-2', driverId: 'driver-2', type: 'grid', value: 3, reason: 'Qualifying incident' },
],
driverMap: {},
};
mockApiClient.getRacePenalties.mockResolvedValue(mockDto);
mockApiClient.getRacePenalties.mockResolvedValue(mockDto as any);
const result = await service.findByRaceId(raceId);
@@ -36,9 +38,9 @@ describe('PenaltyService', () => {
it('should handle empty penalties array', async () => {
const raceId = 'race-123';
const mockDto = { penalties: [] };
const mockDto = { penalties: [], driverMap: {} };
mockApiClient.getRacePenalties.mockResolvedValue(mockDto);
mockApiClient.getRacePenalties.mockResolvedValue(mockDto as any);
const result = await service.findByRaceId(raceId);

View File

@@ -1,4 +1,5 @@
import { PenaltiesApiClient } from '../../api/penalties/PenaltiesApiClient';
import type { PenaltyTypesReferenceDTO } from '../../types/PenaltyTypesReferenceDTO';
/**
* Penalty Service
@@ -19,6 +20,13 @@ export class PenaltyService {
return dto.penalties;
}
/**
* Get allowed penalty types and semantics
*/
async getPenaltyTypesReference(): Promise<PenaltyTypesReferenceDTO> {
return this.apiClient.getPenaltyTypesReference();
}
/**
* Apply a penalty
*/

View File

@@ -19,17 +19,22 @@ describe('TeamJoinService', () => {
const mockDto = {
requests: [
{
id: 'request-1',
requestId: 'request-1',
teamId: 'team-1',
driverId: 'driver-1',
driverName: 'Driver One',
status: 'pending',
requestedAt: '2023-01-01T00:00:00Z',
message: 'Please accept me',
avatarUrl: 'https://example.com/avatar-1.jpg',
},
{
id: 'request-2',
requestId: 'request-2',
teamId: 'team-1',
driverId: 'driver-2',
driverName: 'Driver Two',
status: 'pending',
requestedAt: '2023-01-02T00:00:00Z',
avatarUrl: 'https://example.com/avatar-2.jpg',
},
],
};
@@ -40,20 +45,30 @@ describe('TeamJoinService', () => {
expect(mockApiClient.getJoinRequests).toHaveBeenCalledWith('team-1');
expect(result).toHaveLength(2);
expect(result[0].id).toBe('request-1');
expect(result[0].canApprove).toBe(true);
expect(result[1].id).toBe('request-2');
expect(result[1].canApprove).toBe(true);
const first = result[0];
const second = result[1];
expect(first).toBeDefined();
expect(second).toBeDefined();
expect(first!.id).toBe('request-1');
expect(first!.canApprove).toBe(true);
expect(second!.id).toBe('request-2');
expect(second!.canApprove).toBe(true);
});
it('should pass correct parameters to view model constructor', async () => {
const mockDto = {
requests: [
{
id: 'request-1',
requestId: 'request-1',
teamId: 'team-1',
driverId: 'driver-1',
driverName: 'Driver One',
status: 'pending',
requestedAt: '2023-01-01T00:00:00Z',
avatarUrl: 'https://example.com/avatar-1.jpg',
},
],
};
@@ -62,7 +77,8 @@ describe('TeamJoinService', () => {
const result = await service.getJoinRequests('team-1', 'user-1', false);
expect(result[0].canApprove).toBe(false);
expect(result[0]).toBeDefined();
expect(result[0]!.canApprove).toBe(false);
});
});

View File

@@ -34,7 +34,7 @@ export class TeamJoinService {
* a request requires a future management endpoint, so this method fails explicitly.
*/
async approveJoinRequest(): Promise<never> {
throw new Error('Approving team join requests is not supported in this build');
throw new Error('Not implemented: API endpoint for approving join requests');
}
/**
@@ -44,6 +44,6 @@ export class TeamJoinService {
* must treat this as an unsupported operation rather than a silent no-op.
*/
async rejectJoinRequest(): Promise<never> {
throw new Error('Rejecting team join requests is not supported in this build');
throw new Error('Not implemented: API endpoint for rejecting join requests');
}
}