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 presenter = { getResponseModel: vi.fn(() => ({ feed: [] })) }; const useCase = { execute: vi.fn(async () => Result.ok(undefined)) }; 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' }); }); 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, { 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, { getResponseModel: vi.fn() } as any, ); await expect(service.getDashboardOverview('d1')).rejects.toThrow('Failed to get dashboard overview: Unknown error'); }); });