refactor use cases
This commit is contained in:
@@ -7,7 +7,6 @@ import {
|
||||
} from './GetSponsorUseCase';
|
||||
import type { ISponsorRepository } from '../../domain/repositories/ISponsorRepository';
|
||||
import { Sponsor } from '../../domain/entities/sponsor/Sponsor';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
describe('GetSponsorUseCase', () => {
|
||||
@@ -15,8 +14,6 @@ describe('GetSponsorUseCase', () => {
|
||||
findById: Mock;
|
||||
};
|
||||
|
||||
let output: UseCaseOutputPort<GetSponsorResult> & { present: Mock };
|
||||
|
||||
let useCase: GetSponsorUseCase;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -24,17 +21,12 @@ describe('GetSponsorUseCase', () => {
|
||||
findById: vi.fn(),
|
||||
};
|
||||
|
||||
output = {
|
||||
present: vi.fn(),
|
||||
} as unknown as UseCaseOutputPort<GetSponsorResult> & { present: Mock };
|
||||
|
||||
useCase = new GetSponsorUseCase(
|
||||
sponsorRepository as unknown as ISponsorRepository,
|
||||
output,
|
||||
);
|
||||
});
|
||||
|
||||
it('presents sponsor when found', async () => {
|
||||
it('returns sponsor when found', async () => {
|
||||
const sponsor = Sponsor.create({
|
||||
id: 'sponsor-1',
|
||||
name: 'Test Sponsor',
|
||||
@@ -47,7 +39,8 @@ describe('GetSponsorUseCase', () => {
|
||||
const result = await useCase.execute(input);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(output.present).toHaveBeenCalledWith({ sponsor });
|
||||
const successResult = result.unwrap();
|
||||
expect(successResult.sponsor).toEqual(sponsor);
|
||||
});
|
||||
|
||||
it('returns SPONSOR_NOT_FOUND when sponsor does not exist', async () => {
|
||||
@@ -65,7 +58,6 @@ describe('GetSponsorUseCase', () => {
|
||||
|
||||
expect(err.code).toBe('SPONSOR_NOT_FOUND');
|
||||
expect(err.details.message).toBe('Sponsor not found');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('returns REPOSITORY_ERROR when repository throws', async () => {
|
||||
@@ -83,6 +75,5 @@ describe('GetSponsorUseCase', () => {
|
||||
|
||||
expect(err.code).toBe('REPOSITORY_ERROR');
|
||||
expect(err.details.message).toBe('DB error');
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user