integration tests
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
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
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user