refactor use cases

This commit is contained in:
2026-01-08 15:34:51 +01:00
parent d984ab24a8
commit 52e9a2f6a7
362 changed files with 5192 additions and 8409 deletions

View File

@@ -2,7 +2,6 @@ import { describe, it, expect, vi, type Mock } from 'vitest';
import { ProcessWalletTransactionUseCase, type ProcessWalletTransactionInput } from './ProcessWalletTransactionUseCase';
import type { IWalletRepository, ITransactionRepository } from '../../domain/repositories/IWalletRepository';
import { TransactionType, ReferenceType } from '../../domain/entities/Wallet';
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
describe('ProcessWalletTransactionUseCase', () => {
let walletRepository: {
@@ -13,9 +12,6 @@ describe('ProcessWalletTransactionUseCase', () => {
let transactionRepository: {
create: Mock;
};
let output: {
present: Mock;
};
let useCase: ProcessWalletTransactionUseCase;
beforeEach(() => {
@@ -29,18 +25,13 @@ describe('ProcessWalletTransactionUseCase', () => {
create: vi.fn(),
};
output = {
present: vi.fn(),
};
useCase = new ProcessWalletTransactionUseCase(
walletRepository as unknown as IWalletRepository,
transactionRepository as unknown as ITransactionRepository,
output as unknown as UseCaseOutputPort<unknown>,
);
});
it('processes a deposit transaction and presents the result', async () => {
it('processes a deposit transaction and returns the result', async () => {
const input: ProcessWalletTransactionInput = {
leagueId: 'league-1',
type: TransactionType.DEPOSIT,
@@ -79,10 +70,9 @@ describe('ProcessWalletTransactionUseCase', () => {
const result = await useCase.execute(input);
expect(result.isOk()).toBe(true);
expect(output.present).toHaveBeenCalledWith({
wallet: { ...wallet, balance: 150, totalRevenue: 150 },
transaction,
});
const value = result.value;
expect(value.wallet).toEqual({ ...wallet, balance: 150, totalRevenue: 150 });
expect(value.transaction).toEqual(transaction);
});
it('returns error for insufficient balance on withdrawal', async () => {