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

@@ -0,0 +1,77 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { DriversPageQuery } from './DriversPageQuery';
import { DriversPageService } from '@/lib/services/drivers/DriversPageService';
import { Result } from '@/lib/contracts/Result';
import { DriversViewDataBuilder } from '@/lib/builders/view-data/DriversViewDataBuilder';
// Mock dependencies
vi.mock('@/lib/services/drivers/DriversPageService', () => ({
DriversPageService: vi.fn().mockImplementation(function (this: any) {
this.getLeaderboard = vi.fn();
}),
}));
vi.mock('@/lib/builders/view-data/DriversViewDataBuilder', () => ({
DriversViewDataBuilder: {
build: vi.fn(),
},
}));
describe('DriversPageQuery', () => {
let mockServiceInstance: any;
beforeEach(() => {
vi.clearAllMocks();
mockServiceInstance = {
getLeaderboard: vi.fn(),
};
(DriversPageService as any).mockImplementation(function (this: any) {
return mockServiceInstance;
});
});
describe('execute', () => {
it('should return view data when service succeeds', async () => {
const apiDto = { some: 'drivers-data' };
const viewData = { transformed: 'drivers-view' } as any;
mockServiceInstance.getLeaderboard.mockResolvedValue(Result.ok(apiDto));
(DriversViewDataBuilder.build as any).mockReturnValue(viewData);
const result = await DriversPageQuery.execute();
expect(result.isOk()).toBe(true);
expect(result.unwrap()).toEqual(viewData);
expect(DriversPageService).toHaveBeenCalled();
expect(mockServiceInstance.getLeaderboard).toHaveBeenCalled();
expect(DriversViewDataBuilder.build).toHaveBeenCalledWith(apiDto);
});
it('should return NotFound when service returns notFound error', async () => {
mockServiceInstance.getLeaderboard.mockResolvedValue(Result.err('notFound'));
const result = await DriversPageQuery.execute();
expect(result.isErr()).toBe(true);
expect(result.getError()).toBe('NotFound');
});
it('should return Error when service returns other error', async () => {
mockServiceInstance.getLeaderboard.mockResolvedValue(Result.err('some-other-error'));
const result = await DriversPageQuery.execute();
expect(result.isErr()).toBe(true);
expect(result.getError()).toBe('Error');
});
it('should return Error on exception', async () => {
mockServiceInstance.getLeaderboard.mockRejectedValue(new Error('Unexpected error'));
const result = await DriversPageQuery.execute();
expect(result.isErr()).toBe(true);
expect(result.getError()).toBe('Error');
});
});
});