fix issues in core
This commit is contained in:
@@ -2,11 +2,9 @@ import { describe, it, expect, beforeEach, vi, Mock } from 'vitest';
|
||||
import {
|
||||
GetTotalDriversUseCase,
|
||||
GetTotalDriversInput,
|
||||
GetTotalDriversResult,
|
||||
GetTotalDriversErrorCode,
|
||||
} from './GetTotalDriversUseCase';
|
||||
import { IDriverRepository } from '../../domain/repositories/IDriverRepository';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
describe('GetTotalDriversUseCase', () => {
|
||||
@@ -14,21 +12,12 @@ describe('GetTotalDriversUseCase', () => {
|
||||
let driverRepository: {
|
||||
findAll: Mock;
|
||||
};
|
||||
let output: UseCaseOutputPort<GetTotalDriversResult> & { present: Mock };
|
||||
|
||||
beforeEach(() => {
|
||||
driverRepository = {
|
||||
findAll: vi.fn(),
|
||||
};
|
||||
|
||||
output = {
|
||||
present: vi.fn(),
|
||||
} as unknown as UseCaseOutputPort<GetTotalDriversResult> & { present: Mock };
|
||||
|
||||
useCase = new GetTotalDriversUseCase(
|
||||
driverRepository as unknown as IDriverRepository,
|
||||
output,
|
||||
);
|
||||
useCase = new GetTotalDriversUseCase(driverRepository as unknown as IDriverRepository);
|
||||
});
|
||||
|
||||
it('should return total number of drivers', async () => {
|
||||
@@ -41,11 +30,7 @@ describe('GetTotalDriversUseCase', () => {
|
||||
const result = await useCase.execute(input);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
expect(output.present).toHaveBeenCalledWith<[{ totalDrivers: number }]>(
|
||||
expect.objectContaining({ totalDrivers: 2 }),
|
||||
);
|
||||
expect(result.unwrap()).toEqual({ totalDrivers: 2 });
|
||||
});
|
||||
|
||||
it('should return error on repository failure', async () => {
|
||||
@@ -66,6 +51,5 @@ describe('GetTotalDriversUseCase', () => {
|
||||
|
||||
expect(unwrappedError.code).toBe('REPOSITORY_ERROR');
|
||||
expect(unwrappedError.details.message).toBe(error.message);
|
||||
expect(output.present).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user