/** * Integration Test: Onboarding Personal Information Use Case Orchestration * * Tests the orchestration logic of personal information-related Use Cases: * - CompleteDriverOnboardingUseCase: Handles the initial driver profile creation * * Validates that Use Cases correctly interact with their Ports (Repositories) * Uses In-Memory adapters for fast, deterministic testing * * Focus: Business logic orchestration, NOT UI rendering */ import { describe, it, expect, beforeAll, beforeEach } from 'vitest'; import { InMemoryDriverRepository } from '../../../adapters/racing/persistence/inmemory/InMemoryDriverRepository'; import { CompleteDriverOnboardingUseCase } from '../../../core/racing/application/use-cases/CompleteDriverOnboardingUseCase'; import { Logger } from '../../../core/shared/domain/Logger'; describe('Onboarding Personal Information Use Case Orchestration', () => { let driverRepository: InMemoryDriverRepository; let completeDriverOnboardingUseCase: CompleteDriverOnboardingUseCase; let mockLogger: Logger; beforeAll(() => { mockLogger = { info: () => {}, debug: () => {}, warn: () => {}, error: () => {}, } as unknown as Logger; driverRepository = new InMemoryDriverRepository(mockLogger); completeDriverOnboardingUseCase = new CompleteDriverOnboardingUseCase( driverRepository, mockLogger ); }); beforeEach(async () => { await driverRepository.clear(); }); describe('CompleteDriverOnboardingUseCase - Personal Info Scenarios', () => { it('should create driver with valid personal information', async () => { // Scenario: Valid personal info // Given: A new user const input = { userId: 'user-789', firstName: 'Alice', lastName: 'Wonderland', displayName: 'AliceRacer', country: 'UK', }; // When: CompleteDriverOnboardingUseCase.execute() is called const result = await completeDriverOnboardingUseCase.execute(input); // Then: Validation should pass and driver be created expect(result.isOk()).toBe(true); const { driver } = result.unwrap(); expect(driver.name.toString()).toBe('AliceRacer'); expect(driver.country.toString()).toBe('UK'); }); it('should handle bio as optional personal information', async () => { // Scenario: Optional bio field // Given: Personal info with bio const input = { userId: 'user-bio', firstName: 'Bob', lastName: 'Builder', displayName: 'BobBuilds', country: 'AU', bio: 'I build fast cars', }; // When: CompleteDriverOnboardingUseCase.execute() is called const result = await completeDriverOnboardingUseCase.execute(input); // Then: Bio should be saved expect(result.isOk()).toBe(true); expect(result.unwrap().driver.bio?.toString()).toBe('I build fast cars'); }); }); });