refactor use cases
This commit is contained in:
@@ -4,8 +4,9 @@ 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 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,
|
||||
@@ -15,13 +16,14 @@ describe('DashboardService', () => {
|
||||
|
||||
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,
|
||||
{ getResponseModel: vi.fn() } as any,
|
||||
{ present: vi.fn(), getResponseModel: vi.fn() } as any,
|
||||
);
|
||||
|
||||
await expect(service.getDashboardOverview('d1')).rejects.toThrow('Failed to get dashboard overview: boom');
|
||||
@@ -31,7 +33,7 @@ describe('DashboardService', () => {
|
||||
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,
|
||||
{ present: vi.fn(), getResponseModel: vi.fn() } as any,
|
||||
);
|
||||
|
||||
await expect(service.getDashboardOverview('d1')).rejects.toThrow('Failed to get dashboard overview: Unknown error');
|
||||
|
||||
Reference in New Issue
Block a user