Some checks failed
CI / lint-typecheck (pull_request) Failing after 12s
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
284 lines
9.4 KiB
TypeScript
284 lines
9.4 KiB
TypeScript
import { describe, it, expect, beforeEach } from 'vitest';
|
|
import { DriversTestContext } from '../DriversTestContext';
|
|
import { Driver } from '../../../../core/racing/domain/entities/Driver';
|
|
import { MediaReference } from '../../../../core/domain/media/MediaReference';
|
|
|
|
describe('GetDriverUseCase Integration', () => {
|
|
let context: DriversTestContext;
|
|
|
|
beforeEach(() => {
|
|
context = DriversTestContext.create();
|
|
context.clear();
|
|
});
|
|
|
|
describe('Success Path', () => {
|
|
it('should retrieve complete driver with all data', async () => {
|
|
const driverId = 'driver-123';
|
|
const driver = Driver.create({
|
|
id: driverId,
|
|
iracingId: '12345',
|
|
name: 'John Doe',
|
|
country: 'US',
|
|
bio: 'A passionate racer with 10 years of experience',
|
|
avatarRef: MediaReference.createUploaded('avatar-123'),
|
|
});
|
|
|
|
await context.driverRepository.create(driver);
|
|
|
|
const result = await context.getDriverUseCase.execute({ driverId });
|
|
|
|
expect(result.isOk()).toBe(true);
|
|
const retrievedDriver = result.unwrap()!;
|
|
|
|
expect(retrievedDriver.id).toBe(driverId);
|
|
expect(retrievedDriver.iracingId.toString()).toBe('12345');
|
|
expect(retrievedDriver.name.toString()).toBe('John Doe');
|
|
expect(retrievedDriver.country.toString()).toBe('US');
|
|
expect(retrievedDriver.bio?.toString()).toBe('A passionate racer with 10 years of experience');
|
|
expect(retrievedDriver.avatarRef).toBeDefined();
|
|
});
|
|
|
|
it('should retrieve driver with minimal data', async () => {
|
|
const driverId = 'driver-456';
|
|
const driver = Driver.create({
|
|
id: driverId,
|
|
iracingId: '67890',
|
|
name: 'Jane Smith',
|
|
country: 'UK',
|
|
});
|
|
|
|
await context.driverRepository.create(driver);
|
|
|
|
const result = await context.getDriverUseCase.execute({ driverId });
|
|
|
|
expect(result.isOk()).toBe(true);
|
|
const retrievedDriver = result.unwrap()!;
|
|
|
|
expect(retrievedDriver.id).toBe(driverId);
|
|
expect(retrievedDriver.iracingId.toString()).toBe('67890');
|
|
expect(retrievedDriver.name.toString()).toBe('Jane Smith');
|
|
expect(retrievedDriver.country.toString()).toBe('UK');
|
|
expect(retrievedDriver.bio).toBeUndefined();
|
|
expect(retrievedDriver.avatarRef).toBeDefined();
|
|
});
|
|
|
|
it('should retrieve driver with bio but no avatar', async () => {
|
|
const driverId = 'driver-789';
|
|
const driver = Driver.create({
|
|
id: driverId,
|
|
iracingId: '11111',
|
|
name: 'Bob Johnson',
|
|
country: 'CA',
|
|
bio: 'Canadian racer',
|
|
});
|
|
|
|
await context.driverRepository.create(driver);
|
|
|
|
const result = await context.getDriverUseCase.execute({ driverId });
|
|
|
|
expect(result.isOk()).toBe(true);
|
|
const retrievedDriver = result.unwrap()!;
|
|
|
|
expect(retrievedDriver.id).toBe(driverId);
|
|
expect(retrievedDriver.bio?.toString()).toBe('Canadian racer');
|
|
expect(retrievedDriver.avatarRef).toBeDefined();
|
|
});
|
|
|
|
it('should retrieve driver with avatar but no bio', async () => {
|
|
const driverId = 'driver-999';
|
|
const driver = Driver.create({
|
|
id: driverId,
|
|
iracingId: '22222',
|
|
name: 'Alice Brown',
|
|
country: 'DE',
|
|
avatarRef: MediaReference.createUploaded('avatar-999'),
|
|
});
|
|
|
|
await context.driverRepository.create(driver);
|
|
|
|
const result = await context.getDriverUseCase.execute({ driverId });
|
|
|
|
expect(result.isOk()).toBe(true);
|
|
const retrievedDriver = result.unwrap()!;
|
|
|
|
expect(retrievedDriver.id).toBe(driverId);
|
|
expect(retrievedDriver.bio).toBeUndefined();
|
|
expect(retrievedDriver.avatarRef).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Edge Cases', () => {
|
|
it('should handle driver with no bio', async () => {
|
|
const driverId = 'driver-no-bio';
|
|
const driver = Driver.create({
|
|
id: driverId,
|
|
iracingId: '33333',
|
|
name: 'No Bio Driver',
|
|
country: 'FR',
|
|
});
|
|
|
|
await context.driverRepository.create(driver);
|
|
|
|
const result = await context.getDriverUseCase.execute({ driverId });
|
|
|
|
expect(result.isOk()).toBe(true);
|
|
const retrievedDriver = result.unwrap()!;
|
|
|
|
expect(retrievedDriver.id).toBe(driverId);
|
|
expect(retrievedDriver.bio).toBeUndefined();
|
|
});
|
|
|
|
it('should handle driver with no avatar', async () => {
|
|
const driverId = 'driver-no-avatar';
|
|
const driver = Driver.create({
|
|
id: driverId,
|
|
iracingId: '44444',
|
|
name: 'No Avatar Driver',
|
|
country: 'ES',
|
|
});
|
|
|
|
await context.driverRepository.create(driver);
|
|
|
|
const result = await context.getDriverUseCase.execute({ driverId });
|
|
|
|
expect(result.isOk()).toBe(true);
|
|
const retrievedDriver = result.unwrap()!;
|
|
|
|
expect(retrievedDriver.id).toBe(driverId);
|
|
expect(retrievedDriver.avatarRef).toBeDefined();
|
|
});
|
|
|
|
it('should handle driver with no data at all', async () => {
|
|
const driverId = 'driver-minimal';
|
|
const driver = Driver.create({
|
|
id: driverId,
|
|
iracingId: '55555',
|
|
name: 'Minimal Driver',
|
|
country: 'IT',
|
|
});
|
|
|
|
await context.driverRepository.create(driver);
|
|
|
|
const result = await context.getDriverUseCase.execute({ driverId });
|
|
|
|
expect(result.isOk()).toBe(true);
|
|
const retrievedDriver = result.unwrap()!;
|
|
|
|
expect(retrievedDriver.id).toBe(driverId);
|
|
expect(retrievedDriver.iracingId.toString()).toBe('55555');
|
|
expect(retrievedDriver.name.toString()).toBe('Minimal Driver');
|
|
expect(retrievedDriver.country.toString()).toBe('IT');
|
|
expect(retrievedDriver.bio).toBeUndefined();
|
|
expect(retrievedDriver.avatarRef).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Error Handling', () => {
|
|
it('should return null when driver does not exist', async () => {
|
|
const driverId = 'non-existent-driver';
|
|
|
|
const result = await context.getDriverUseCase.execute({ driverId });
|
|
|
|
expect(result.isOk()).toBe(true);
|
|
expect(result.unwrap()).toBeNull();
|
|
});
|
|
|
|
it('should handle repository errors gracefully', async () => {
|
|
const driverId = 'driver-error';
|
|
const driver = Driver.create({
|
|
id: driverId,
|
|
iracingId: '66666',
|
|
name: 'Error Driver',
|
|
country: 'US',
|
|
});
|
|
|
|
await context.driverRepository.create(driver);
|
|
|
|
const originalFindById = context.driverRepository.findById.bind(context.driverRepository);
|
|
context.driverRepository.findById = async () => {
|
|
throw new Error('Repository error');
|
|
};
|
|
|
|
const result = await context.getDriverUseCase.execute({ driverId });
|
|
|
|
expect(result.isErr()).toBe(true);
|
|
const error = result.unwrapErr();
|
|
expect(error.message).toBe('Repository error');
|
|
|
|
context.driverRepository.findById = originalFindById;
|
|
});
|
|
});
|
|
|
|
describe('Data Orchestration', () => {
|
|
it('should correctly retrieve driver with all fields populated', async () => {
|
|
const driverId = 'driver-complete';
|
|
const driver = Driver.create({
|
|
id: driverId,
|
|
iracingId: '77777',
|
|
name: 'Complete Driver',
|
|
country: 'US',
|
|
bio: 'Complete driver profile with all fields',
|
|
avatarRef: MediaReference.createUploaded('avatar-complete'),
|
|
category: 'pro',
|
|
});
|
|
|
|
await context.driverRepository.create(driver);
|
|
|
|
const result = await context.getDriverUseCase.execute({ driverId });
|
|
|
|
expect(result.isOk()).toBe(true);
|
|
const retrievedDriver = result.unwrap()!;
|
|
|
|
expect(retrievedDriver.id).toBe(driverId);
|
|
expect(retrievedDriver.iracingId.toString()).toBe('77777');
|
|
expect(retrievedDriver.name.toString()).toBe('Complete Driver');
|
|
expect(retrievedDriver.country.toString()).toBe('US');
|
|
expect(retrievedDriver.bio?.toString()).toBe('Complete driver profile with all fields');
|
|
expect(retrievedDriver.avatarRef).toBeDefined();
|
|
expect(retrievedDriver.category).toBe('pro');
|
|
});
|
|
|
|
it('should correctly retrieve driver with system-default avatar', async () => {
|
|
const driverId = 'driver-system-avatar';
|
|
const driver = Driver.create({
|
|
id: driverId,
|
|
iracingId: '88888',
|
|
name: 'System Avatar Driver',
|
|
country: 'US',
|
|
avatarRef: MediaReference.createSystemDefault('avatar'),
|
|
});
|
|
|
|
await context.driverRepository.create(driver);
|
|
|
|
const result = await context.getDriverUseCase.execute({ driverId });
|
|
|
|
expect(result.isOk()).toBe(true);
|
|
const retrievedDriver = result.unwrap()!;
|
|
|
|
expect(retrievedDriver.avatarRef).toBeDefined();
|
|
expect(retrievedDriver.avatarRef.type).toBe('system-default');
|
|
});
|
|
|
|
it('should correctly retrieve driver with generated avatar', async () => {
|
|
const driverId = 'driver-generated-avatar';
|
|
const driver = Driver.create({
|
|
id: driverId,
|
|
iracingId: '99999',
|
|
name: 'Generated Avatar Driver',
|
|
country: 'US',
|
|
avatarRef: MediaReference.createGenerated('gen-123'),
|
|
});
|
|
|
|
await context.driverRepository.create(driver);
|
|
|
|
const result = await context.getDriverUseCase.execute({ driverId });
|
|
|
|
expect(result.isOk()).toBe(true);
|
|
const retrievedDriver = result.unwrap()!;
|
|
|
|
expect(retrievedDriver.avatarRef).toBeDefined();
|
|
expect(retrievedDriver.avatarRef.type).toBe('generated');
|
|
});
|
|
});
|
|
});
|