46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import type { Logger } from '@core/shared/domain/Logger';
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { InMemoryGameRepository } from './InMemoryGameRepository';
|
|
|
|
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.');
|
|
});
|
|
});
|
|
}); |