fix issues in core
This commit is contained in:
@@ -15,6 +15,7 @@ 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';
|
||||
|
||||
describe('DashboardOverviewUseCase', () => {
|
||||
it('partitions upcoming races into myUpcomingRaces and otherUpcomingRaces and selects nextRace from myUpcomingRaces', async () => {
|
||||
@@ -226,6 +227,7 @@ describe('DashboardOverviewUseCase', () => {
|
||||
clearRaceRegistrations: async (): Promise<void> => {
|
||||
throw new Error('Not implemented');
|
||||
},
|
||||
findByRaceId: async (): Promise<any[]> => [],
|
||||
};
|
||||
|
||||
const feedRepository = {
|
||||
@@ -253,6 +255,14 @@ 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,
|
||||
@@ -265,21 +275,23 @@ describe('DashboardOverviewUseCase', () => {
|
||||
socialRepository,
|
||||
getDriverAvatar,
|
||||
getDriverStats,
|
||||
outputPort,
|
||||
);
|
||||
|
||||
const input: DashboardOverviewInput = { driverId };
|
||||
|
||||
const result: UseCaseResult<
|
||||
DashboardOverviewResult,
|
||||
void,
|
||||
ApplicationErrorCode<'DRIVER_NOT_FOUND' | 'REPOSITORY_ERROR', { message: string }>
|
||||
> = await useCase.execute(input);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
const vm = result.unwrap();
|
||||
expect(_presentedData).not.toBeNull();
|
||||
const vm = _presentedData!;
|
||||
|
||||
expect(vm.myUpcomingRaces.map(r => r.race.id)).toEqual(['race-1', 'race-3']);
|
||||
expect(vm.myUpcomingRaces.map((r: any) => r.race.id)).toEqual(['race-1', 'race-3']);
|
||||
|
||||
expect(vm.otherUpcomingRaces.map(r => r.race.id)).toEqual(['race-2', 'race-4']);
|
||||
expect(vm.otherUpcomingRaces.map((r: any) => r.race.id)).toEqual(['race-2', 'race-4']);
|
||||
|
||||
expect(vm.nextRace).not.toBeNull();
|
||||
expect(vm.nextRace!.race.id).toBe('race-1');
|
||||
@@ -465,7 +477,7 @@ describe('DashboardOverviewUseCase', () => {
|
||||
getMembership: async (leagueId: string, driverIdParam: string): Promise<LeagueMembership | null> => {
|
||||
return (
|
||||
memberships.find(
|
||||
m => m.leagueId === leagueId && m.driverId === driverIdParam,
|
||||
m => m.leagueId.toString() === leagueId && m.driverId.toString() === driverIdParam,
|
||||
) ?? null
|
||||
);
|
||||
},
|
||||
@@ -499,6 +511,7 @@ describe('DashboardOverviewUseCase', () => {
|
||||
clearRaceRegistrations: async (): Promise<void> => {
|
||||
throw new Error('Not implemented');
|
||||
},
|
||||
findByRaceId: async (): Promise<any[]> => [],
|
||||
};
|
||||
|
||||
const feedRepository = {
|
||||
@@ -526,6 +539,14 @@ 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,
|
||||
@@ -538,37 +559,39 @@ describe('DashboardOverviewUseCase', () => {
|
||||
socialRepository,
|
||||
getDriverAvatar,
|
||||
getDriverStats,
|
||||
outputPort,
|
||||
);
|
||||
|
||||
const input: DashboardOverviewInput = { driverId };
|
||||
|
||||
const result: UseCaseResult<
|
||||
DashboardOverviewResult,
|
||||
void,
|
||||
ApplicationErrorCode<'DRIVER_NOT_FOUND' | 'REPOSITORY_ERROR', { message: string }>
|
||||
> = await useCase.execute(input);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
const vm = result.unwrap();
|
||||
expect(_presentedData).not.toBeNull();
|
||||
const vm = _presentedData!;
|
||||
|
||||
expect(vm.recentResults.length).toBe(2);
|
||||
expect(vm.recentResults[0]!.race.id).toBe('race-new');
|
||||
expect(vm.recentResults[1]!.race.id).toBe('race-old');
|
||||
|
||||
const summariesByLeague = new Map(
|
||||
vm.leagueStandingsSummaries.map(s => [s.league.id, s]),
|
||||
vm.leagueStandingsSummaries.map((s: any) => [s.league.id.toString(), s]),
|
||||
);
|
||||
|
||||
const summaryA = summariesByLeague.get('league-A');
|
||||
const summaryB = summariesByLeague.get('league-B');
|
||||
|
||||
expect(summaryA).toBeDefined();
|
||||
expect(summaryA!.standing?.position).toBe(3);
|
||||
expect(summaryA!.standing?.points).toBe(50);
|
||||
expect(summaryA!.standing?.position.toNumber()).toBe(3);
|
||||
expect(summaryA!.standing?.points.toNumber()).toBe(50);
|
||||
expect(summaryA!.totalDrivers).toBe(2);
|
||||
|
||||
expect(summaryB).toBeDefined();
|
||||
expect(summaryB!.standing?.position).toBe(1);
|
||||
expect(summaryB!.standing?.points).toBe(100);
|
||||
expect(summaryB!.standing?.position.toNumber()).toBe(1);
|
||||
expect(summaryB!.standing?.points.toNumber()).toBe(100);
|
||||
expect(summaryB!.totalDrivers).toBe(2);
|
||||
});
|
||||
|
||||
@@ -708,6 +731,7 @@ describe('DashboardOverviewUseCase', () => {
|
||||
clearRaceRegistrations: async (): Promise<void> => {
|
||||
throw new Error('Not implemented');
|
||||
},
|
||||
findByRaceId: async (): Promise<any[]> => [],
|
||||
};
|
||||
|
||||
const feedRepository = {
|
||||
@@ -725,6 +749,14 @@ 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,
|
||||
@@ -737,17 +769,19 @@ describe('DashboardOverviewUseCase', () => {
|
||||
socialRepository,
|
||||
getDriverAvatar,
|
||||
getDriverStats,
|
||||
outputPort,
|
||||
);
|
||||
|
||||
const input: DashboardOverviewInput = { driverId };
|
||||
|
||||
const result: UseCaseResult<
|
||||
DashboardOverviewResult,
|
||||
void,
|
||||
ApplicationErrorCode<'DRIVER_NOT_FOUND' | 'REPOSITORY_ERROR', { message: string }>
|
||||
> = await useCase.execute(input);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
const vm = result.unwrap();
|
||||
expect(_presentedData).not.toBeNull();
|
||||
const vm = _presentedData!;
|
||||
|
||||
expect(vm.myUpcomingRaces).toEqual([]);
|
||||
expect(vm.otherUpcomingRaces).toEqual([]);
|
||||
@@ -893,6 +927,7 @@ describe('DashboardOverviewUseCase', () => {
|
||||
clearRaceRegistrations: async (): Promise<void> => {
|
||||
throw new Error('Not implemented');
|
||||
},
|
||||
findByRaceId: async (): Promise<any[]> => [],
|
||||
};
|
||||
|
||||
const feedRepository = {
|
||||
@@ -910,6 +945,13 @@ describe('DashboardOverviewUseCase', () => {
|
||||
|
||||
const getDriverStats = () => null;
|
||||
|
||||
// Mock output port to capture presented data
|
||||
const outputPort: UseCaseOutputPort<DashboardOverviewResult> = {
|
||||
present: (_data: DashboardOverviewResult) => {
|
||||
// No-op
|
||||
},
|
||||
};
|
||||
|
||||
const useCase = new DashboardOverviewUseCase(
|
||||
driverRepository,
|
||||
raceRepository,
|
||||
@@ -922,12 +964,13 @@ describe('DashboardOverviewUseCase', () => {
|
||||
socialRepository,
|
||||
getDriverAvatar,
|
||||
getDriverStats,
|
||||
outputPort,
|
||||
);
|
||||
|
||||
const input: DashboardOverviewInput = { driverId };
|
||||
|
||||
const result: UseCaseResult<
|
||||
DashboardOverviewResult,
|
||||
void,
|
||||
ApplicationErrorCode<'DRIVER_NOT_FOUND' | 'REPOSITORY_ERROR', { message: string }>
|
||||
> = await useCase.execute(input);
|
||||
|
||||
@@ -1075,6 +1118,7 @@ describe('DashboardOverviewUseCase', () => {
|
||||
clearRaceRegistrations: async (): Promise<void> => {
|
||||
throw new Error('Not implemented');
|
||||
},
|
||||
findByRaceId: async (): Promise<any[]> => [],
|
||||
};
|
||||
|
||||
const feedRepository = {
|
||||
@@ -1092,6 +1136,13 @@ describe('DashboardOverviewUseCase', () => {
|
||||
|
||||
const getDriverStats = () => null;
|
||||
|
||||
// Mock output port to capture presented data
|
||||
const outputPort: UseCaseOutputPort<DashboardOverviewResult> = {
|
||||
present: (_data: DashboardOverviewResult) => {
|
||||
// No-op
|
||||
},
|
||||
};
|
||||
|
||||
const useCase = new DashboardOverviewUseCase(
|
||||
driverRepository,
|
||||
raceRepository,
|
||||
@@ -1104,12 +1155,13 @@ describe('DashboardOverviewUseCase', () => {
|
||||
socialRepository,
|
||||
getDriverAvatar,
|
||||
getDriverStats,
|
||||
outputPort,
|
||||
);
|
||||
|
||||
const input: DashboardOverviewInput = { driverId };
|
||||
|
||||
const result: UseCaseResult<
|
||||
DashboardOverviewResult,
|
||||
void,
|
||||
ApplicationErrorCode<'DRIVER_NOT_FOUND' | 'REPOSITORY_ERROR', { message: string }>
|
||||
> = await useCase.execute(input);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user