refactor use cases
This commit is contained in:
@@ -9,7 +9,6 @@ import { ILeagueMembershipRepository } from '../../domain/repositories/ILeagueMe
|
||||
import { IDriverRepository } from '../../domain/repositories/IDriverRepository';
|
||||
import { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
|
||||
import { Driver } from '../../domain/entities/Driver';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
describe('GetLeagueJoinRequestsUseCase', () => {
|
||||
@@ -23,7 +22,6 @@ describe('GetLeagueJoinRequestsUseCase', () => {
|
||||
let leagueRepository: {
|
||||
exists: Mock;
|
||||
};
|
||||
let output: UseCaseOutputPort<GetLeagueJoinRequestsResult> & { present: Mock };
|
||||
|
||||
beforeEach(() => {
|
||||
leagueMembershipRepository = {
|
||||
@@ -35,15 +33,11 @@ describe('GetLeagueJoinRequestsUseCase', () => {
|
||||
leagueRepository = {
|
||||
exists: vi.fn(),
|
||||
};
|
||||
output = {
|
||||
present: vi.fn(),
|
||||
};
|
||||
|
||||
useCase = new GetLeagueJoinRequestsUseCase(
|
||||
leagueMembershipRepository as unknown as ILeagueMembershipRepository,
|
||||
driverRepository as unknown as IDriverRepository,
|
||||
leagueRepository as unknown as ILeagueRepository,
|
||||
output,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -75,19 +69,15 @@ describe('GetLeagueJoinRequestsUseCase', () => {
|
||||
const result = await useCase.execute(input);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
const presented = output.present.mock.calls[0]?.[0] as GetLeagueJoinRequestsResult;
|
||||
|
||||
expect(presented.joinRequests).toHaveLength(1);
|
||||
expect(presented.joinRequests[0]).toMatchObject({
|
||||
const successResult = result.unwrap();
|
||||
expect(successResult.joinRequests).toHaveLength(1);
|
||||
expect(successResult.joinRequests[0]).toMatchObject({
|
||||
id: 'req-1',
|
||||
leagueId,
|
||||
driverId: 'driver-1',
|
||||
message: 'msg',
|
||||
});
|
||||
expect(presented?.joinRequests[0]?.driver).toBe(driver);
|
||||
expect(successResult.joinRequests[0].driver).toBe(driver);
|
||||
});
|
||||
|
||||
it('should return LEAGUE_NOT_FOUND error when league does not exist', async () => {
|
||||
@@ -107,7 +97,6 @@ describe('GetLeagueJoinRequestsUseCase', () => {
|
||||
|
||||
expect(err.code).toBe('LEAGUE_NOT_FOUND');
|
||||
expect(err.details.message).toBe('League not found');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should return REPOSITORY_ERROR when repository throws', async () => {
|
||||
@@ -128,6 +117,5 @@ describe('GetLeagueJoinRequestsUseCase', () => {
|
||||
|
||||
expect(err.code).toBe('REPOSITORY_ERROR');
|
||||
expect(err.details.message).toBe('Repository failure');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user