import { describe, it, expect, beforeEach } from 'vitest'; import { OnboardingTestContext } from '../OnboardingTestContext'; describe('CompleteDriverOnboardingUseCase - Success Path', () => { let context: OnboardingTestContext; beforeEach(async () => { context = OnboardingTestContext.create(); await context.clear(); }); it('should complete onboarding with valid personal info', async () => { // Scenario: Complete onboarding successfully // Given: A new user ID const userId = 'user-123'; const input = { userId, firstName: 'John', lastName: 'Doe', displayName: 'RacerJohn', country: 'US', bio: 'New racer on the grid', }; // When: CompleteDriverOnboardingUseCase.execute() is called const result = await context.completeDriverOnboardingUseCase.execute(input); // Then: Driver should be created expect(result.isOk()).toBe(true); const { driver } = result.unwrap(); expect(driver.id).toBe(userId); expect(driver.name.toString()).toBe('RacerJohn'); expect(driver.country.toString()).toBe('US'); expect(driver.bio?.toString()).toBe('New racer on the grid'); // And: Repository should contain the driver const savedDriver = await context.driverRepository.findById(userId); expect(savedDriver).not.toBeNull(); expect(savedDriver?.id).toBe(userId); }); it('should complete onboarding with minimal required data', async () => { // Scenario: Complete onboarding with minimal data // Given: A new user ID const userId = 'user-456'; const input = { userId, firstName: 'Jane', lastName: 'Smith', displayName: 'JaneS', country: 'UK', }; // When: CompleteDriverOnboardingUseCase.execute() is called const result = await context.completeDriverOnboardingUseCase.execute(input); // Then: Driver should be created successfully expect(result.isOk()).toBe(true); const { driver } = result.unwrap(); expect(driver.id).toBe(userId); expect(driver.bio).toBeUndefined(); }); 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 context.completeDriverOnboardingUseCase.execute(input); // Then: Bio should be saved expect(result.isOk()).toBe(true); expect(result.unwrap().driver.bio?.toString()).toBe('I build fast cars'); }); });