fix core tests

This commit is contained in:
2025-12-23 20:09:02 +01:00
parent 7290fe69b5
commit b5431355ca
25 changed files with 415 additions and 211 deletions

View File

@@ -1,22 +1,18 @@
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,
} from './GetAllLeaguesWithCapacityUseCase';
describe('GetAllLeaguesWithCapacityUseCase', () => {
let mockLeagueRepo: { findAll: Mock };
let mockMembershipRepo: { getLeagueMembers: Mock };
let output: UseCaseOutputPort<GetAllLeaguesWithCapacityResult> & { present: Mock };
beforeEach(() => {
mockLeagueRepo = { findAll: vi.fn() };
mockMembershipRepo = { getLeagueMembers: vi.fn() };
output = { present: vi.fn() } as unknown as typeof output;
});
it('should return leagues with capacity information', async () => {
@@ -32,34 +28,30 @@ describe('GetAllLeaguesWithCapacityUseCase', () => {
{ status: 'active', role: 'owner' },
{ status: 'inactive', role: 'member' },
];
const members2 = [
{ status: 'active', role: 'admin' },
];
const members2 = [{ status: 'active', role: 'admin' }];
mockLeagueRepo.findAll.mockResolvedValue([league1, league2]);
mockMembershipRepo.getLeagueMembers
.mockResolvedValueOnce(members1)
.mockResolvedValueOnce(members2);
mockMembershipRepo.getLeagueMembers.mockResolvedValueOnce(members1).mockResolvedValueOnce(members2);
const result = await useCase.execute({} as GetAllLeaguesWithCapacityInput);
expect(result.isOk()).toBe(true);
expect(result.unwrap()).toBeUndefined();
const resultValue = result.unwrap();
expect(resultValue).toBeDefined();
expect(resultValue?.leagues).toHaveLength(2);
expect(resultValue.leagues).toHaveLength(2);
const [first, second] = resultValue?.leagues ?? [];
const first = resultValue.leagues[0]!;
const second = resultValue.leagues[1]!;
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 () => {
@@ -73,10 +65,9 @@ describe('GetAllLeaguesWithCapacityUseCase', () => {
const result = await useCase.execute({} as GetAllLeaguesWithCapacityInput);
expect(result.isOk()).toBe(true);
expect(result.unwrap()).toBeUndefined();
const resultValue = result.unwrap();
expect(resultValue).toBeDefined();
expect(resultValue?.leagues).toEqual([]);
expect(resultValue.leagues).toEqual([]);
});
});