Files
gridpilot.gg/apps/api/src/domain/dashboard/DashboardService.test.ts
2026-01-08 15:34:51 +01:00

41 lines
2.1 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest';
import { Result } from '@core/shared/application/Result';
import { DashboardService } from './DashboardService';
describe('DashboardService', () => {
it('getDashboardOverview returns presenter model on success', async () => {
const mockResult = { currentDriver: null, myUpcomingRaces: [], otherUpcomingRaces: [], upcomingRaces: [], activeLeaguesCount: 0, nextRace: null, recentResults: [], leagueStandingsSummaries: [], feedSummary: { notificationCount: 0, items: [] }, friends: [] };
const presenter = { present: vi.fn(), getResponseModel: vi.fn(() => ({ feed: [] })) };
const useCase = { execute: vi.fn(async () => Result.ok(mockResult)) };
const service = new DashboardService(
{ debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() } as any,
useCase as any,
presenter as any,
);
await expect(service.getDashboardOverview('d1')).resolves.toEqual({ feed: [] });
expect(useCase.execute).toHaveBeenCalledWith({ driverId: 'd1' });
expect(presenter.present).toHaveBeenCalledWith(mockResult);
});
it('getDashboardOverview throws with details message on error', async () => {
const service = new DashboardService(
{ debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() } as any,
{ execute: vi.fn(async () => Result.err({ code: 'REPOSITORY_ERROR', details: { message: 'boom' } })) } as any,
{ present: vi.fn(), getResponseModel: vi.fn() } as any,
);
await expect(service.getDashboardOverview('d1')).rejects.toThrow('Failed to get dashboard overview: boom');
});
it('getDashboardOverview throws with fallback message when no details.message', async () => {
const service = new DashboardService(
{ debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() } as any,
{ execute: vi.fn(async () => Result.err({ code: 'REPOSITORY_ERROR' } as any)) } as any,
{ present: vi.fn(), getResponseModel: vi.fn() } as any,
);
await expect(service.getDashboardOverview('d1')).rejects.toThrow('Failed to get dashboard overview: Unknown error');
});
});