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,104 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { LeagueProtestReviewPageQuery } from './LeagueProtestReviewPageQuery';
import { Result } from '@/lib/contracts/Result';
import { LeaguesApiClient } from '@/lib/gateways/api/leagues/LeaguesApiClient';
import { ProtestsApiClient } from '@/lib/gateways/api/protests/ProtestsApiClient';
import { ConsoleErrorReporter } from '@/lib/infrastructure/logging/ConsoleErrorReporter';
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
// Mock dependencies
vi.mock('@/lib/gateways/api/leagues/LeaguesApiClient', () => ({
LeaguesApiClient: vi.fn().mockImplementation(function (this: any) { return this; }),
}));
vi.mock('@/lib/gateways/api/protests/ProtestsApiClient', () => ({
ProtestsApiClient: vi.fn().mockImplementation(function (this: any) { return this; }),
}));
vi.mock('@/lib/infrastructure/logging/ConsoleErrorReporter', () => ({
ConsoleErrorReporter: vi.fn().mockImplementation(function (this: any) { return this; }),
}));
vi.mock('@/lib/infrastructure/logging/ConsoleLogger', () => ({
ConsoleLogger: vi.fn().mockImplementation(function (this: any) { return this; }),
}));
describe('LeagueProtestReviewPageQuery', () => {
let query: LeagueProtestReviewPageQuery;
beforeEach(() => {
vi.clearAllMocks();
query = new LeagueProtestReviewPageQuery();
});
it('should return placeholder data when execution succeeds', async () => {
const input = { leagueId: 'league-123', protestId: 'protest-456' };
const result = await query.execute(input);
expect(result.isOk()).toBe(true);
const data = result.unwrap() as any;
expect(data.protest.id).toBe('protest-456');
expect(LeaguesApiClient).toHaveBeenCalled();
expect(ProtestsApiClient).toHaveBeenCalled();
expect(ConsoleErrorReporter).toHaveBeenCalled();
expect(ConsoleLogger).toHaveBeenCalled();
});
it('should return redirect error on 403/401 errors', async () => {
const input = { leagueId: 'league-123', protestId: 'protest-456' };
(LeaguesApiClient as any).mockImplementationOnce(function () {
throw new Error('403 Forbidden');
});
const result = await query.execute(input);
expect(result.isErr()).toBe(true);
expect(result.getError()).toBe('redirect');
});
it('should return notFound error on 404 errors', async () => {
const input = { leagueId: 'league-123', protestId: 'protest-456' };
(LeaguesApiClient as any).mockImplementationOnce(function () {
throw new Error('404 Not Found');
});
const result = await query.execute(input);
expect(result.isErr()).toBe(true);
expect(result.getError()).toBe('notFound');
});
it('should return PROTEST_FETCH_FAILED on server errors', async () => {
const input = { leagueId: 'league-123', protestId: 'protest-456' };
(LeaguesApiClient as any).mockImplementationOnce(function () {
throw new Error('500 Internal Server Error');
});
const result = await query.execute(input);
expect(result.isErr()).toBe(true);
expect(result.getError()).toBe('PROTEST_FETCH_FAILED');
});
it('should return UNKNOWN_ERROR on other errors', async () => {
const input = { leagueId: 'league-123', protestId: 'protest-456' };
(LeaguesApiClient as any).mockImplementationOnce(function () {
throw new Error('Some random error');
});
const result = await query.execute(input);
expect(result.isErr()).toBe(true);
expect(result.getError()).toBe('UNKNOWN_ERROR');
});
it('should provide a static execute method', async () => {
const input = { leagueId: 'league-123', protestId: 'protest-456' };
const result = await LeagueProtestReviewPageQuery.execute(input);
expect(result.isOk()).toBe(true);
expect((result.unwrap() as any).protest.id).toBe('protest-456');
});
});