Files
gridpilot.gg/core/racing/application/use-cases/GetLeagueAdminUseCase.test.ts
2025-12-16 21:05:01 +01:00

57 lines
1.5 KiB
TypeScript

import { describe, it, expect, beforeEach, vi, Mock } from 'vitest';
import { GetLeagueAdminUseCase } from './GetLeagueAdminUseCase';
import type { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
describe('GetLeagueAdminUseCase', () => {
let mockLeagueRepo: ILeagueRepository;
let mockFindById: Mock;
beforeEach(() => {
mockFindById = vi.fn();
mockLeagueRepo = {
findById: mockFindById,
findAll: vi.fn(),
create: vi.fn(),
update: vi.fn(),
delete: vi.fn(),
exists: vi.fn(),
findByOwnerId: vi.fn(),
searchByName: vi.fn(),
} as ILeagueRepository;
});
const createUseCase = () => new GetLeagueAdminUseCase(
mockLeagueRepo,
);
const params = {
leagueId: 'league1',
};
it('should return error when league not found', async () => {
mockFindById.mockResolvedValue(null);
const useCase = createUseCase();
const result = await useCase.execute(params);
expect(result.isErr()).toBe(true);
expect(result.unwrapErr().code).toBe('LEAGUE_NOT_FOUND');
expect(result.unwrapErr().details.message).toBe('League not found');
});
it('should return league data when league found', async () => {
const league = { id: 'league1', ownerId: 'owner1' };
mockFindById.mockResolvedValue(league);
const useCase = createUseCase();
const result = await useCase.execute(params);
expect(result.isOk()).toBe(true);
expect(result.value).toEqual({
league: {
id: 'league1',
ownerId: 'owner1',
},
});
});
});