refactor
This commit is contained in:
@@ -1,38 +1,47 @@
|
||||
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 };
|
||||
let mockLeagueRepo: ILeagueRepository;
|
||||
let mockFindById: Mock;
|
||||
|
||||
beforeEach(() => {
|
||||
mockLeagueRepo = { findById: vi.fn() };
|
||||
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 as unknown as ILeagueRepository,
|
||||
mockLeagueRepo,
|
||||
);
|
||||
|
||||
const params: GetLeagueAdminUseCaseParams = {
|
||||
const params = {
|
||||
leagueId: 'league1',
|
||||
};
|
||||
|
||||
it('should return error when league not found', async () => {
|
||||
mockLeagueRepo.findById.mockResolvedValue(null);
|
||||
mockFindById.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');
|
||||
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' };
|
||||
mockLeagueRepo.findById.mockResolvedValue(league);
|
||||
mockFindById.mockResolvedValue(league);
|
||||
|
||||
const useCase = createUseCase();
|
||||
const result = await useCase.execute(params);
|
||||
|
||||
Reference in New Issue
Block a user