website refactor
This commit is contained in:
@@ -1,12 +1,8 @@
|
||||
import { describe, it, expect, beforeEach, vi, Mock } from 'vitest';
|
||||
import { beforeEach, describe, expect, it, Mock, vi } from 'vitest';
|
||||
import {
|
||||
CreateLeagueWithSeasonAndScoringUseCase,
|
||||
type CreateLeagueWithSeasonAndScoringCommand,
|
||||
type CreateLeagueWithSeasonAndScoringResult,
|
||||
CreateLeagueWithSeasonAndScoringUseCase,
|
||||
type CreateLeagueWithSeasonAndScoringCommand
|
||||
} from './CreateLeagueWithSeasonAndScoringUseCase';
|
||||
import type { LeagueRepository } from '../../domain/repositories/LeagueRepository';
|
||||
import type { SeasonRepository } from '../../domain/repositories/SeasonRepository';
|
||||
import type { LeagueScoringConfigRepository } from '../../domain/repositories/LeagueScoringConfigRepository';
|
||||
|
||||
describe('CreateLeagueWithSeasonAndScoringUseCase', () => {
|
||||
let useCase: CreateLeagueWithSeasonAndScoringUseCase;
|
||||
@@ -26,7 +22,6 @@ describe('CreateLeagueWithSeasonAndScoringUseCase', () => {
|
||||
warn: Mock;
|
||||
error: Mock;
|
||||
};
|
||||
let output: { present: Mock } ;
|
||||
|
||||
beforeEach(() => {
|
||||
leagueRepository = {
|
||||
@@ -45,12 +40,11 @@ describe('CreateLeagueWithSeasonAndScoringUseCase', () => {
|
||||
warn: vi.fn(),
|
||||
error: vi.fn(),
|
||||
};
|
||||
output = { present: vi.fn() } as unknown as typeof output;
|
||||
useCase = new CreateLeagueWithSeasonAndScoringUseCase(leagueRepository as unknown as ILeagueRepository,
|
||||
seasonRepository as unknown as ISeasonRepository,
|
||||
leagueScoringConfigRepository as unknown as ILeagueScoringConfigRepository,
|
||||
useCase = new CreateLeagueWithSeasonAndScoringUseCase(leagueRepository as any,
|
||||
seasonRepository as any,
|
||||
leagueScoringConfigRepository as any,
|
||||
getLeagueScoringPresetById,
|
||||
logger as unknown as Logger);
|
||||
logger as any);
|
||||
});
|
||||
|
||||
it('should create league, season, and scoring successfully', async () => {
|
||||
@@ -82,11 +76,11 @@ describe('CreateLeagueWithSeasonAndScoringUseCase', () => {
|
||||
const result = await useCase.execute(command);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
const presented = result.unwrap();
|
||||
|
||||
const presented = (expect(presented?.league.id.toString()).toBeDefined();
|
||||
expect(presented?.season.id).toBeDefined();
|
||||
expect(presented?.scoringConfig.seasonId.toString()).toBe(presented?.season.id);
|
||||
expect(presented.league.id).toBeDefined();
|
||||
expect(presented.season.id).toBeDefined();
|
||||
expect(presented.scoringConfig.seasonId.toString()).toBe(presented.season.id);
|
||||
expect(leagueRepository.create).toHaveBeenCalledTimes(1);
|
||||
expect(seasonRepository.create).toHaveBeenCalledTimes(1);
|
||||
expect(leagueScoringConfigRepository.save).toHaveBeenCalledTimes(1);
|
||||
@@ -113,7 +107,7 @@ describe('CreateLeagueWithSeasonAndScoringUseCase', () => {
|
||||
if ('details' in err && err.details && typeof err.details === 'object' && 'message' in err.details) {
|
||||
expect(err.details.message).toBe('League name is required');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should return error when ownerId is empty', async () => {
|
||||
const command = {
|
||||
@@ -136,7 +130,7 @@ describe('CreateLeagueWithSeasonAndScoringUseCase', () => {
|
||||
if ('details' in err && err.details && typeof err.details === 'object' && 'message' in err.details) {
|
||||
expect(err.details.message).toBe('League ownerId is required');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should return error when gameId is empty', async () => {
|
||||
const command = {
|
||||
@@ -159,7 +153,7 @@ describe('CreateLeagueWithSeasonAndScoringUseCase', () => {
|
||||
if ('details' in err && err.details && typeof err.details === 'object' && 'message' in err.details) {
|
||||
expect(err.details.message).toBe('gameId is required');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should return error when visibility is missing', async () => {
|
||||
const command: Partial<CreateLeagueWithSeasonAndScoringCommand> = {
|
||||
@@ -180,7 +174,7 @@ describe('CreateLeagueWithSeasonAndScoringUseCase', () => {
|
||||
if ('details' in err && err.details && typeof err.details === 'object' && 'message' in err.details) {
|
||||
expect(err.details.message).toBe('visibility is required');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should return error when maxDrivers is invalid', async () => {
|
||||
const command = {
|
||||
@@ -204,7 +198,7 @@ describe('CreateLeagueWithSeasonAndScoringUseCase', () => {
|
||||
if ('details' in err && err.details && typeof err.details === 'object' && 'message' in err.details) {
|
||||
expect(err.details.message).toBe('maxDrivers must be greater than 0 when provided');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should return error when ranked league has insufficient drivers', async () => {
|
||||
const command = {
|
||||
@@ -228,7 +222,7 @@ describe('CreateLeagueWithSeasonAndScoringUseCase', () => {
|
||||
if ('details' in err && err.details && typeof err.details === 'object' && 'message' in err.details) {
|
||||
expect(err.details.message).toContain('Ranked leagues require at least 10 drivers');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should return error when scoring preset is unknown', async () => {
|
||||
const command = {
|
||||
@@ -254,7 +248,7 @@ describe('CreateLeagueWithSeasonAndScoringUseCase', () => {
|
||||
if ('details' in err && err.details && typeof err.details === 'object' && 'message' in err.details) {
|
||||
expect(err.details.message).toBe('Unknown scoring preset: unknown-preset');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should return error when repository throws', async () => {
|
||||
const command = {
|
||||
@@ -285,5 +279,5 @@ describe('CreateLeagueWithSeasonAndScoringUseCase', () => {
|
||||
if ('details' in err && err.details && typeof err.details === 'object' && 'message' in err.details) {
|
||||
expect(err.details.message).toBe('DB error');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user