Files
gridpilot.gg/tests/integration/profile/use-cases/UpdateDriverProfileUseCase.test.ts
Marc Mintel 6df38a462a
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
integration tests
2026-01-23 11:44:59 +01:00

45 lines
1.6 KiB
TypeScript

import { describe, it, expect, beforeEach } from 'vitest';
import { ProfileTestContext } from '../ProfileTestContext';
import { UpdateDriverProfileUseCase } from '../../../../core/racing/application/use-cases/UpdateDriverProfileUseCase';
import { Driver } from '../../../../core/racing/domain/entities/Driver';
describe('UpdateDriverProfileUseCase', () => {
let context: ProfileTestContext;
let useCase: UpdateDriverProfileUseCase;
beforeEach(async () => {
context = new ProfileTestContext();
useCase = new UpdateDriverProfileUseCase(context.driverRepository, context.logger);
await context.clear();
});
it('should update driver bio and country', async () => {
// Given: A driver exists
const driverId = 'd2';
const driver = Driver.create({ id: driverId, iracingId: '2', name: 'Update Driver', country: 'US' });
await context.driverRepository.create(driver);
// When: UpdateDriverProfileUseCase.execute() is called
const result = await useCase.execute({
driverId,
bio: 'New bio',
country: 'DE',
});
// Then: The driver should be updated
expect(result.isOk()).toBe(true);
const updatedDriver = await context.driverRepository.findById(driverId);
expect(updatedDriver?.bio?.toString()).toBe('New bio');
expect(updatedDriver?.country.toString()).toBe('DE');
});
it('should return error when driver does not exist', async () => {
const result = await useCase.execute({
driverId: 'non-existent',
bio: 'New bio',
});
expect(result.isErr()).toBe(true);
expect((result.error as any).code).toBe('DRIVER_NOT_FOUND');
});
});