website service tests
This commit is contained in:
60
apps/website/lib/services/dashboard/DashboardService.test.ts
Normal file
60
apps/website/lib/services/dashboard/DashboardService.test.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { describe, it, expect, vi, Mocked } from 'vitest';
|
||||
import { DashboardService } from './DashboardService';
|
||||
import { DashboardApiClient } from '../../api/dashboard/DashboardApiClient';
|
||||
import { DashboardOverviewViewModel } from '../../view-models/DashboardOverviewViewModel';
|
||||
|
||||
describe('DashboardService', () => {
|
||||
let mockApiClient: Mocked<DashboardApiClient>;
|
||||
let service: DashboardService;
|
||||
|
||||
beforeEach(() => {
|
||||
mockApiClient = {
|
||||
getDashboardOverview: vi.fn(),
|
||||
} as Mocked<DashboardApiClient>;
|
||||
|
||||
service = new DashboardService(mockApiClient);
|
||||
});
|
||||
|
||||
describe('getDashboardOverview', () => {
|
||||
it('should call apiClient.getDashboardOverview and return DashboardOverviewViewModel', async () => {
|
||||
const mockDto = {
|
||||
currentDriver: {
|
||||
id: 'driver-123',
|
||||
name: 'Test Driver',
|
||||
avatarUrl: 'https://example.com/avatar.jpg',
|
||||
country: 'US',
|
||||
totalRaces: 42,
|
||||
wins: 10,
|
||||
podiums: 20,
|
||||
rating: 1500,
|
||||
globalRank: 5,
|
||||
consistency: 85,
|
||||
},
|
||||
myUpcomingRaces: [],
|
||||
otherUpcomingRaces: [],
|
||||
upcomingRaces: [],
|
||||
activeLeaguesCount: 3,
|
||||
nextRace: null,
|
||||
recentResults: [],
|
||||
leagueStandingsSummaries: [],
|
||||
feedSummary: { feedItems: [] },
|
||||
friends: [],
|
||||
};
|
||||
|
||||
mockApiClient.getDashboardOverview.mockResolvedValue(mockDto);
|
||||
|
||||
const result = await service.getDashboardOverview();
|
||||
|
||||
expect(mockApiClient.getDashboardOverview).toHaveBeenCalled();
|
||||
expect(result).toBeInstanceOf(DashboardOverviewViewModel);
|
||||
expect(result.activeLeaguesCount).toBe(3);
|
||||
});
|
||||
|
||||
it('should throw error when apiClient.getDashboardOverview fails', async () => {
|
||||
const error = new Error('API call failed');
|
||||
mockApiClient.getDashboardOverview.mockRejectedValue(error);
|
||||
|
||||
await expect(service.getDashboardOverview()).rejects.toThrow('API call failed');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user