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,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');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user