fix issues in core

This commit is contained in:
2025-12-23 14:43:49 +01:00
parent 11492d1ff2
commit df5c20c5cc
62 changed files with 480 additions and 334 deletions

View File

@@ -1,13 +1,12 @@
import { describe, it, expect, beforeEach, vi, Mock } from 'vitest';
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
import { beforeEach, describe, expect, it, Mock, vi } from 'vitest';
import type { ILeagueMembershipRepository } from '../../domain/repositories/ILeagueMembershipRepository';
import type { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
import {
GetAllLeaguesWithCapacityUseCase,
type GetAllLeaguesWithCapacityInput,
type GetAllLeaguesWithCapacityResult,
type LeagueCapacitySummary,
} from './GetAllLeaguesWithCapacityUseCase';
import type { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
import type { ILeagueMembershipRepository } from '../../domain/repositories/ILeagueMembershipRepository';
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
describe('GetAllLeaguesWithCapacityUseCase', () => {
let mockLeagueRepo: { findAll: Mock };
@@ -24,7 +23,6 @@ describe('GetAllLeaguesWithCapacityUseCase', () => {
const useCase = new GetAllLeaguesWithCapacityUseCase(
mockLeagueRepo as unknown as ILeagueRepository,
mockMembershipRepo as unknown as ILeagueMembershipRepository,
output,
);
const league1 = { id: 'league1', name: 'Test League 1', settings: { maxDrivers: 10 } };
@@ -48,27 +46,26 @@ describe('GetAllLeaguesWithCapacityUseCase', () => {
expect(result.isOk()).toBe(true);
expect(result.unwrap()).toBeUndefined();
expect(output.present).toHaveBeenCalledTimes(1);
const resultValue = result.unwrap();
expect(resultValue).toBeDefined();
const presented = output.present.mock.calls[0][0] as GetAllLeaguesWithCapacityResult;
expect(presented.leagues).toHaveLength(2);
expect(resultValue?.leagues).toHaveLength(2);
const [first, second] = presented.leagues as LeagueCapacitySummary[];
const [first, second] = resultValue?.leagues ?? [];
expect(first.league).toEqual(league1);
expect(first.currentDrivers).toBe(2);
expect(first.maxDrivers).toBe(10);
expect(first?.league).toEqual(league1);
expect(first?.currentDrivers).toBe(2);
expect(first?.maxDrivers).toBe(10);
expect(second.league).toEqual(league2);
expect(second.currentDrivers).toBe(1);
expect(second.maxDrivers).toBe(20);
expect(second?.league).toEqual(league2);
expect(second?.currentDrivers).toBe(1);
expect(second?.maxDrivers).toBe(20);
});
it('should return empty result when no leagues', async () => {
const useCase = new GetAllLeaguesWithCapacityUseCase(
mockLeagueRepo as unknown as ILeagueRepository,
mockMembershipRepo as unknown as ILeagueMembershipRepository,
output,
);
mockLeagueRepo.findAll.mockResolvedValue([]);
@@ -78,8 +75,8 @@ describe('GetAllLeaguesWithCapacityUseCase', () => {
expect(result.isOk()).toBe(true);
expect(result.unwrap()).toBeUndefined();
expect(output.present).toHaveBeenCalledTimes(1);
const presented = output.present.mock.calls[0][0] as GetAllLeaguesWithCapacityResult;
expect(presented.leagues).toEqual([]);
const resultValue = result.unwrap();
expect(resultValue).toBeDefined();
expect(resultValue?.leagues).toEqual([]);
});
});