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

This commit is contained in:
2026-01-23 00:46:34 +01:00
parent eaf51712a7
commit a0f41f242f
53 changed files with 3214 additions and 8820 deletions

View File

@@ -0,0 +1,73 @@
import { describe, it, expect, beforeEach } from 'vitest';
import { DriversTestContext } from '../DriversTestContext';
import { Driver } from '../../../../core/racing/domain/entities/Driver';
describe('DriverStatsUseCase Integration', () => {
let context: DriversTestContext;
beforeEach(() => {
context = DriversTestContext.create();
context.clear();
});
describe('Success Path', () => {
it('should compute driver statistics from race results', async () => {
const driverId = 'd7';
const driver = Driver.create({ id: driverId, iracingId: '7', name: 'Stats Driver', country: 'US' });
await context.driverRepository.create(driver);
await context.driverStatsRepository.saveDriverStats(driverId, {
rating: 1800,
totalRaces: 15,
wins: 3,
podiums: 8,
overallRank: 5,
safetyRating: 4.2,
sportsmanshipRating: 90,
dnfs: 1,
avgFinish: 4.2,
bestFinish: 1,
worstFinish: 12,
consistency: 80,
experienceLevel: 'intermediate'
});
const stats = await context.driverStatsUseCase.getDriverStats(driverId);
expect(stats).not.toBeNull();
expect(stats!.rating).toBe(1800);
expect(stats!.totalRaces).toBe(15);
expect(stats!.wins).toBe(3);
expect(stats!.podiums).toBe(8);
expect(stats!.overallRank).toBe(5);
expect(stats!.safetyRating).toBe(4.2);
expect(stats!.sportsmanshipRating).toBe(90);
expect(stats!.dnfs).toBe(1);
expect(stats!.avgFinish).toBe(4.2);
expect(stats!.bestFinish).toBe(1);
expect(stats!.worstFinish).toBe(12);
expect(stats!.consistency).toBe(80);
expect(stats!.experienceLevel).toBe('intermediate');
});
it('should handle driver with no race results', async () => {
const driverId = 'd8';
const driver = Driver.create({ id: driverId, iracingId: '8', name: 'New Stats Driver', country: 'DE' });
await context.driverRepository.create(driver);
const stats = await context.driverStatsUseCase.getDriverStats(driverId);
expect(stats).toBeNull();
});
});
describe('Error Handling', () => {
it('should return null when driver does not exist', async () => {
const nonExistentDriverId = 'non-existent-driver';
const stats = await context.driverStatsUseCase.getDriverStats(nonExistentDriverId);
expect(stats).toBeNull();
});
});
});

View File

@@ -0,0 +1,91 @@
import { describe, it, expect, beforeEach } from 'vitest';
import { DriversTestContext } from '../DriversTestContext';
import { Driver } from '../../../../core/racing/domain/entities/Driver';
import { Team } from '../../../../core/racing/domain/entities/Team';
describe('GetProfileOverviewUseCase Integration', () => {
let context: DriversTestContext;
beforeEach(() => {
context = DriversTestContext.create();
context.clear();
});
describe('Success Path', () => {
it('should retrieve complete driver profile overview', async () => {
const driverId = 'd1';
const driver = Driver.create({ id: driverId, iracingId: '1', name: 'John Doe', country: 'US' });
await context.driverRepository.create(driver);
await context.driverStatsRepository.saveDriverStats(driverId, {
rating: 2000,
totalRaces: 10,
wins: 2,
podiums: 5,
overallRank: 1,
safetyRating: 4.5,
sportsmanshipRating: 95,
dnfs: 0,
avgFinish: 3.5,
bestFinish: 1,
worstFinish: 10,
consistency: 85,
experienceLevel: 'pro'
});
const team = Team.create({ id: 't1', name: 'Team 1', tag: 'T1', description: 'Desc', ownerId: 'other', leagues: [] });
await context.teamRepository.create(team);
await context.teamMembershipRepository.saveMembership({
teamId: 't1',
driverId: driverId,
role: 'driver',
status: 'active',
joinedAt: new Date()
});
context.socialRepository.seed({
drivers: [driver, Driver.create({ id: 'f1', iracingId: '2', name: 'Friend 1', country: 'UK' })],
friendships: [{ driverId: driverId, friendId: 'f1' }],
feedEvents: []
});
const result = await context.getProfileOverviewUseCase.execute({ driverId });
expect(result.isOk()).toBe(true);
const overview = result.unwrap();
expect(overview.driverInfo.driver.id).toBe(driverId);
expect(overview.stats?.rating).toBe(2000);
expect(overview.teamMemberships).toHaveLength(1);
expect(overview.teamMemberships[0].team.id).toBe('t1');
expect(overview.socialSummary.friendsCount).toBe(1);
expect(overview.extendedProfile).toBeDefined();
});
it('should handle driver with minimal data', async () => {
const driverId = 'new';
const driver = Driver.create({ id: driverId, iracingId: '9', name: 'New Driver', country: 'DE' });
await context.driverRepository.create(driver);
const result = await context.getProfileOverviewUseCase.execute({ driverId });
expect(result.isOk()).toBe(true);
const overview = result.unwrap();
expect(overview.driverInfo.driver.id).toBe(driverId);
expect(overview.stats).toBeNull();
expect(overview.teamMemberships).toHaveLength(0);
expect(overview.socialSummary.friendsCount).toBe(0);
});
});
describe('Error Handling', () => {
it('should return error when driver does not exist', async () => {
const result = await context.getProfileOverviewUseCase.execute({ driverId: 'none' });
expect(result.isErr()).toBe(true);
const error = result.unwrapErr();
expect(error.code).toBe('DRIVER_NOT_FOUND');
});
});
});

View File

@@ -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');
});
});
});