refactor use cases
This commit is contained in:
@@ -5,7 +5,6 @@ import {
|
||||
type GetLeagueRosterMembersResult,
|
||||
type GetLeagueRosterMembersErrorCode,
|
||||
} from './GetLeagueRosterMembersUseCase';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import { LeagueMembership } from '../../domain/entities/LeagueMembership';
|
||||
import { Driver } from '../../domain/entities/Driver';
|
||||
@@ -28,8 +27,6 @@ describe('GetLeagueRosterMembersUseCase', () => {
|
||||
exists: Mock;
|
||||
};
|
||||
|
||||
let output: UseCaseOutputPort<GetLeagueRosterMembersResult> & { present: Mock };
|
||||
|
||||
beforeEach(() => {
|
||||
leagueMembershipRepository = {
|
||||
getLeagueMembers: vi.fn(),
|
||||
@@ -40,19 +37,15 @@ describe('GetLeagueRosterMembersUseCase', () => {
|
||||
leagueRepository = {
|
||||
exists: vi.fn(),
|
||||
};
|
||||
output = {
|
||||
present: vi.fn(),
|
||||
};
|
||||
|
||||
useCase = new GetLeagueRosterMembersUseCase(
|
||||
leagueMembershipRepository as unknown as ILeagueMembershipRepository,
|
||||
driverRepository as unknown as IDriverRepository,
|
||||
leagueRepository as unknown as ILeagueRepository,
|
||||
output,
|
||||
);
|
||||
});
|
||||
|
||||
it('presents only members with resolvable drivers', async () => {
|
||||
it('returns members with resolvable drivers', async () => {
|
||||
const leagueId = 'league-1';
|
||||
|
||||
const memberships = [
|
||||
@@ -89,14 +82,11 @@ describe('GetLeagueRosterMembersUseCase', () => {
|
||||
const result = await useCase.execute({ leagueId } as GetLeagueRosterMembersInput);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
const successResult = result.unwrap();
|
||||
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
const presented = output.present.mock.calls[0]?.[0] as GetLeagueRosterMembersResult;
|
||||
|
||||
expect(presented.members).toHaveLength(1);
|
||||
expect(presented.members[0]?.membership).toEqual(memberships[0]);
|
||||
expect(presented.members[0]?.driver).toEqual(driver1);
|
||||
expect(successResult.members).toHaveLength(1);
|
||||
expect(successResult.members[0]?.membership).toEqual(memberships[0]);
|
||||
expect(successResult.members[0]?.driver).toEqual(driver1);
|
||||
});
|
||||
|
||||
it('returns LEAGUE_NOT_FOUND when league does not exist', async () => {
|
||||
@@ -113,7 +103,6 @@ describe('GetLeagueRosterMembersUseCase', () => {
|
||||
|
||||
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 () => {
|
||||
@@ -130,6 +119,5 @@ describe('GetLeagueRosterMembersUseCase', () => {
|
||||
|
||||
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