Files
gridpilot.gg/tests/integration/leagues/creation/league-create-error.test.ts
Marc Mintel 6df38a462a
Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m50s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
integration tests
2026-01-23 11:44:59 +01:00

70 lines
2.4 KiB
TypeScript

import { describe, it, expect, beforeEach } from 'vitest';
import { LeaguesTestContext } from '../LeaguesTestContext';
import { LeagueCreateCommand } from '../../../../core/leagues/application/ports/LeagueCreateCommand';
import { InMemoryLeagueRepository } from '../../../../adapters/leagues/persistence/inmemory/InMemoryLeagueRepository';
import { CreateLeagueUseCase } from '../../../../core/leagues/application/use-cases/CreateLeagueUseCase';
describe('League Creation - Error Handling', () => {
let context: LeaguesTestContext;
beforeEach(() => {
context = new LeaguesTestContext();
context.clear();
});
it('should throw error when driver ID is invalid', async () => {
const command: LeagueCreateCommand = {
name: 'Test League',
visibility: 'public',
ownerId: '',
approvalRequired: false,
lateJoinAllowed: false,
bonusPointsEnabled: false,
penaltiesEnabled: false,
protestsEnabled: false,
appealsEnabled: false,
};
await expect(context.createLeagueUseCase.execute(command)).rejects.toThrow('Owner ID is required');
expect(context.eventPublisher.getLeagueCreatedEventCount()).toBe(0);
});
it('should throw error when league name is empty', async () => {
const command: LeagueCreateCommand = {
name: '',
visibility: 'public',
ownerId: 'driver-123',
approvalRequired: false,
lateJoinAllowed: false,
bonusPointsEnabled: false,
penaltiesEnabled: false,
protestsEnabled: false,
appealsEnabled: false,
};
await expect(context.createLeagueUseCase.execute(command)).rejects.toThrow();
expect(context.eventPublisher.getLeagueCreatedEventCount()).toBe(0);
});
it('should throw error when repository throws error', async () => {
const errorRepo = new InMemoryLeagueRepository();
errorRepo.create = async () => { throw new Error('Database error'); };
const errorUseCase = new CreateLeagueUseCase(errorRepo, context.eventPublisher);
const command: LeagueCreateCommand = {
name: 'Test League',
visibility: 'public',
ownerId: 'driver-123',
approvalRequired: false,
lateJoinAllowed: false,
bonusPointsEnabled: false,
penaltiesEnabled: false,
protestsEnabled: false,
appealsEnabled: false,
};
await expect(errorUseCase.execute(command)).rejects.toThrow('Database error');
expect(context.eventPublisher.getLeagueCreatedEventCount()).toBe(0);
});
});