fix issues in core

This commit is contained in:
2025-12-23 11:25:08 +01:00
parent 1efd971032
commit 2854ae3c5c
113 changed files with 1142 additions and 458 deletions

View File

@@ -89,10 +89,10 @@ describe('CreateLeagueWithSeasonAndScoringUseCase', () => {
expect(result.unwrap()).toBeUndefined();
expect(output.present).toHaveBeenCalledTimes(1);
const presented = output.present.mock.calls[0][0] as CreateLeagueWithSeasonAndScoringResult;
expect(presented.league.id.toString()).toBeDefined();
expect(presented.season.id).toBeDefined();
expect(presented.scoringConfig.seasonId.toString()).toBe(presented.season.id);
const presented = (output.present as Mock).mock.calls[0]?.[0] as unknown as CreateLeagueWithSeasonAndScoringResult;
expect(presented?.league.id.toString()).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);
@@ -114,8 +114,11 @@ describe('CreateLeagueWithSeasonAndScoringUseCase', () => {
const result = await useCase.execute(command);
expect(result.isErr()).toBe(true);
expect(result.unwrapErr().code).toBe('VALIDATION_ERROR');
expect(result.unwrapErr().details?.message).toBe('League name is required');
const err = result.unwrapErr();
expect(err.code).toBe('VALIDATION_ERROR');
if ('details' in err && err.details && typeof err.details === 'object' && 'message' in err.details) {
expect(err.details.message).toBe('League name is required');
}
expect(output.present).not.toHaveBeenCalled();
});
@@ -135,8 +138,11 @@ describe('CreateLeagueWithSeasonAndScoringUseCase', () => {
const result = await useCase.execute(command as CreateLeagueWithSeasonAndScoringCommand);
expect(result.isErr()).toBe(true);
expect(result.unwrapErr().code).toBe('VALIDATION_ERROR');
expect(result.unwrapErr().details?.message).toBe('League ownerId is required');
const err = result.unwrapErr();
expect(err.code).toBe('VALIDATION_ERROR');
if ('details' in err && err.details && typeof err.details === 'object' && 'message' in err.details) {
expect(err.details.message).toBe('League ownerId is required');
}
expect(output.present).not.toHaveBeenCalled();
});
@@ -157,7 +163,7 @@ describe('CreateLeagueWithSeasonAndScoringUseCase', () => {
expect(result.isErr()).toBe(true);
expect(result.unwrapErr().code).toBe('VALIDATION_ERROR');
expect(result.unwrapErr().details?.message).toBe('gameId is required');
expect((result.unwrapErr() as any).details.message).toBe('gameId is required');
expect(output.present).not.toHaveBeenCalled();
});
@@ -175,8 +181,11 @@ describe('CreateLeagueWithSeasonAndScoringUseCase', () => {
const result = await useCase.execute(command as CreateLeagueWithSeasonAndScoringCommand);
expect(result.isErr()).toBe(true);
expect(result.unwrapErr().code).toBe('VALIDATION_ERROR');
expect(result.unwrapErr().details?.message).toBe('visibility is required');
const err = result.unwrapErr();
expect(err.code).toBe('VALIDATION_ERROR');
if ('details' in err && err.details && typeof err.details === 'object' && 'message' in err.details) {
expect(err.details.message).toBe('visibility is required');
}
expect(output.present).not.toHaveBeenCalled();
});
@@ -197,8 +206,11 @@ describe('CreateLeagueWithSeasonAndScoringUseCase', () => {
const result = await useCase.execute(command);
expect(result.isErr()).toBe(true);
expect(result.unwrapErr().code).toBe('VALIDATION_ERROR');
expect(result.unwrapErr().details?.message).toBe('maxDrivers must be greater than 0 when provided');
const err = result.unwrapErr();
expect(err.code).toBe('VALIDATION_ERROR');
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');
}
expect(output.present).not.toHaveBeenCalled();
});
@@ -219,8 +231,11 @@ describe('CreateLeagueWithSeasonAndScoringUseCase', () => {
const result = await useCase.execute(command);
expect(result.isErr()).toBe(true);
expect(result.unwrapErr().code).toBe('VALIDATION_ERROR');
expect(result.unwrapErr().details?.message).toContain('Ranked leagues require at least 10 drivers');
const err = result.unwrapErr();
expect(err.code).toBe('VALIDATION_ERROR');
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');
}
expect(output.present).not.toHaveBeenCalled();
});
@@ -243,8 +258,11 @@ describe('CreateLeagueWithSeasonAndScoringUseCase', () => {
const result = await useCase.execute(command);
expect(result.isErr()).toBe(true);
expect(result.unwrapErr().code).toBe('UNKNOWN_PRESET');
expect(result.unwrapErr().details?.message).toBe('Unknown scoring preset: unknown-preset');
const err = result.unwrapErr();
expect(err.code).toBe('UNKNOWN_PRESET');
if ('details' in err && err.details && typeof err.details === 'object' && 'message' in err.details) {
expect(err.details.message).toBe('Unknown scoring preset: unknown-preset');
}
expect(output.present).not.toHaveBeenCalled();
});
@@ -272,8 +290,11 @@ describe('CreateLeagueWithSeasonAndScoringUseCase', () => {
const result = await useCase.execute(command);
expect(result.isErr()).toBe(true);
expect(result.unwrapErr().code).toBe('REPOSITORY_ERROR');
expect(result.unwrapErr().details?.message).toBe('DB error');
const err = result.unwrapErr();
expect(err.code).toBe('REPOSITORY_ERROR');
if ('details' in err && err.details && typeof err.details === 'object' && 'message' in err.details) {
expect(err.details.message).toBe('DB error');
}
expect(output.present).not.toHaveBeenCalled();
});
});