refactor use cases
This commit is contained in:
@@ -3,7 +3,6 @@ import { GetWalletUseCase, type GetWalletInput } from './GetWalletUseCase';
|
||||
import type { ITransactionRepository, IWalletRepository } from '../../domain/repositories/IWalletRepository';
|
||||
import type { Transaction, Wallet } from '../../domain/entities/Wallet';
|
||||
import { TransactionType } from '../../domain/entities/Wallet';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
|
||||
describe('GetWalletUseCase', () => {
|
||||
let walletRepository: {
|
||||
@@ -15,10 +14,6 @@ describe('GetWalletUseCase', () => {
|
||||
findByWalletId: Mock;
|
||||
};
|
||||
|
||||
let output: {
|
||||
present: Mock;
|
||||
};
|
||||
|
||||
let useCase: GetWalletUseCase;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -31,14 +26,9 @@ describe('GetWalletUseCase', () => {
|
||||
findByWalletId: vi.fn(),
|
||||
};
|
||||
|
||||
output = {
|
||||
present: vi.fn(),
|
||||
};
|
||||
|
||||
useCase = new GetWalletUseCase(
|
||||
walletRepository as unknown as IWalletRepository,
|
||||
transactionRepository as unknown as ITransactionRepository,
|
||||
output as unknown as UseCaseOutputPort<unknown>,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -49,10 +39,9 @@ describe('GetWalletUseCase', () => {
|
||||
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.unwrapErr().code).toBe('INVALID_INPUT');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('presents existing wallet and transactions sorted desc by createdAt', async () => {
|
||||
it('returns wallet and transactions sorted desc by createdAt', async () => {
|
||||
const input: GetWalletInput = { leagueId: 'league-1' };
|
||||
|
||||
const wallet: Wallet = {
|
||||
@@ -90,14 +79,15 @@ describe('GetWalletUseCase', () => {
|
||||
const result = await useCase.execute(input);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(transactionRepository.findByWalletId).toHaveBeenCalledWith('wallet-1');
|
||||
expect(output.present).toHaveBeenCalledWith({
|
||||
const value = result.value;
|
||||
expect(value).toEqual({
|
||||
wallet,
|
||||
transactions: [newer, older],
|
||||
});
|
||||
expect(transactionRepository.findByWalletId).toHaveBeenCalledWith('wallet-1');
|
||||
});
|
||||
|
||||
it('creates wallet when missing, then presents wallet and transactions', async () => {
|
||||
it('creates wallet when missing, then returns wallet and transactions', async () => {
|
||||
const input: GetWalletInput = { leagueId: 'league-1' };
|
||||
|
||||
vi.useFakeTimers();
|
||||
@@ -131,7 +121,8 @@ describe('GetWalletUseCase', () => {
|
||||
const createdWalletArg = walletRepository.create.mock.calls[0]?.[0] as Wallet;
|
||||
expect(transactionRepository.findByWalletId).toHaveBeenCalledWith(createdWalletArg.id);
|
||||
|
||||
expect(output.present).toHaveBeenCalledWith({
|
||||
const value = result.value;
|
||||
expect(value).toEqual({
|
||||
wallet: createdWalletArg,
|
||||
transactions: [],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user