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
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:
@@ -0,0 +1,54 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { TeamsTestContext } from '../TeamsTestContext';
|
||||
import { Team } from '../../../../core/racing/domain/entities/Team';
|
||||
|
||||
describe('GetTeamsLeaderboardUseCase', () => {
|
||||
const context = new TeamsTestContext();
|
||||
|
||||
// Mock driver stats provider
|
||||
const getDriverStats = (driverId: string) => {
|
||||
const statsMap: Record<string, { rating: number, wins: number, totalRaces: number }> = {
|
||||
'd1': { rating: 2000, wins: 10, totalRaces: 50 },
|
||||
'd2': { rating: 1500, wins: 5, totalRaces: 30 },
|
||||
'd3': { rating: 1000, wins: 2, totalRaces: 20 },
|
||||
};
|
||||
return statsMap[driverId] || null;
|
||||
};
|
||||
|
||||
const getTeamsLeaderboardUseCase = context.createGetTeamsLeaderboardUseCase(getDriverStats);
|
||||
|
||||
beforeEach(() => {
|
||||
context.clear();
|
||||
});
|
||||
|
||||
describe('Success Path', () => {
|
||||
it('should retrieve ranked team leaderboard with performance metrics', async () => {
|
||||
const team1 = Team.create({ id: 't1', name: 'Pro Team', tag: 'PRO', description: 'Desc', ownerId: 'o1', leagues: [] });
|
||||
const team2 = Team.create({ id: 't2', name: 'Am Team', tag: 'AM', description: 'Desc', ownerId: 'o2', leagues: [] });
|
||||
await context.teamRepository.create(team1);
|
||||
await context.teamRepository.create(team2);
|
||||
|
||||
await context.membershipRepository.saveMembership({ teamId: 't1', driverId: 'd1', role: 'owner', status: 'active', joinedAt: new Date() });
|
||||
await context.membershipRepository.saveMembership({ teamId: 't2', driverId: 'd3', role: 'owner', status: 'active', joinedAt: new Date() });
|
||||
|
||||
const result = await getTeamsLeaderboardUseCase.execute({ leagueId: 'any' });
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
const { items, topItems } = result.unwrap();
|
||||
expect(items).toHaveLength(2);
|
||||
|
||||
expect(topItems[0]?.team.id.toString()).toBe('t1');
|
||||
expect(topItems[0]?.rating).toBe(2000);
|
||||
expect(topItems[1]?.team.id.toString()).toBe('t2');
|
||||
expect(topItems[1]?.rating).toBe(1000);
|
||||
});
|
||||
|
||||
it('should handle empty leaderboard', async () => {
|
||||
const result = await getTeamsLeaderboardUseCase.execute({ leagueId: 'any' });
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
const { items } = result.unwrap();
|
||||
expect(items).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user