website refactor

This commit is contained in:
2026-01-16 15:20:25 +01:00
parent 7e02fc3ea5
commit 37b1aa626c
325 changed files with 2167 additions and 2782 deletions

View File

@@ -1,18 +1,17 @@
import { describe, it, expect, beforeEach, vi } from 'vitest';
import {
GetAllRacesUseCase,
type GetAllRacesResult,
type GetAllRacesInput,
} from './GetAllRacesUseCase';
import type { RaceRepository } from '../../domain/repositories/RaceRepository';
import type { LeagueRepository } from '../../domain/repositories/LeagueRepository';
import type { Logger } from '@core/shared/application';
import { Race } from '../../domain/entities/Race';
import type { Logger } from '@core/shared/domain/Logger';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { League } from '../../domain/entities/League';
import { Race } from '../../domain/entities/Race';
import type { LeagueRepository } from '../../domain/repositories/LeagueRepository';
import type { RaceRepository } from '../../domain/repositories/RaceRepository';
import {
GetAllRacesUseCase,
type GetAllRacesInput
} from './GetAllRacesUseCase';
describe('GetAllRacesUseCase', () => {
const mockRaceFindAll = vi.fn();
const mockRaceRepo: IRaceRepository = {
const mockRaceRepo: RaceRepository = {
findById: vi.fn(),
findAll: mockRaceFindAll,
findByLeagueId: vi.fn(),
@@ -27,7 +26,7 @@ describe('GetAllRacesUseCase', () => {
};
const mockLeagueFindAll = vi.fn();
const mockLeagueRepo: ILeagueRepository = {
const mockLeagueRepo: LeagueRepository = {
findById: vi.fn(),
findAll: mockLeagueFindAll,
findByOwnerId: vi.fn(),
@@ -47,13 +46,12 @@ describe('GetAllRacesUseCase', () => {
beforeEach(() => {
vi.clearAllMocks();
});
});
it('should present domain races and leagues data', async () => {
it('should return domain races and leagues data', async () => {
const useCase = new GetAllRacesUseCase(mockRaceRepo,
mockLeagueRepo,
mockLogger);
useCase.setOutput(output);
const race1 = Race.create({
id: 'race1',
@@ -95,17 +93,16 @@ describe('GetAllRacesUseCase', () => {
const result = await useCase.execute(input);
expect(result.isOk()).toBe(true);
expect(result.unwrap()).toBeUndefined();
const presented = expect(presented.totalCount).toBe(2);
const presented = result.unwrap();
expect(presented.totalCount).toBe(2);
expect(presented.races).toEqual([race1, race2]);
expect(presented.leagues).toEqual([league1, league2]);
});
it('should present empty result when no races or leagues', async () => {
it('should return empty result when no races or leagues', async () => {
const useCase = new GetAllRacesUseCase(mockRaceRepo,
mockLeagueRepo,
mockLogger);
useCase.setOutput(output);
mockRaceFindAll.mockResolvedValue([]);
mockLeagueFindAll.mockResolvedValue([]);
@@ -113,13 +110,13 @@ describe('GetAllRacesUseCase', () => {
const result = await useCase.execute({});
expect(result.isOk()).toBe(true);
expect(result.unwrap()).toBeUndefined();
const presented = expect(presented.totalCount).toBe(0);
const presented = result.unwrap();
expect(presented.totalCount).toBe(0);
expect(presented.races).toEqual([]);
expect(presented.leagues).toEqual([]);
});
it('should return error when repository throws and not present data', async () => {
it('should return error when repository throws', async () => {
const useCase = new GetAllRacesUseCase(mockRaceRepo,
mockLeagueRepo,
mockLogger);
@@ -133,5 +130,5 @@ describe('GetAllRacesUseCase', () => {
const err = result.unwrapErr();
expect(err.code).toBe('REPOSITORY_ERROR');
expect(err.details.message).toBe('Repository error');
});
});
});