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

@@ -10,7 +10,6 @@ import { IDriverRepository } from '../../domain/repositories/IDriverRepository';
import { ITeamRepository } from '../../domain/repositories/ITeamRepository';
import { Driver } from '../../domain/entities/Driver';
import { Team } from '../../domain/entities/Team';
import type { UseCaseOutputPort } from '@core/shared/application';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
describe('GetTeamJoinRequestsUseCase', () => {
@@ -24,8 +23,6 @@ describe('GetTeamJoinRequestsUseCase', () => {
let teamRepository: {
findById: Mock;
};
let output: UseCaseOutputPort<GetTeamJoinRequestsResult> & { present: Mock };
beforeEach(() => {
membershipRepository = {
getJoinRequests: vi.fn(),
@@ -36,16 +33,10 @@ describe('GetTeamJoinRequestsUseCase', () => {
teamRepository = {
findById: vi.fn(),
};
output = {
present: vi.fn(),
};
useCase = new GetTeamJoinRequestsUseCase(
membershipRepository as unknown as ITeamMembershipRepository,
useCase = new GetTeamJoinRequestsUseCase(membershipRepository as unknown as ITeamMembershipRepository,
driverRepository as unknown as IDriverRepository,
teamRepository as unknown as ITeamRepository,
output,
);
teamRepository as unknown as ITeamRepository);
});
it('should return join requests with drivers when team exists', async () => {
@@ -79,12 +70,7 @@ describe('GetTeamJoinRequestsUseCase', () => {
const result = await useCase.execute(input);
expect(result.isOk()).toBe(true);
expect(result.unwrap()).toBeUndefined();
expect(output.present).toHaveBeenCalledTimes(1);
const presentedRaw = output.present.mock.calls[0]?.[0];
expect(presentedRaw).toBeDefined();
const presented = presentedRaw as GetTeamJoinRequestsResult;
const presented = result.unwrap() as GetTeamJoinRequestsResult;
expect(presented.team).toBe(team);
expect(presented.joinRequests).toHaveLength(1);
@@ -114,8 +100,7 @@ describe('GetTeamJoinRequestsUseCase', () => {
expect(err.code).toBe('TEAM_NOT_FOUND');
expect(err.details.message).toBe('Team not found');
expect(output.present).not.toHaveBeenCalled();
});
});
it('should return REPOSITORY_ERROR when repository throws', async () => {
const teamId = 'team-1';
@@ -135,6 +120,5 @@ describe('GetTeamJoinRequestsUseCase', () => {
expect(err.code).toBe('REPOSITORY_ERROR');
expect(err.details.message).toBe('Repository failure');
expect(output.present).not.toHaveBeenCalled();
});
});
});