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,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