import { describe, it, expect, beforeEach } from 'vitest'; import { ProfileTestContext } from '../ProfileTestContext'; import { UpdateDriverProfileUseCase } from '../../../../core/racing/application/use-cases/UpdateDriverProfileUseCase'; import { Driver } from '../../../../core/racing/domain/entities/Driver'; describe('UpdateDriverProfileUseCase', () => { let context: ProfileTestContext; let useCase: UpdateDriverProfileUseCase; beforeEach(async () => { context = new ProfileTestContext(); useCase = new UpdateDriverProfileUseCase(context.driverRepository, context.logger); await context.clear(); }); it('should update driver bio and country', async () => { // Given: A driver exists const driverId = 'd2'; const driver = Driver.create({ id: driverId, iracingId: '2', name: 'Update Driver', country: 'US' }); await context.driverRepository.create(driver); // When: UpdateDriverProfileUseCase.execute() is called const result = await useCase.execute({ driverId, bio: 'New bio', country: 'DE', }); // Then: The driver should be updated expect(result.isOk()).toBe(true); const updatedDriver = await context.driverRepository.findById(driverId); expect(updatedDriver?.bio?.toString()).toBe('New bio'); expect(updatedDriver?.country.toString()).toBe('DE'); }); it('should return error when driver does not exist', async () => { const result = await useCase.execute({ driverId: 'non-existent', bio: 'New bio', }); expect(result.isErr()).toBe(true); expect((result.error as any).code).toBe('DRIVER_NOT_FOUND'); }); });