refactor use cases
This commit is contained in:
@@ -2,7 +2,6 @@ import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest';
|
||||
import { UpdateMemberPaymentUseCase, type UpdateMemberPaymentInput } from './UpdateMemberPaymentUseCase';
|
||||
import type { IMembershipFeeRepository, IMemberPaymentRepository } from '../../domain/repositories/IMembershipFeeRepository';
|
||||
import { MemberPaymentStatus, type MemberPayment } from '../../domain/entities/MemberPayment';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
|
||||
describe('UpdateMemberPaymentUseCase', () => {
|
||||
let membershipFeeRepository: {
|
||||
@@ -15,10 +14,6 @@ describe('UpdateMemberPaymentUseCase', () => {
|
||||
update: Mock;
|
||||
};
|
||||
|
||||
let output: {
|
||||
present: Mock;
|
||||
};
|
||||
|
||||
let useCase: UpdateMemberPaymentUseCase;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -32,14 +27,9 @@ describe('UpdateMemberPaymentUseCase', () => {
|
||||
update: vi.fn(),
|
||||
};
|
||||
|
||||
output = {
|
||||
present: vi.fn(),
|
||||
};
|
||||
|
||||
useCase = new UpdateMemberPaymentUseCase(
|
||||
membershipFeeRepository as unknown as IMembershipFeeRepository,
|
||||
memberPaymentRepository as unknown as IMemberPaymentRepository,
|
||||
output as unknown as UseCaseOutputPort<unknown>,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -58,7 +48,6 @@ describe('UpdateMemberPaymentUseCase', () => {
|
||||
expect(memberPaymentRepository.findByFeeIdAndDriverId).not.toHaveBeenCalled();
|
||||
expect(memberPaymentRepository.create).not.toHaveBeenCalled();
|
||||
expect(memberPaymentRepository.update).not.toHaveBeenCalled();
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('creates a new payment when missing, applies status and paidAt when PAID', async () => {
|
||||
@@ -112,8 +101,9 @@ describe('UpdateMemberPaymentUseCase', () => {
|
||||
}),
|
||||
);
|
||||
|
||||
const value = result.value;
|
||||
const updated = memberPaymentRepository.update.mock.calls[0]?.[0] as MemberPayment;
|
||||
expect(output.present).toHaveBeenCalledWith({ payment: updated });
|
||||
expect(value.payment).toEqual(updated);
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
@@ -164,7 +154,8 @@ describe('UpdateMemberPaymentUseCase', () => {
|
||||
}),
|
||||
);
|
||||
|
||||
const value = result.value;
|
||||
const updated = memberPaymentRepository.update.mock.calls[0]?.[0] as MemberPayment;
|
||||
expect(output.present).toHaveBeenCalledWith({ payment: updated });
|
||||
expect(value.payment).toEqual(updated);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user