refactor use cases
This commit is contained in:
@@ -15,7 +15,6 @@ import { Result as RaceResult } from '@core/racing/domain/entities/result/Result
|
||||
import type { FeedItem } from '@core/social/domain/types/FeedItem';
|
||||
import { Result as UseCaseResult } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
import { JoinRequest } from '@core/racing/domain/entities/JoinRequest';
|
||||
import { RaceRegistration } from '@core/racing/domain/entities/RaceRegistration';
|
||||
|
||||
@@ -257,14 +256,6 @@ describe('DashboardOverviewUseCase', () => {
|
||||
}
|
||||
: null;
|
||||
|
||||
// Mock output port to capture presented data
|
||||
let _presentedData: DashboardOverviewResult | null = null;
|
||||
const outputPort: UseCaseOutputPort<DashboardOverviewResult> = {
|
||||
present: (data: DashboardOverviewResult) => {
|
||||
_presentedData = data;
|
||||
},
|
||||
};
|
||||
|
||||
const useCase = new DashboardOverviewUseCase(
|
||||
driverRepository,
|
||||
raceRepository,
|
||||
@@ -277,19 +268,17 @@ describe('DashboardOverviewUseCase', () => {
|
||||
socialRepository,
|
||||
getDriverAvatar,
|
||||
getDriverStats,
|
||||
outputPort,
|
||||
);
|
||||
|
||||
const input: DashboardOverviewInput = { driverId };
|
||||
|
||||
const result: UseCaseResult<
|
||||
void,
|
||||
DashboardOverviewResult,
|
||||
ApplicationErrorCode<'DRIVER_NOT_FOUND' | 'REPOSITORY_ERROR', { message: string }>
|
||||
> = await useCase.execute(input);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(_presentedData).not.toBeNull();
|
||||
const vm = _presentedData!;
|
||||
const vm = result.unwrap();
|
||||
|
||||
expect(vm.myUpcomingRaces.map(r => r.race.id)).toEqual(['race-1', 'race-3']);
|
||||
|
||||
@@ -541,14 +530,6 @@ describe('DashboardOverviewUseCase', () => {
|
||||
}
|
||||
: null;
|
||||
|
||||
// Mock output port to capture presented data
|
||||
let _presentedData: DashboardOverviewResult | null = null;
|
||||
const outputPort: UseCaseOutputPort<DashboardOverviewResult> = {
|
||||
present: (data: DashboardOverviewResult) => {
|
||||
_presentedData = data;
|
||||
},
|
||||
};
|
||||
|
||||
const useCase = new DashboardOverviewUseCase(
|
||||
driverRepository,
|
||||
raceRepository,
|
||||
@@ -561,19 +542,17 @@ describe('DashboardOverviewUseCase', () => {
|
||||
socialRepository,
|
||||
getDriverAvatar,
|
||||
getDriverStats,
|
||||
outputPort,
|
||||
);
|
||||
|
||||
const input: DashboardOverviewInput = { driverId };
|
||||
|
||||
const result: UseCaseResult<
|
||||
void,
|
||||
DashboardOverviewResult,
|
||||
ApplicationErrorCode<'DRIVER_NOT_FOUND' | 'REPOSITORY_ERROR', { message: string }>
|
||||
> = await useCase.execute(input);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(_presentedData).not.toBeNull();
|
||||
const vm = _presentedData!;
|
||||
const vm = result.unwrap();
|
||||
|
||||
expect(vm.recentResults.length).toBe(2);
|
||||
expect(vm.recentResults[0]!.race.id).toBe('race-new');
|
||||
@@ -751,14 +730,6 @@ describe('DashboardOverviewUseCase', () => {
|
||||
|
||||
const getDriverStats = () => null;
|
||||
|
||||
// Mock output port to capture presented data
|
||||
let _presentedData: DashboardOverviewResult | null = null;
|
||||
const outputPort: UseCaseOutputPort<DashboardOverviewResult> = {
|
||||
present: (data: DashboardOverviewResult) => {
|
||||
_presentedData = data;
|
||||
},
|
||||
};
|
||||
|
||||
const useCase = new DashboardOverviewUseCase(
|
||||
driverRepository,
|
||||
raceRepository,
|
||||
@@ -771,19 +742,17 @@ describe('DashboardOverviewUseCase', () => {
|
||||
socialRepository,
|
||||
getDriverAvatar,
|
||||
getDriverStats,
|
||||
outputPort,
|
||||
);
|
||||
|
||||
const input: DashboardOverviewInput = { driverId };
|
||||
|
||||
const result: UseCaseResult<
|
||||
void,
|
||||
DashboardOverviewResult,
|
||||
ApplicationErrorCode<'DRIVER_NOT_FOUND' | 'REPOSITORY_ERROR', { message: string }>
|
||||
> = await useCase.execute(input);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(_presentedData).not.toBeNull();
|
||||
const vm = _presentedData!;
|
||||
const vm = result.unwrap();
|
||||
|
||||
expect(vm.myUpcomingRaces).toEqual([]);
|
||||
expect(vm.otherUpcomingRaces).toEqual([]);
|
||||
@@ -947,13 +916,6 @@ describe('DashboardOverviewUseCase', () => {
|
||||
|
||||
const getDriverStats = () => null;
|
||||
|
||||
// Mock output port to capture presented data
|
||||
const outputPort: UseCaseOutputPort<DashboardOverviewResult> = {
|
||||
present: (_data: DashboardOverviewResult) => {
|
||||
void _data;
|
||||
},
|
||||
};
|
||||
|
||||
const useCase = new DashboardOverviewUseCase(
|
||||
driverRepository,
|
||||
raceRepository,
|
||||
@@ -966,13 +928,12 @@ describe('DashboardOverviewUseCase', () => {
|
||||
socialRepository,
|
||||
getDriverAvatar,
|
||||
getDriverStats,
|
||||
outputPort,
|
||||
);
|
||||
|
||||
const input: DashboardOverviewInput = { driverId };
|
||||
|
||||
const result: UseCaseResult<
|
||||
void,
|
||||
DashboardOverviewResult,
|
||||
ApplicationErrorCode<'DRIVER_NOT_FOUND' | 'REPOSITORY_ERROR', { message: string }>
|
||||
> = await useCase.execute(input);
|
||||
|
||||
@@ -1138,13 +1099,6 @@ describe('DashboardOverviewUseCase', () => {
|
||||
|
||||
const getDriverStats = () => null;
|
||||
|
||||
// Mock output port to capture presented data
|
||||
const outputPort: UseCaseOutputPort<DashboardOverviewResult> = {
|
||||
present: (_data: DashboardOverviewResult) => {
|
||||
void _data;
|
||||
},
|
||||
};
|
||||
|
||||
const useCase = new DashboardOverviewUseCase(
|
||||
driverRepository,
|
||||
raceRepository,
|
||||
@@ -1157,13 +1111,12 @@ describe('DashboardOverviewUseCase', () => {
|
||||
socialRepository,
|
||||
getDriverAvatar,
|
||||
getDriverStats,
|
||||
outputPort,
|
||||
);
|
||||
|
||||
const input: DashboardOverviewInput = { driverId };
|
||||
|
||||
const result: UseCaseResult<
|
||||
void,
|
||||
DashboardOverviewResult,
|
||||
ApplicationErrorCode<'DRIVER_NOT_FOUND' | 'REPOSITORY_ERROR', { message: string }>
|
||||
> = await useCase.execute(input);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user