Files
gridpilot.gg/adapters/racing/persistence/inmemory/InMemoryGameRepository.test.ts
2025-12-27 11:58:35 +01:00

46 lines
1.5 KiB
TypeScript

import { vi, describe, it, expect, beforeEach } from 'vitest';
import { InMemoryGameRepository } from './InMemoryGameRepository';
import type { Logger } from '@core/shared/application';
describe('InMemoryGameRepository', () => {
let repository: InMemoryGameRepository;
let mockLogger: Logger;
beforeEach(() => {
mockLogger = {
debug: vi.fn(),
info: vi.fn(),
warn: vi.fn(),
error: vi.fn(),
};
repository = new InMemoryGameRepository(mockLogger);
});
describe('constructor', () => {
it('should initialize with a logger', () => {
expect(repository).toBeDefined();
expect(mockLogger.info).toHaveBeenCalledWith('InMemoryGameRepository initialized.');
});
});
describe('findById', () => {
it('should return null if game not found', async () => {
const result = await repository.findById('nonexistent');
expect(result).toBeNull();
expect(mockLogger.debug).toHaveBeenCalledWith('[InMemoryGameRepository] Finding game by ID: nonexistent');
expect(mockLogger.warn).toHaveBeenCalledWith('Game with ID nonexistent not found.');
});
});
describe('findAll', () => {
it('should return default seeded games', async () => {
const result = await repository.findAll();
const ids = result.map((g) => g.id.toString());
expect(ids).toEqual(expect.arrayContaining(['iracing', 'acc', 'f1-24', 'f1-23']));
expect(result).toHaveLength(4);
expect(mockLogger.debug).toHaveBeenCalledWith('[InMemoryGameRepository] Finding all games.');
});
});
});