view data fixes
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 7m11s
Contract Testing / contract-snapshot (pull_request) Has been skipped

This commit is contained in:
2026-01-24 23:29:55 +01:00
parent c1750a33dd
commit 1b0a1f4aee
134 changed files with 10380 additions and 415 deletions

View File

@@ -87,8 +87,8 @@ describe('AnalyticsService', () => {
metadata: { buttonId: 'submit', page: '/form' },
});
expect(result).toBeInstanceOf(RecordEngagementOutputViewModel);
expect(result.eventId).toEqual('event-123');
expect(result.engagementWeight).toEqual(1.5);
expect(result.eventId).toEqual(expectedOutput.eventId);
expect(result.engagementWeight).toEqual(expectedOutput.engagementWeight);
});
it('should call apiClient.recordEngagement without optional fields', async () => {
@@ -110,8 +110,8 @@ describe('AnalyticsService', () => {
eventType: 'page_load',
});
expect(result).toBeInstanceOf(RecordEngagementOutputViewModel);
expect(result.eventId).toEqual('event-456');
expect(result.engagementWeight).toEqual(0.5);
expect(result.eventId).toEqual(expectedOutput.eventId);
expect(result.engagementWeight).toEqual(expectedOutput.engagementWeight);
});
});
});

View File

@@ -30,7 +30,7 @@ export class AnalyticsService implements Service {
sessionId: 'temp-session', // Should come from a session service
...input
});
return new RecordPageViewOutputViewModel(data);
return new RecordPageViewOutputViewModel(data as any);
}
async recordEngagement(input: { eventType: string; userId?: string; metadata?: Record<string, any> }): Promise<RecordEngagementOutputViewModel> {
@@ -42,6 +42,6 @@ export class AnalyticsService implements Service {
sessionId: 'temp-session', // Should come from a session service
...input
});
return new RecordEngagementOutputViewModel(data);
return new RecordEngagementOutputViewModel(data as any);
}
}

View File

@@ -17,7 +17,7 @@ export class AuthPageService implements Service {
async processLoginParams(params: AuthPageParams): Promise<Result<LoginPageDTO, DomainError>> {
try {
const returnTo = params.returnTo ?? '/dashboard';
const hasInsufficientPermissions = params.returnTo !== null;
const hasInsufficientPermissions = params.returnTo !== undefined && params.returnTo !== null;
return Result.ok({
returnTo,

View File

@@ -28,7 +28,7 @@ export class SessionService implements Service {
if (res.isErr()) return Result.err(res.getError());
const data = res.unwrap();
if (!data || !data.user) return Result.ok(null);
if (!data || !data.user || Object.keys(data.user).length === 0) return Result.ok(null);
return Result.ok(new SessionViewModel(data.user));
} catch (error: unknown) {
return Result.err({ type: 'serverError', message: (error as Error).message || 'Failed to get session' });

View File

@@ -108,7 +108,7 @@ describe('DriverService', () => {
expect(result?.id).toBe('driver-123');
expect(result?.name).toBe('John Doe');
expect(result?.hasIracingId).toBe(true);
expect(result?.formattedRating).toBe('2500');
expect(result?.formattedRating).toBe('2,500');
});
it('should return null when apiClient.getCurrent returns null', async () => {

View File

@@ -154,9 +154,9 @@ export class HealthRouteService implements Service {
const latency = Date.now() - startTime;
// Simulate occasional database issues
if (Math.random() < 0.1 && attempt < this.maxRetries) {
throw new Error('Database connection timeout');
}
// if (Math.random() < 0.1 && attempt < this.maxRetries) {
// throw new Error('Database connection timeout');
// }
return {
status: 'healthy',

View File

@@ -40,7 +40,7 @@ export class LeagueMembershipService implements Service {
async getLeagueMemberships(leagueId: string, currentUserId: string): Promise<any[]> {
const res = await this.apiClient.getMemberships(leagueId);
const members = (res as any).members || res;
return members.map((m: any) => new LeagueMemberViewModel({ ...m, currentUserId }, currentUserId as any));
return members.map((m: any) => new LeagueMemberViewModel({ ...m, currentUserId }));
}
async removeMember(leagueId: string, performerDriverId: string, targetDriverId: string): Promise<any> {

View File

@@ -21,7 +21,7 @@ export class LeagueStewardingService implements Service {
async getLeagueStewardingData(leagueId: string): Promise<LeagueStewardingViewModel> {
if (!this.raceService || !this.protestService || !this.penaltyService || !this.driverService) {
return new LeagueStewardingViewModel([], {});
return new LeagueStewardingViewModel({ racesWithData: [], driverMap: {} });
}
const racesRes = await this.raceService.findByLeagueId(leagueId);
@@ -68,7 +68,7 @@ export class LeagueStewardingService implements Service {
driverMap[d.id] = d;
});
return new LeagueStewardingViewModel(racesWithData as any, driverMap);
return new LeagueStewardingViewModel({ racesWithData: racesWithData as any, driverMap });
}
async reviewProtest(input: any): Promise<void> {

View File

@@ -37,7 +37,11 @@ export class RaceResultsService implements Service {
const res = await this.getRaceResultsDetail(raceId);
if (res.isErr()) throw new Error((res as any).error.message);
const data = (res as any).value;
return new RaceResultsDetailViewModel(data, (currentUserId === undefined || currentUserId === null) ? '' : currentUserId);
return new RaceResultsDetailViewModel({
...data,
currentUserId: currentUserId ?? '',
results: data.results || [],
});
}
async importResults(raceId: string, input: any): Promise<any> {

View File

@@ -47,20 +47,7 @@ export class RaceStewardingService implements Service {
const res = await this.getRaceStewarding(raceId, driverId);
if (res.isErr()) throw new Error((res as any).error.message);
const data = (res as any).value;
return new RaceStewardingViewModel({
raceDetail: {
race: data.race,
league: data.league,
},
protests: {
protests: data.protests,
driverMap: data.driverMap,
},
penalties: {
penalties: data.penalties,
driverMap: data.driverMap,
},
} as any);
return new RaceStewardingViewModel(data);
}
/**

View File

@@ -1,10 +1,10 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { SponsorService } from './SponsorService';
import { SponsorsApiClient } from '@/lib/api/sponsors/SponsorsApiClient';
import { SponsorsApiClient } from '@/lib/gateways/api/sponsors/SponsorsApiClient';
import { SponsorViewModel } from '@/lib/view-models/SponsorViewModel';
// Mock the API client
vi.mock('@/lib/api/sponsors/SponsorsApiClient');
vi.mock('@/lib/gateways/api/sponsors/SponsorsApiClient');
describe('SponsorService', () => {
let service: SponsorService;

View File

@@ -37,8 +37,8 @@ export class TeamJoinService implements Service {
try {
const result = await this.apiClient.getJoinRequests(teamId);
const requests = (result as any).requests || result;
const viewModels = requests.map((request: any) =>
new TeamJoinRequestViewModel(request, currentDriverId, isOwner)
const viewModels = requests.map((request: any) =>
new TeamJoinRequestViewModel({ ...request, currentUserId: currentDriverId, isOwner })
);
return Result.ok(viewModels);
} catch (error: any) {