refactor use cases
This commit is contained in:
@@ -2,14 +2,12 @@ import { describe, it, expect, vi, type Mock } from 'vitest';
|
||||
import { GetPrizesUseCase, type GetPrizesInput } from './GetPrizesUseCase';
|
||||
import type { IPrizeRepository } from '../../domain/repositories/IPrizeRepository';
|
||||
import { PrizeType, type Prize } from '../../domain/entities/Prize';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
|
||||
describe('GetPrizesUseCase', () => {
|
||||
let prizeRepository: {
|
||||
findByLeagueId: Mock;
|
||||
findByLeagueIdAndSeasonId: Mock;
|
||||
};
|
||||
let output: { present: Mock };
|
||||
let useCase: GetPrizesUseCase;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -18,13 +16,8 @@ describe('GetPrizesUseCase', () => {
|
||||
findByLeagueIdAndSeasonId: vi.fn(),
|
||||
};
|
||||
|
||||
output = {
|
||||
present: vi.fn(),
|
||||
};
|
||||
|
||||
useCase = new GetPrizesUseCase(
|
||||
prizeRepository as unknown as IPrizeRepository,
|
||||
output as unknown as UseCaseOutputPort<unknown>,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -62,10 +55,9 @@ describe('GetPrizesUseCase', () => {
|
||||
expect(prizeRepository.findByLeagueId).toHaveBeenCalledWith('league-1');
|
||||
expect(prizeRepository.findByLeagueIdAndSeasonId).not.toHaveBeenCalled();
|
||||
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
const presented = (output.present as unknown as Mock).mock.calls[0]![0]!.prizes as Prize[];
|
||||
expect(presented.map(p => p.position)).toEqual([1, 2]);
|
||||
expect(presented.map(p => p.id)).toEqual(['p1', 'p2']);
|
||||
const value = result.value;
|
||||
expect(value.prizes.map(p => p.position)).toEqual([1, 2]);
|
||||
expect(value.prizes.map(p => p.id)).toEqual(['p1', 'p2']);
|
||||
});
|
||||
|
||||
it('retrieves and sorts prizes by leagueId and seasonId when provided', async () => {
|
||||
@@ -102,9 +94,8 @@ describe('GetPrizesUseCase', () => {
|
||||
expect(prizeRepository.findByLeagueIdAndSeasonId).toHaveBeenCalledWith('league-1', 'season-1');
|
||||
expect(prizeRepository.findByLeagueId).not.toHaveBeenCalled();
|
||||
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
const presented = (output.present as unknown as Mock).mock.calls[0]![0]!.prizes as Prize[];
|
||||
expect(presented.map(p => p.position)).toEqual([1, 3]);
|
||||
expect(presented.map(p => p.id)).toEqual(['p1', 'p3']);
|
||||
const value = result.value;
|
||||
expect(value.prizes.map(p => p.position)).toEqual([1, 3]);
|
||||
expect(value.prizes.map(p => p.id)).toEqual(['p1', 'p3']);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user