integration tests
Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m51s
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 4m51s
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,131 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { DriversTestContext } from '../DriversTestContext';
|
||||
import { Driver } from '../../../../core/racing/domain/entities/Driver';
|
||||
|
||||
describe('UpdateDriverProfileUseCase Integration', () => {
|
||||
let context: DriversTestContext;
|
||||
|
||||
beforeEach(() => {
|
||||
context = DriversTestContext.create();
|
||||
context.clear();
|
||||
});
|
||||
|
||||
describe('Success Path', () => {
|
||||
it('should update driver bio', async () => {
|
||||
const driverId = 'd2';
|
||||
const driver = Driver.create({ id: driverId, iracingId: '2', name: 'Update Driver', country: 'US', bio: 'Original bio' });
|
||||
await context.driverRepository.create(driver);
|
||||
|
||||
const result = await context.updateDriverProfileUseCase.execute({
|
||||
driverId,
|
||||
bio: 'Updated bio',
|
||||
});
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
|
||||
const updatedDriver = await context.driverRepository.findById(driverId);
|
||||
expect(updatedDriver).not.toBeNull();
|
||||
expect(updatedDriver!.bio?.toString()).toBe('Updated bio');
|
||||
});
|
||||
|
||||
it('should update driver country', async () => {
|
||||
const driverId = 'd3';
|
||||
const driver = Driver.create({ id: driverId, iracingId: '3', name: 'Country Driver', country: 'US' });
|
||||
await context.driverRepository.create(driver);
|
||||
|
||||
const result = await context.updateDriverProfileUseCase.execute({
|
||||
driverId,
|
||||
country: 'DE',
|
||||
});
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
|
||||
const updatedDriver = await context.driverRepository.findById(driverId);
|
||||
expect(updatedDriver).not.toBeNull();
|
||||
expect(updatedDriver!.country.toString()).toBe('DE');
|
||||
});
|
||||
|
||||
it('should update multiple profile fields at once', async () => {
|
||||
const driverId = 'd4';
|
||||
const driver = Driver.create({ id: driverId, iracingId: '4', name: 'Multi Update Driver', country: 'US', bio: 'Original bio' });
|
||||
await context.driverRepository.create(driver);
|
||||
|
||||
const result = await context.updateDriverProfileUseCase.execute({
|
||||
driverId,
|
||||
bio: 'Updated bio',
|
||||
country: 'FR',
|
||||
});
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
|
||||
const updatedDriver = await context.driverRepository.findById(driverId);
|
||||
expect(updatedDriver).not.toBeNull();
|
||||
expect(updatedDriver!.bio?.toString()).toBe('Updated bio');
|
||||
expect(updatedDriver!.country.toString()).toBe('FR');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Validation', () => {
|
||||
it('should reject update with empty bio', async () => {
|
||||
const driverId = 'd5';
|
||||
const driver = Driver.create({ id: driverId, iracingId: '5', name: 'Empty Bio Driver', country: 'US' });
|
||||
await context.driverRepository.create(driver);
|
||||
|
||||
const result = await context.updateDriverProfileUseCase.execute({
|
||||
driverId,
|
||||
bio: '',
|
||||
});
|
||||
|
||||
expect(result.isErr()).toBe(true);
|
||||
const error = result.unwrapErr();
|
||||
expect(error.code).toBe('INVALID_PROFILE_DATA');
|
||||
expect(error.details.message).toBe('Profile data is invalid');
|
||||
});
|
||||
|
||||
it('should reject update with empty country', async () => {
|
||||
const driverId = 'd6';
|
||||
const driver = Driver.create({ id: driverId, iracingId: '6', name: 'Empty Country Driver', country: 'US' });
|
||||
await context.driverRepository.create(driver);
|
||||
|
||||
const result = await context.updateDriverProfileUseCase.execute({
|
||||
driverId,
|
||||
country: '',
|
||||
});
|
||||
|
||||
expect(result.isErr()).toBe(true);
|
||||
const error = result.unwrapErr();
|
||||
expect(error.code).toBe('INVALID_PROFILE_DATA');
|
||||
expect(error.details.message).toBe('Profile data is invalid');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Error Handling', () => {
|
||||
it('should return error when driver does not exist', async () => {
|
||||
const nonExistentDriverId = 'non-existent-driver';
|
||||
|
||||
const result = await context.updateDriverProfileUseCase.execute({
|
||||
driverId: nonExistentDriverId,
|
||||
bio: 'New bio',
|
||||
});
|
||||
|
||||
expect(result.isErr()).toBe(true);
|
||||
const error = result.unwrapErr();
|
||||
expect(error.code).toBe('DRIVER_NOT_FOUND');
|
||||
expect(error.details.message).toContain('Driver with id');
|
||||
});
|
||||
|
||||
it('should return error when driver ID is invalid', async () => {
|
||||
const invalidDriverId = '';
|
||||
|
||||
const result = await context.updateDriverProfileUseCase.execute({
|
||||
driverId: invalidDriverId,
|
||||
bio: 'New bio',
|
||||
});
|
||||
|
||||
expect(result.isErr()).toBe(true);
|
||||
const error = result.unwrapErr();
|
||||
expect(error.code).toBe('DRIVER_NOT_FOUND');
|
||||
expect(error.details.message).toContain('Driver with id');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user