refactor use cases
This commit is contained in:
@@ -13,7 +13,6 @@ import { Money } from '../../domain/value-objects/Money';
|
||||
import { Transaction } from '../../domain/entities/league-wallet/Transaction';
|
||||
import { TransactionId } from '../../domain/entities/league-wallet/TransactionId';
|
||||
import { LeagueWalletId } from '../../domain/entities/league-wallet/LeagueWalletId';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
describe('GetLeagueWalletUseCase', () => {
|
||||
@@ -26,7 +25,6 @@ describe('GetLeagueWalletUseCase', () => {
|
||||
let transactionRepository: {
|
||||
findByWalletId: Mock;
|
||||
};
|
||||
let output: UseCaseOutputPort<GetLeagueWalletResult> & { present: Mock };
|
||||
let useCase: GetLeagueWalletUseCase;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -42,16 +40,9 @@ describe('GetLeagueWalletUseCase', () => {
|
||||
findByWalletId: vi.fn(),
|
||||
};
|
||||
|
||||
output = {
|
||||
present: vi.fn(),
|
||||
} as unknown as UseCaseOutputPort<GetLeagueWalletResult> & { present: Mock };
|
||||
|
||||
useCase = new GetLeagueWalletUseCase(
|
||||
leagueRepository as unknown as ILeagueRepository,
|
||||
useCase = new GetLeagueWalletUseCase(leagueRepository as unknown as ILeagueRepository,
|
||||
leagueWalletRepository as unknown as ILeagueWalletRepository,
|
||||
transactionRepository as unknown as ITransactionRepository,
|
||||
output,
|
||||
);
|
||||
transactionRepository as unknown as ITransactionRepository);
|
||||
});
|
||||
|
||||
it('returns mapped wallet data when wallet exists', async () => {
|
||||
@@ -133,11 +124,7 @@ describe('GetLeagueWalletUseCase', () => {
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
|
||||
const presented = (output.present as Mock).mock.calls[0]![0] as GetLeagueWalletResult;
|
||||
|
||||
expect(presented.wallet).toBe(wallet);
|
||||
const presented = (expect(presented.wallet).toBe(wallet);
|
||||
expect(presented.transactions).toHaveLength(transactions.length);
|
||||
expect(presented.transactions[0]!.id).toEqual(
|
||||
transactions.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime())[0]!
|
||||
@@ -184,8 +171,7 @@ describe('GetLeagueWalletUseCase', () => {
|
||||
|
||||
expect(err.code).toBe('WALLET_NOT_FOUND');
|
||||
expect(err.details.message).toBe('League wallet not found');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('returns league not found when league does not exist', async () => {
|
||||
const leagueId = 'league-missing';
|
||||
@@ -204,8 +190,7 @@ describe('GetLeagueWalletUseCase', () => {
|
||||
|
||||
expect(err.code).toBe('LEAGUE_NOT_FOUND');
|
||||
expect(err.details.message).toBe('League not found');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('returns repository error when repository throws', async () => {
|
||||
const leagueId = 'league-1';
|
||||
@@ -224,6 +209,5 @@ describe('GetLeagueWalletUseCase', () => {
|
||||
|
||||
expect(err.code).toBe('REPOSITORY_ERROR');
|
||||
expect(err.details.message).toBe('DB error');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user