Files
gridpilot.gg/adapters/leagues/persistence/inmemory/InMemoryLeagueRepository.test.ts
Marc Mintel 838f1602de
Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m51s
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
adapter tests
2026-01-24 21:39:59 +01:00

128 lines
3.4 KiB
TypeScript

import { InMemoryLeagueRepository } from './InMemoryLeagueRepository';
import { LeagueData } from '../../../../core/leagues/application/ports/LeagueRepository';
describe('InMemoryLeagueRepository', () => {
let repository: InMemoryLeagueRepository;
beforeEach(() => {
repository = new InMemoryLeagueRepository();
});
const createLeague = (id: string, name: string, ownerId: string): LeagueData => ({
id,
name,
ownerId,
description: `Description for ${name}`,
visibility: 'public',
status: 'active',
createdAt: new Date(),
updatedAt: new Date(),
maxDrivers: 100,
approvalRequired: false,
lateJoinAllowed: true,
raceFrequency: 'weekly',
raceDay: 'Monday',
raceTime: '20:00',
tracks: ['Spa'],
scoringSystem: null,
bonusPointsEnabled: true,
penaltiesEnabled: true,
protestsEnabled: true,
appealsEnabled: true,
stewardTeam: [],
gameType: 'iRacing',
skillLevel: 'Intermediate',
category: 'Road',
tags: [],
});
describe('create and findById', () => {
it('should return null when league does not exist', async () => {
// When
const result = await repository.findById('non-existent');
// Then
expect(result).toBeNull();
});
it('should create and retrieve a league', async () => {
// Given
const league = createLeague('l1', 'League 1', 'o1');
// When
await repository.create(league);
const result = await repository.findById('l1');
// Then
expect(result).toEqual(league);
});
});
describe('findByName', () => {
it('should find a league by name', async () => {
// Given
const league = createLeague('l1', 'Unique Name', 'o1');
await repository.create(league);
// When
const result = await repository.findByName('Unique Name');
// Then
expect(result).toEqual(league);
});
});
describe('update', () => {
it('should update an existing league', async () => {
// Given
const league = createLeague('l1', 'Original Name', 'o1');
await repository.create(league);
// When
const updated = await repository.update('l1', { name: 'Updated Name' });
// Then
expect(updated.name).toBe('Updated Name');
const result = await repository.findById('l1');
expect(result?.name).toBe('Updated Name');
});
it('should throw error when updating non-existent league', async () => {
// When & Then
await expect(repository.update('non-existent', { name: 'New' })).rejects.toThrow();
});
});
describe('delete', () => {
it('should delete a league', async () => {
// Given
const league = createLeague('l1', 'To Delete', 'o1');
await repository.create(league);
// When
await repository.delete('l1');
// Then
const result = await repository.findById('l1');
expect(result).toBeNull();
});
});
describe('search', () => {
it('should find leagues by name or description', async () => {
// Given
const l1 = createLeague('l1', 'Formula 1', 'o1');
const l2 = createLeague('l2', 'GT3 Masters', 'o1');
await repository.create(l1);
await repository.create(l2);
// When
const results = await repository.search('Formula');
// Then
expect(results).toHaveLength(1);
expect(results[0].id).toBe('l1');
});
});
});