import { describe, it, expect, beforeEach, vi, Mock } from 'vitest'; import { GetLeagueAdminUseCase } from './GetLeagueAdminUseCase'; import type { ILeagueRepository } from '../../domain/repositories/ILeagueRepository'; import type { GetLeagueAdminUseCaseParams } from './GetLeagueAdminUseCaseParams'; import { RacingDomainValidationError } from '../../domain/errors/RacingDomainError'; describe('GetLeagueAdminUseCase', () => { let mockLeagueRepo: { findById: Mock }; beforeEach(() => { mockLeagueRepo = { findById: vi.fn() }; }); const createUseCase = () => new GetLeagueAdminUseCase( mockLeagueRepo as unknown as ILeagueRepository, ); const params: GetLeagueAdminUseCaseParams = { leagueId: 'league1', }; it('should return error when league not found', async () => { mockLeagueRepo.findById.mockResolvedValue(null); const useCase = createUseCase(); const result = await useCase.execute(params); expect(result.isErr()).toBe(true); expect(result.unwrapErr()).toBeInstanceOf(RacingDomainValidationError); expect(result.unwrapErr().message).toBe('League not found'); }); it('should return league data when league found', async () => { const league = { id: 'league1', ownerId: 'owner1' }; mockLeagueRepo.findById.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', }, }); }); });