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
101 lines
2.5 KiB
TypeScript
101 lines
2.5 KiB
TypeScript
import { InMemoryActivityRepository } from './InMemoryActivityRepository';
|
|
import { DriverData } from '../../../../core/dashboard/application/ports/DashboardRepository';
|
|
|
|
describe('InMemoryActivityRepository', () => {
|
|
let repository: InMemoryActivityRepository;
|
|
|
|
beforeEach(() => {
|
|
repository = new InMemoryActivityRepository();
|
|
});
|
|
|
|
describe('findDriverById', () => {
|
|
it('should return null when driver does not exist', async () => {
|
|
// Given
|
|
const driverId = 'non-existent';
|
|
|
|
// When
|
|
const result = await repository.findDriverById(driverId);
|
|
|
|
// Then
|
|
expect(result).toBeNull();
|
|
});
|
|
|
|
it('should return driver when it exists', async () => {
|
|
// Given
|
|
const driver: DriverData = {
|
|
id: 'driver-1',
|
|
name: 'John Doe',
|
|
rating: 1500,
|
|
rank: 10,
|
|
starts: 100,
|
|
wins: 10,
|
|
podiums: 30,
|
|
leagues: 5,
|
|
};
|
|
repository.addDriver(driver);
|
|
|
|
// When
|
|
const result = await repository.findDriverById(driver.id);
|
|
|
|
// Then
|
|
expect(result).toEqual(driver);
|
|
});
|
|
|
|
it('should overwrite driver with same id (idempotency/uniqueness)', async () => {
|
|
// Given
|
|
const driverId = 'driver-1';
|
|
const driver1: DriverData = {
|
|
id: driverId,
|
|
name: 'John Doe',
|
|
rating: 1500,
|
|
rank: 10,
|
|
starts: 100,
|
|
wins: 10,
|
|
podiums: 30,
|
|
leagues: 5,
|
|
};
|
|
const driver2: DriverData = {
|
|
id: driverId,
|
|
name: 'John Updated',
|
|
rating: 1600,
|
|
rank: 5,
|
|
starts: 101,
|
|
wins: 11,
|
|
podiums: 31,
|
|
leagues: 5,
|
|
};
|
|
|
|
// When
|
|
repository.addDriver(driver1);
|
|
repository.addDriver(driver2);
|
|
const result = await repository.findDriverById(driverId);
|
|
|
|
// Then
|
|
expect(result).toEqual(driver2);
|
|
});
|
|
});
|
|
|
|
describe('upcomingRaces', () => {
|
|
it('should return empty array when no races for driver', async () => {
|
|
// When
|
|
const result = await repository.getUpcomingRaces('driver-1');
|
|
|
|
// Then
|
|
expect(result).toEqual([]);
|
|
});
|
|
|
|
it('should return races when they exist', async () => {
|
|
// Given
|
|
const driverId = 'driver-1';
|
|
const races = [{ id: 'race-1', name: 'Grand Prix', date: new Date().toISOString() }];
|
|
repository.addUpcomingRaces(driverId, races);
|
|
|
|
// When
|
|
const result = await repository.getUpcomingRaces(driverId);
|
|
|
|
// Then
|
|
expect(result).toEqual(races);
|
|
});
|
|
});
|
|
});
|