website refactor
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import type { DriverRepository } from '../../domain/repositories/DriverRepository';
|
||||
import type { PenaltyRepository } from '../../domain/repositories/PenaltyRepository';
|
||||
import type { RaceRepository } from '../../domain/repositories/RaceRepository';
|
||||
import type { ResultRepository } from '../../domain/repositories/ResultRepository';
|
||||
import type { StandingRepository } from '../../domain/repositories/StandingRepository';
|
||||
import type { DriverRatingPort } from '../ports/DriverRatingPort';
|
||||
import { describe, it, expect, beforeEach, vi, Mock } from 'vitest';
|
||||
import {
|
||||
GetLeagueDriverSeasonStatsUseCase,
|
||||
type GetLeagueDriverSeasonStatsErrorCode,
|
||||
type GetLeagueDriverSeasonStatsInput,
|
||||
type GetLeagueDriverSeasonStatsResult,
|
||||
} from './GetLeagueDriverSeasonStatsUseCase';
|
||||
import type { StandingRepository } from '../../domain/repositories/StandingRepository';
|
||||
import type { ResultRepository } from '../../domain/repositories/ResultRepository';
|
||||
import type { PenaltyRepository } from '../../domain/repositories/PenaltyRepository';
|
||||
import type { RaceRepository } from '../../domain/repositories/RaceRepository';
|
||||
import type { DriverRepository } from '../../domain/repositories/DriverRepository';
|
||||
import type { DriverRatingPort } from '../ports/DriverRatingPort';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
describe('GetLeagueDriverSeasonStatsUseCase', () => {
|
||||
const mockStandingFindByLeagueId = vi.fn();
|
||||
@@ -20,15 +20,15 @@ describe('GetLeagueDriverSeasonStatsUseCase', () => {
|
||||
const mockRaceFindByLeagueId = vi.fn();
|
||||
const mockDriverRatingGetRating = vi.fn();
|
||||
const mockDriverFindById = vi.fn();
|
||||
const mockTeamFindById = vi.fn();
|
||||
|
||||
let useCase: GetLeagueDriverSeasonStatsUseCase;
|
||||
let standingRepository: IStandingRepository;
|
||||
let resultRepository: IResultRepository;
|
||||
let penaltyRepository: IPenaltyRepository;
|
||||
let raceRepository: IRaceRepository;
|
||||
let driverRepository: IDriverRepository;
|
||||
let driverRatingPort: DriverRatingPort;
|
||||
let standingRepository: any;
|
||||
let resultRepository: any;
|
||||
let penaltyRepository: any;
|
||||
let raceRepository: any;
|
||||
let driverRepository: any;
|
||||
let driverRatingPort: any;
|
||||
|
||||
beforeEach(() => {
|
||||
mockStandingFindByLeagueId.mockReset();
|
||||
mockResultFindByDriverIdAndLeagueId.mockReset();
|
||||
@@ -36,7 +36,6 @@ describe('GetLeagueDriverSeasonStatsUseCase', () => {
|
||||
mockRaceFindByLeagueId.mockReset();
|
||||
mockDriverRatingGetRating.mockReset();
|
||||
mockDriverFindById.mockReset();
|
||||
mockTeamFindById.mockReset();
|
||||
|
||||
standingRepository = {
|
||||
findByLeagueId: mockStandingFindByLeagueId,
|
||||
@@ -103,8 +102,6 @@ describe('GetLeagueDriverSeasonStatsUseCase', () => {
|
||||
updateDriverRating: vi.fn(),
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
useCase = new GetLeagueDriverSeasonStatsUseCase(standingRepository,
|
||||
resultRepository,
|
||||
penaltyRepository,
|
||||
@@ -182,8 +179,8 @@ describe('GetLeagueDriverSeasonStatsUseCase', () => {
|
||||
const result = await useCase.execute(input);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
const presented = expect(presented.leagueId).toBe('league-1');
|
||||
const presented = result.unwrap();
|
||||
expect(presented.leagueId).toBe('league-1');
|
||||
expect(presented.stats).toHaveLength(2);
|
||||
|
||||
expect(presented.stats[0]).toEqual({
|
||||
@@ -231,8 +228,8 @@ describe('GetLeagueDriverSeasonStatsUseCase', () => {
|
||||
const result = await useCase.execute(input);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
const presented = expect(presented?.stats[0]?.penaltyPoints).toBe(0);
|
||||
const presented = result.unwrap();
|
||||
expect(presented.stats[0]?.penaltyPoints).toBe(0);
|
||||
});
|
||||
|
||||
it('should return LEAGUE_NOT_FOUND when no standings are found', async () => {
|
||||
@@ -250,7 +247,7 @@ describe('GetLeagueDriverSeasonStatsUseCase', () => {
|
||||
>;
|
||||
expect(err.code).toBe('LEAGUE_NOT_FOUND');
|
||||
expect(err.details.message).toBe('League not found');
|
||||
});
|
||||
});
|
||||
|
||||
it('should return REPOSITORY_ERROR when an unexpected error occurs', async () => {
|
||||
const input: GetLeagueDriverSeasonStatsInput = { leagueId: 'league-1' };
|
||||
@@ -265,8 +262,7 @@ describe('GetLeagueDriverSeasonStatsUseCase', () => {
|
||||
GetLeagueDriverSeasonStatsErrorCode,
|
||||
{ message: string }
|
||||
>;
|
||||
|
||||
expect(err.code).toBe('REPOSITORY_ERROR');
|
||||
expect(err.details.message).toBe('repository failure');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user