wip
This commit is contained in:
@@ -73,15 +73,22 @@ describe('ImportRaceResultsUseCase', () => {
|
||||
let existsByRaceIdCalled = false;
|
||||
const recalcCalls: string[] = [];
|
||||
|
||||
const raceRepository = {
|
||||
const raceRepository: {
|
||||
findById: (id: string) => Promise<Race | null>;
|
||||
} = {
|
||||
findById: async (id: string) => races.get(id) ?? null,
|
||||
} as unknown as any;
|
||||
|
||||
const leagueRepository = {
|
||||
};
|
||||
|
||||
const leagueRepository: {
|
||||
findById: (id: string) => Promise<League | null>;
|
||||
} = {
|
||||
findById: async (id: string) => leagues.get(id) ?? null,
|
||||
} as unknown as any;
|
||||
|
||||
const resultRepository = {
|
||||
};
|
||||
|
||||
const resultRepository: {
|
||||
existsByRaceId: (raceId: string) => Promise<boolean>;
|
||||
createMany: (results: Result[]) => Promise<Result[]>;
|
||||
} = {
|
||||
existsByRaceId: async (raceId: string) => {
|
||||
existsByRaceIdCalled = true;
|
||||
return storedResults.some((r) => r.raceId === raceId);
|
||||
@@ -90,13 +97,15 @@ describe('ImportRaceResultsUseCase', () => {
|
||||
storedResults.push(...results);
|
||||
return results;
|
||||
},
|
||||
} as unknown as any;
|
||||
|
||||
const standingRepository = {
|
||||
};
|
||||
|
||||
const standingRepository: {
|
||||
recalculate: (leagueId: string) => Promise<void>;
|
||||
} = {
|
||||
recalculate: async (leagueId: string) => {
|
||||
recalcCalls.push(leagueId);
|
||||
},
|
||||
} as unknown as any;
|
||||
};
|
||||
|
||||
const presenter = new FakeImportRaceResultsPresenter();
|
||||
|
||||
@@ -183,28 +192,37 @@ describe('ImportRaceResultsUseCase', () => {
|
||||
}),
|
||||
];
|
||||
|
||||
const raceRepository = {
|
||||
const raceRepository: {
|
||||
findById: (id: string) => Promise<Race | null>;
|
||||
} = {
|
||||
findById: async (id: string) => races.get(id) ?? null,
|
||||
} as unknown as any;
|
||||
|
||||
const leagueRepository = {
|
||||
};
|
||||
|
||||
const leagueRepository: {
|
||||
findById: (id: string) => Promise<League | null>;
|
||||
} = {
|
||||
findById: async (id: string) => leagues.get(id) ?? null,
|
||||
} as unknown as any;
|
||||
|
||||
const resultRepository = {
|
||||
};
|
||||
|
||||
const resultRepository: {
|
||||
existsByRaceId: (raceId: string) => Promise<boolean>;
|
||||
createMany: (results: Result[]) => Promise<Result[]>;
|
||||
} = {
|
||||
existsByRaceId: async (raceId: string) => {
|
||||
return storedResults.some((r) => r.raceId === raceId);
|
||||
},
|
||||
createMany: async (_results: Result[]) => {
|
||||
throw new Error('Should not be called when results already exist');
|
||||
},
|
||||
} as unknown as any;
|
||||
|
||||
const standingRepository = {
|
||||
};
|
||||
|
||||
const standingRepository: {
|
||||
recalculate: (leagueId: string) => Promise<void>;
|
||||
} = {
|
||||
recalculate: async (_leagueId: string) => {
|
||||
throw new Error('Should not be called when results already exist');
|
||||
},
|
||||
} as unknown as any;
|
||||
};
|
||||
|
||||
const presenter = new FakeImportRaceResultsPresenter();
|
||||
|
||||
@@ -257,8 +275,16 @@ describe('GetRaceResultsDetailUseCase', () => {
|
||||
status: 'completed',
|
||||
});
|
||||
|
||||
const driver1 = { id: 'driver-a', name: 'Driver A', country: 'US' } as any;
|
||||
const driver2 = { id: 'driver-b', name: 'Driver B', country: 'GB' } as any;
|
||||
const driver1: { id: string; name: string; country: string } = {
|
||||
id: 'driver-a',
|
||||
name: 'Driver A',
|
||||
country: 'US',
|
||||
};
|
||||
const driver2: { id: string; name: string; country: string } = {
|
||||
id: 'driver-b',
|
||||
name: 'Driver B',
|
||||
country: 'GB',
|
||||
};
|
||||
|
||||
const result1 = Result.create({
|
||||
id: 'r1',
|
||||
@@ -285,26 +311,36 @@ describe('GetRaceResultsDetailUseCase', () => {
|
||||
const results = [result1, result2];
|
||||
const drivers = [driver1, driver2];
|
||||
|
||||
const raceRepository = {
|
||||
const raceRepository: {
|
||||
findById: (id: string) => Promise<Race | null>;
|
||||
} = {
|
||||
findById: async (id: string) => races.get(id) ?? null,
|
||||
} as unknown as any;
|
||||
|
||||
const leagueRepository = {
|
||||
};
|
||||
|
||||
const leagueRepository: {
|
||||
findById: (id: string) => Promise<League | null>;
|
||||
} = {
|
||||
findById: async (id: string) => leagues.get(id) ?? null,
|
||||
} as unknown as any;
|
||||
|
||||
const resultRepository = {
|
||||
};
|
||||
|
||||
const resultRepository: {
|
||||
findByRaceId: (raceId: string) => Promise<Result[]>;
|
||||
} = {
|
||||
findByRaceId: async (raceId: string) =>
|
||||
results.filter((r) => r.raceId === raceId),
|
||||
} as unknown as any;
|
||||
|
||||
const driverRepository = {
|
||||
};
|
||||
|
||||
const driverRepository: {
|
||||
findAll: () => Promise<Array<{ id: string; name: string; country: string }>>;
|
||||
} = {
|
||||
findAll: async () => drivers,
|
||||
} as unknown as any;
|
||||
|
||||
const penaltyRepository = {
|
||||
};
|
||||
|
||||
const penaltyRepository: {
|
||||
findByRaceId: (raceId: string) => Promise<Penalty[]>;
|
||||
} = {
|
||||
findByRaceId: async () => [] as Penalty[],
|
||||
} as unknown as any;
|
||||
};
|
||||
|
||||
const presenter = new FakeRaceResultsDetailPresenter();
|
||||
|
||||
@@ -350,7 +386,11 @@ describe('GetRaceResultsDetailUseCase', () => {
|
||||
status: 'completed',
|
||||
});
|
||||
|
||||
const driver = { id: 'driver-pen', name: 'Penalty Driver', country: 'DE' } as any;
|
||||
const driver: { id: string; name: string; country: string } = {
|
||||
id: 'driver-pen',
|
||||
name: 'Penalty Driver',
|
||||
country: 'DE',
|
||||
};
|
||||
|
||||
const result = Result.create({
|
||||
id: 'res-pen',
|
||||
@@ -380,27 +420,37 @@ describe('GetRaceResultsDetailUseCase', () => {
|
||||
const drivers = [driver];
|
||||
const penalties = [penalty];
|
||||
|
||||
const raceRepository = {
|
||||
const raceRepository: {
|
||||
findById: (id: string) => Promise<Race | null>;
|
||||
} = {
|
||||
findById: async (id: string) => races.get(id) ?? null,
|
||||
} as unknown as any;
|
||||
|
||||
const leagueRepository = {
|
||||
};
|
||||
|
||||
const leagueRepository: {
|
||||
findById: (id: string) => Promise<League | null>;
|
||||
} = {
|
||||
findById: async (id: string) => leagues.get(id) ?? null,
|
||||
} as unknown as any;
|
||||
|
||||
const resultRepository = {
|
||||
};
|
||||
|
||||
const resultRepository: {
|
||||
findByRaceId: (raceId: string) => Promise<Result[]>;
|
||||
} = {
|
||||
findByRaceId: async (raceId: string) =>
|
||||
results.filter((r) => r.raceId === raceId),
|
||||
} as unknown as any;
|
||||
|
||||
const driverRepository = {
|
||||
};
|
||||
|
||||
const driverRepository: {
|
||||
findAll: () => Promise<Array<{ id: string; name: string; country: string }>>;
|
||||
} = {
|
||||
findAll: async () => drivers,
|
||||
} as unknown as any;
|
||||
|
||||
const penaltyRepository = {
|
||||
};
|
||||
|
||||
const penaltyRepository: {
|
||||
findByRaceId: (raceId: string) => Promise<Penalty[]>;
|
||||
} = {
|
||||
findByRaceId: async (raceId: string) =>
|
||||
penalties.filter((p) => p.raceId === raceId),
|
||||
} as unknown as any;
|
||||
};
|
||||
|
||||
const presenter = new FakeRaceResultsDetailPresenter();
|
||||
|
||||
@@ -437,28 +487,38 @@ describe('GetRaceResultsDetailUseCase', () => {
|
||||
|
||||
it('presents an error when race does not exist', async () => {
|
||||
// Given repositories without the requested race
|
||||
const raceRepository = {
|
||||
const raceRepository: {
|
||||
findById: (id: string) => Promise<Race | null>;
|
||||
} = {
|
||||
findById: async () => null,
|
||||
} as unknown as any;
|
||||
|
||||
const leagueRepository = {
|
||||
};
|
||||
|
||||
const leagueRepository: {
|
||||
findById: (id: string) => Promise<League | null>;
|
||||
} = {
|
||||
findById: async () => null,
|
||||
} as unknown as any;
|
||||
|
||||
const resultRepository = {
|
||||
};
|
||||
|
||||
const resultRepository: {
|
||||
findByRaceId: (raceId: string) => Promise<Result[]>;
|
||||
} = {
|
||||
findByRaceId: async () => [] as Result[],
|
||||
} as unknown as any;
|
||||
|
||||
const driverRepository = {
|
||||
findAll: async () => [] as any[],
|
||||
} as unknown as any;
|
||||
|
||||
const penaltyRepository = {
|
||||
};
|
||||
|
||||
const driverRepository: {
|
||||
findAll: () => Promise<Array<{ id: string; name: string; country: string }>>;
|
||||
} = {
|
||||
findAll: async () => [],
|
||||
};
|
||||
|
||||
const penaltyRepository: {
|
||||
findByRaceId: (raceId: string) => Promise<Penalty[]>;
|
||||
} = {
|
||||
findByRaceId: async () => [] as Penalty[],
|
||||
} as unknown as any;
|
||||
|
||||
};
|
||||
|
||||
const presenter = new FakeRaceResultsDetailPresenter();
|
||||
|
||||
|
||||
const useCase = new GetRaceResultsDetailUseCase(
|
||||
raceRepository,
|
||||
leagueRepository,
|
||||
@@ -467,10 +527,10 @@ describe('GetRaceResultsDetailUseCase', () => {
|
||||
penaltyRepository,
|
||||
presenter,
|
||||
);
|
||||
|
||||
|
||||
// When
|
||||
await useCase.execute({ raceId: 'missing-race' });
|
||||
|
||||
|
||||
const viewModel = presenter.getViewModel();
|
||||
expect(viewModel).not.toBeNull();
|
||||
expect(viewModel!.race).toBeNull();
|
||||
|
||||
Reference in New Issue
Block a user