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

@@ -5,7 +5,6 @@ import {
type GetLeagueRosterJoinRequestsResult,
type GetLeagueRosterJoinRequestsErrorCode,
} from './GetLeagueRosterJoinRequestsUseCase';
import type { UseCaseOutputPort } from '@core/shared/application';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import { Driver } from '../../domain/entities/Driver';
import type { ILeagueMembershipRepository } from '../../domain/repositories/ILeagueMembershipRepository';
@@ -27,8 +26,6 @@ describe('GetLeagueRosterJoinRequestsUseCase', () => {
exists: Mock;
};
let output: UseCaseOutputPort<GetLeagueRosterJoinRequestsResult> & { present: Mock };
beforeEach(() => {
leagueMembershipRepository = {
getJoinRequests: vi.fn(),
@@ -39,19 +36,15 @@ describe('GetLeagueRosterJoinRequestsUseCase', () => {
leagueRepository = {
exists: vi.fn(),
};
output = {
present: vi.fn(),
};
useCase = new GetLeagueRosterJoinRequestsUseCase(
leagueMembershipRepository as unknown as ILeagueMembershipRepository,
driverRepository as unknown as IDriverRepository,
leagueRepository as unknown as ILeagueRepository,
output,
);
});
it('presents only join requests with resolvable drivers', async () => {
it('returns join requests with resolvable drivers', async () => {
const leagueId = 'league-1';
const requestedAt = new Date('2025-01-02T03:04:05.000Z');
@@ -88,13 +81,10 @@ describe('GetLeagueRosterJoinRequestsUseCase', () => {
const result = await useCase.execute({ leagueId } as GetLeagueRosterJoinRequestsInput);
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 GetLeagueRosterJoinRequestsResult;
expect(presented.joinRequests).toHaveLength(1);
expect(presented.joinRequests[0]).toMatchObject({
expect(successResult.joinRequests).toHaveLength(1);
expect(successResult.joinRequests[0]).toMatchObject({
id: 'req-1',
leagueId,
driverId: 'driver-1',
@@ -118,7 +108,6 @@ describe('GetLeagueRosterJoinRequestsUseCase', () => {
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 () => {
@@ -135,6 +124,5 @@ describe('GetLeagueRosterJoinRequestsUseCase', () => {
expect(err.code).toBe('REPOSITORY_ERROR');
expect(err.details.message).toBe('Repository failure');
expect(output.present).not.toHaveBeenCalled();
});
});