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

@@ -9,7 +9,6 @@ import { ITeamRepository } from '../../domain/repositories/ITeamRepository';
import { ITeamMembershipRepository } from '../../domain/repositories/ITeamMembershipRepository';
import { Team } from '../../domain/entities/Team';
import type { TeamMembership } from '../../domain/types/TeamMembership';
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
describe('GetTeamDetailsUseCase', () => {
@@ -20,8 +19,6 @@ describe('GetTeamDetailsUseCase', () => {
let membershipRepository: {
getMembership: Mock;
};
let output: UseCaseOutputPort<GetTeamDetailsResult> & { present: Mock };
beforeEach(() => {
teamRepository = {
findById: vi.fn(),
@@ -29,14 +26,8 @@ describe('GetTeamDetailsUseCase', () => {
membershipRepository = {
getMembership: vi.fn(),
};
output = {
present: vi.fn(),
} as unknown as UseCaseOutputPort<GetTeamDetailsResult> & { present: Mock };
useCase = new GetTeamDetailsUseCase(
teamRepository as unknown as ITeamRepository,
membershipRepository as unknown as ITeamMembershipRepository,
output,
);
useCase = new GetTeamDetailsUseCase(teamRepository as unknown as ITeamRepository,
membershipRepository as unknown as ITeamMembershipRepository);
});
it('should return team details with membership', async () => {
@@ -67,9 +58,7 @@ describe('GetTeamDetailsUseCase', () => {
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 presentedRaw = expect(presentedRaw).toBeDefined();
const presented = presentedRaw as GetTeamDetailsResult;
expect(presented.team).toBe(team);
expect(presented.membership).toEqual(membership);
@@ -104,9 +93,7 @@ describe('GetTeamDetailsUseCase', () => {
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 presentedRaw = expect(presentedRaw).toBeDefined();
const presented = presentedRaw as GetTeamDetailsResult;
expect(presented.canManage).toBe(true);
});
@@ -127,8 +114,7 @@ describe('GetTeamDetailsUseCase', () => {
>;
expect(errorResult.code).toBe('TEAM_NOT_FOUND');
expect(errorResult.details?.message).toBe('Team not found');
expect(output.present).not.toHaveBeenCalled();
});
});
it('should return error on repository failure', async () => {
const teamId = 'team-1';
@@ -146,6 +132,5 @@ describe('GetTeamDetailsUseCase', () => {
>;
expect(errorResult.code).toBe('REPOSITORY_ERROR');
expect(errorResult.details?.message).toBe('DB error');
expect(output.present).not.toHaveBeenCalled();
});
});
});