integration tests
Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m50s
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
Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m50s
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
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
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');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,67 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { OnboardingTestContext } from '../OnboardingTestContext';
|
||||
|
||||
describe('CompleteDriverOnboardingUseCase - Validation & Errors', () => {
|
||||
let context: OnboardingTestContext;
|
||||
|
||||
beforeEach(async () => {
|
||||
context = OnboardingTestContext.create();
|
||||
await context.clear();
|
||||
});
|
||||
|
||||
it('should reject onboarding if driver already exists', async () => {
|
||||
// Scenario: Already onboarded user
|
||||
// Given: A driver already exists for the user
|
||||
const userId = 'existing-user';
|
||||
const existingInput = {
|
||||
userId,
|
||||
firstName: 'Old',
|
||||
lastName: 'Name',
|
||||
displayName: 'OldRacer',
|
||||
country: 'DE',
|
||||
};
|
||||
await context.completeDriverOnboardingUseCase.execute(existingInput);
|
||||
|
||||
// When: CompleteDriverOnboardingUseCase.execute() is called again for same user
|
||||
const result = await context.completeDriverOnboardingUseCase.execute({
|
||||
userId,
|
||||
firstName: 'New',
|
||||
lastName: 'Name',
|
||||
displayName: 'NewRacer',
|
||||
country: 'FR',
|
||||
});
|
||||
|
||||
// Then: Should return DRIVER_ALREADY_EXISTS error
|
||||
expect(result.isErr()).toBe(true);
|
||||
const error = result.unwrapErr();
|
||||
expect(error.code).toBe('DRIVER_ALREADY_EXISTS');
|
||||
});
|
||||
|
||||
it('should handle repository errors gracefully', async () => {
|
||||
// Scenario: Repository error
|
||||
// Given: Repository throws an error
|
||||
const userId = 'error-user';
|
||||
const originalCreate = context.driverRepository.create.bind(context.driverRepository);
|
||||
context.driverRepository.create = async () => {
|
||||
throw new Error('Database failure');
|
||||
};
|
||||
|
||||
// When: CompleteDriverOnboardingUseCase.execute() is called
|
||||
const result = await context.completeDriverOnboardingUseCase.execute({
|
||||
userId,
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
displayName: 'RacerJohn',
|
||||
country: 'US',
|
||||
});
|
||||
|
||||
// Then: Should return REPOSITORY_ERROR
|
||||
expect(result.isErr()).toBe(true);
|
||||
const error = result.unwrapErr();
|
||||
expect(error.code).toBe('REPOSITORY_ERROR');
|
||||
expect(error.details.message).toBe('Database failure');
|
||||
|
||||
// Restore
|
||||
context.driverRepository.create = originalCreate;
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user