refactor use cases
This commit is contained in:
@@ -2,11 +2,9 @@ import { describe, it, expect, vi, type Mock } from 'vitest';
|
||||
import { AwardPrizeUseCase, type AwardPrizeInput } from './AwardPrizeUseCase';
|
||||
import type { IPrizeRepository } from '../../domain/repositories/IPrizeRepository';
|
||||
import { PrizeType, type Prize } from '../../domain/entities/Prize';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
|
||||
describe('AwardPrizeUseCase', () => {
|
||||
let prizeRepository: { findById: Mock; update: Mock };
|
||||
let output: { present: Mock };
|
||||
let useCase: AwardPrizeUseCase;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -15,13 +13,8 @@ describe('AwardPrizeUseCase', () => {
|
||||
update: vi.fn(),
|
||||
};
|
||||
|
||||
output = {
|
||||
present: vi.fn(),
|
||||
};
|
||||
|
||||
useCase = new AwardPrizeUseCase(
|
||||
prizeRepository as unknown as IPrizeRepository,
|
||||
output as unknown as UseCaseOutputPort<unknown>,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -34,7 +27,6 @@ describe('AwardPrizeUseCase', () => {
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.unwrapErr().code).toBe('PRIZE_NOT_FOUND');
|
||||
expect(prizeRepository.update).not.toHaveBeenCalled();
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('returns PRIZE_ALREADY_AWARDED when prize is already awarded', async () => {
|
||||
@@ -59,10 +51,9 @@ describe('AwardPrizeUseCase', () => {
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.unwrapErr().code).toBe('PRIZE_ALREADY_AWARDED');
|
||||
expect(prizeRepository.update).not.toHaveBeenCalled();
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('awards prize and presents updated prize', async () => {
|
||||
it('awards prize and returns updated prize', async () => {
|
||||
const prize: Prize = {
|
||||
id: 'prize-1',
|
||||
leagueId: 'league-1',
|
||||
@@ -92,13 +83,14 @@ describe('AwardPrizeUseCase', () => {
|
||||
}),
|
||||
);
|
||||
|
||||
expect(output.present).toHaveBeenCalledWith({
|
||||
prize: expect.objectContaining({
|
||||
const value = result.value;
|
||||
expect(value.prize).toEqual(
|
||||
expect.objectContaining({
|
||||
id: 'prize-1',
|
||||
awarded: true,
|
||||
awardedTo: 'driver-1',
|
||||
awardedAt: expect.any(Date),
|
||||
}),
|
||||
});
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user