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

This commit is contained in:
2026-01-23 11:44:59 +01:00
parent a0f41f242f
commit 6df38a462a
125 changed files with 4712 additions and 19184 deletions

View File

@@ -0,0 +1,37 @@
import { describe, it, expect, beforeEach } from 'vitest';
import { ProfileTestContext } from '../ProfileTestContext';
import { GetDriverLiveriesUseCase } from '../../../../core/racing/application/use-cases/GetDriverLiveriesUseCase';
import { DriverLivery } from '../../../../core/racing/domain/entities/DriverLivery';
describe('GetDriverLiveriesUseCase', () => {
let context: ProfileTestContext;
let useCase: GetDriverLiveriesUseCase;
beforeEach(async () => {
context = new ProfileTestContext();
useCase = new GetDriverLiveriesUseCase(context.liveryRepository, context.logger);
await context.clear();
});
it('should retrieve driver liveries', async () => {
// Given: A driver has liveries
const driverId = 'd3';
const livery = DriverLivery.create({
id: 'l1',
driverId,
gameId: 'iracing',
carId: 'porsche_911_gt3_r',
uploadedImageUrl: 'https://example.com/livery.png'
});
await context.liveryRepository.createDriverLivery(livery);
// When: GetDriverLiveriesUseCase.execute() is called
const result = await useCase.execute({ driverId });
// Then: It should return the liveries
expect(result.isOk()).toBe(true);
const liveries = result.unwrap();
expect(liveries).toHaveLength(1);
expect(liveries[0].id).toBe('l1');
});
});

View File

@@ -0,0 +1,50 @@
import { describe, it, expect, beforeEach } from 'vitest';
import { ProfileTestContext } from '../ProfileTestContext';
import { GetLeagueMembershipsUseCase } from '../../../../core/racing/application/use-cases/GetLeagueMembershipsUseCase';
import { Driver } from '../../../../core/racing/domain/entities/Driver';
import { League } from '../../../../core/racing/domain/entities/League';
import { LeagueMembership } from '../../../../core/racing/domain/entities/LeagueMembership';
describe('GetLeagueMembershipsUseCase', () => {
let context: ProfileTestContext;
let useCase: GetLeagueMembershipsUseCase;
beforeEach(async () => {
context = new ProfileTestContext();
useCase = new GetLeagueMembershipsUseCase(
context.leagueMembershipRepository,
context.driverRepository,
context.leagueRepository
);
await context.clear();
});
it('should retrieve league memberships for a league', async () => {
// Given: A league with members
const leagueId = 'lg1';
const driverId = 'd4';
const league = League.create({ id: leagueId, name: 'League 1', description: 'Desc', ownerId: 'owner' });
await context.leagueRepository.create(league);
const membership = LeagueMembership.create({
id: 'm1',
leagueId,
driverId,
role: 'member',
status: 'active'
});
await context.leagueMembershipRepository.saveMembership(membership);
const driver = Driver.create({ id: driverId, iracingId: '4', name: 'Member Driver', country: 'US' });
await context.driverRepository.create(driver);
// When: GetLeagueMembershipsUseCase.execute() is called
const result = await useCase.execute({ leagueId });
// Then: It should return the memberships with driver info
expect(result.isOk()).toBe(true);
const data = result.unwrap();
expect(data.memberships).toHaveLength(1);
expect(data.memberships[0].driver?.id).toBe(driverId);
});
});

View File

@@ -0,0 +1,56 @@
import { describe, it, expect, beforeEach } from 'vitest';
import { ProfileTestContext } from '../ProfileTestContext';
import { GetPendingSponsorshipRequestsUseCase } from '../../../../core/racing/application/use-cases/GetPendingSponsorshipRequestsUseCase';
import { Sponsor } from '../../../../core/racing/domain/entities/sponsor/Sponsor';
import { SponsorshipRequest } from '../../../../core/racing/domain/entities/SponsorshipRequest';
import { Money } from '../../../../core/racing/domain/value-objects/Money';
describe('GetPendingSponsorshipRequestsUseCase', () => {
let context: ProfileTestContext;
let useCase: GetPendingSponsorshipRequestsUseCase;
beforeEach(async () => {
context = new ProfileTestContext();
useCase = new GetPendingSponsorshipRequestsUseCase(
context.sponsorshipRequestRepository,
context.sponsorRepository
);
await context.clear();
});
it('should retrieve pending sponsorship requests for a driver', async () => {
// Given: A driver has pending sponsorship requests
const driverId = 'd5';
const sponsorId = 's1';
const sponsor = Sponsor.create({
id: sponsorId,
name: 'Sponsor 1',
contactEmail: 'sponsor@example.com'
});
await context.sponsorRepository.create(sponsor);
const request = SponsorshipRequest.create({
id: 'sr1',
sponsorId,
entityType: 'driver',
entityId: driverId,
tier: 'main',
offeredAmount: Money.create(1000, 'USD')
});
await context.sponsorshipRequestRepository.create(request);
// When: GetPendingSponsorshipRequestsUseCase.execute() is called
const result = await useCase.execute({
entityType: 'driver',
entityId: driverId
});
// Then: It should return the pending requests
expect(result.isOk()).toBe(true);
const data = result.unwrap();
expect(data.requests).toHaveLength(1);
expect(data.requests[0].request.id).toBe('sr1');
expect(data.requests[0].sponsor?.id.toString()).toBe(sponsorId);
});
});

View File

@@ -0,0 +1,94 @@
import { describe, it, expect, beforeEach } from 'vitest';
import { ProfileTestContext } from '../ProfileTestContext';
import { GetProfileOverviewUseCase } from '../../../../core/racing/application/use-cases/GetProfileOverviewUseCase';
import { DriverStatsUseCase } from '../../../../core/racing/application/use-cases/DriverStatsUseCase';
import { RankingUseCase } from '../../../../core/racing/application/use-cases/RankingUseCase';
import { Driver } from '../../../../core/racing/domain/entities/Driver';
import { Team } from '../../../../core/racing/domain/entities/Team';
describe('GetProfileOverviewUseCase', () => {
let context: ProfileTestContext;
let useCase: GetProfileOverviewUseCase;
beforeEach(async () => {
context = new ProfileTestContext();
const driverStatsUseCase = new DriverStatsUseCase(
context.resultRepository,
context.standingRepository,
context.driverStatsRepository,
context.logger
);
const rankingUseCase = new RankingUseCase(
context.standingRepository,
context.driverRepository,
context.driverStatsRepository,
context.logger
);
useCase = new GetProfileOverviewUseCase(
context.driverRepository,
context.teamRepository,
context.teamMembershipRepository,
context.socialRepository,
context.driverExtendedProfileProvider,
driverStatsUseCase,
rankingUseCase
);
await context.clear();
});
it('should retrieve complete driver profile overview', async () => {
// Given: A driver exists with stats, team, and friends
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'
} as any);
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: []
});
// When: GetProfileOverviewUseCase.execute() is called
const result = await useCase.execute({ driverId });
// Then: The result should contain all profile sections
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.socialSummary.friendsCount).toBe(1);
});
it('should return error when driver does not exist', async () => {
const result = await useCase.execute({ driverId: 'non-existent' });
expect(result.isErr()).toBe(true);
expect((result.error as any).code).toBe('DRIVER_NOT_FOUND');
});
});

View File

@@ -0,0 +1,44 @@
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');
});
});