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,51 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { LeaderboardsTestContext } from '../LeaderboardsTestContext';
|
||||
|
||||
describe('GetTeamRankingsUseCase - Data Orchestration', () => {
|
||||
let context: LeaderboardsTestContext;
|
||||
|
||||
beforeEach(() => {
|
||||
context = LeaderboardsTestContext.create();
|
||||
context.clear();
|
||||
});
|
||||
|
||||
it('should correctly calculate team rankings based on rating', async () => {
|
||||
const ratings = [4.9, 4.7, 4.6, 4.3, 4.1];
|
||||
ratings.forEach((rating, index) => {
|
||||
context.repository.addTeam({
|
||||
id: `team-${index}`,
|
||||
name: `Team ${index}`,
|
||||
rating,
|
||||
memberCount: 2 + index,
|
||||
raceCount: 20 + index,
|
||||
});
|
||||
});
|
||||
|
||||
const result = await context.getTeamRankingsUseCase.execute({});
|
||||
|
||||
expect(result.teams[0].rank).toBe(1);
|
||||
expect(result.teams[0].rating).toBe(4.9);
|
||||
expect(result.teams[4].rank).toBe(5);
|
||||
expect(result.teams[4].rating).toBe(4.1);
|
||||
});
|
||||
|
||||
it('should correctly aggregate member counts from drivers', async () => {
|
||||
// Scenario: Member count aggregation
|
||||
// Given: A team exists with 5 drivers
|
||||
// And: Each driver is affiliated with the team
|
||||
for (let i = 1; i <= 5; i++) {
|
||||
context.repository.addDriver({
|
||||
id: `driver-${i}`,
|
||||
name: `Driver ${i}`,
|
||||
rating: 5.0 - i * 0.1,
|
||||
teamId: 'team-1',
|
||||
teamName: 'Team 1',
|
||||
raceCount: 10,
|
||||
});
|
||||
}
|
||||
|
||||
const result = await context.getTeamRankingsUseCase.execute({});
|
||||
|
||||
expect(result.teams[0].memberCount).toBe(5);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,48 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { LeaderboardsTestContext } from '../LeaderboardsTestContext';
|
||||
|
||||
describe('GetTeamRankingsUseCase - Search & Filter', () => {
|
||||
let context: LeaderboardsTestContext;
|
||||
|
||||
beforeEach(() => {
|
||||
context = LeaderboardsTestContext.create();
|
||||
context.clear();
|
||||
});
|
||||
|
||||
describe('Search', () => {
|
||||
it('should search for teams by name', async () => {
|
||||
context.repository.addTeam({ id: 'team-1', name: 'Racing Team', rating: 4.9, memberCount: 5, raceCount: 100 });
|
||||
context.repository.addTeam({ id: 'team-2', name: 'Speed Squad', rating: 4.7, memberCount: 3, raceCount: 80 });
|
||||
|
||||
const result = await context.getTeamRankingsUseCase.execute({ search: 'Racing' });
|
||||
|
||||
expect(result.teams).toHaveLength(1);
|
||||
expect(result.teams[0].name).toBe('Racing Team');
|
||||
expect(context.eventPublisher.getTeamRankingsAccessedEventCount()).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Filter', () => {
|
||||
it('should filter teams by rating range', async () => {
|
||||
context.repository.addTeam({ id: 'team-1', name: 'Team A', rating: 3.5, memberCount: 2, raceCount: 20 });
|
||||
context.repository.addTeam({ id: 'team-2', name: 'Team B', rating: 4.0, memberCount: 2, raceCount: 20 });
|
||||
|
||||
const result = await context.getTeamRankingsUseCase.execute({ minRating: 4.0 });
|
||||
|
||||
expect(result.teams).toHaveLength(1);
|
||||
expect(result.teams[0].rating).toBe(4.0);
|
||||
expect(context.eventPublisher.getTeamRankingsAccessedEventCount()).toBe(1);
|
||||
});
|
||||
|
||||
it('should filter teams by member count', async () => {
|
||||
context.repository.addTeam({ id: 'team-1', name: 'Team A', rating: 4.9, memberCount: 2, raceCount: 20 });
|
||||
context.repository.addTeam({ id: 'team-2', name: 'Team B', rating: 4.7, memberCount: 5, raceCount: 20 });
|
||||
|
||||
const result = await context.getTeamRankingsUseCase.execute({ minMemberCount: 5 });
|
||||
|
||||
expect(result.teams).toHaveLength(1);
|
||||
expect(result.teams[0].memberCount).toBe(5);
|
||||
expect(context.eventPublisher.getTeamRankingsAccessedEventCount()).toBe(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,68 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { LeaderboardsTestContext } from '../LeaderboardsTestContext';
|
||||
|
||||
describe('GetTeamRankingsUseCase - Success Path', () => {
|
||||
let context: LeaderboardsTestContext;
|
||||
|
||||
beforeEach(() => {
|
||||
context = LeaderboardsTestContext.create();
|
||||
context.clear();
|
||||
});
|
||||
|
||||
it('should retrieve all teams with complete data', async () => {
|
||||
context.repository.addTeam({ id: 'team-1', name: 'Racing Team A', rating: 4.9, memberCount: 5, raceCount: 100 });
|
||||
context.repository.addTeam({ id: 'team-2', name: 'Speed Squad', rating: 4.7, memberCount: 3, raceCount: 80 });
|
||||
context.repository.addTeam({ id: 'team-3', name: 'Champions League', rating: 4.3, memberCount: 4, raceCount: 60 });
|
||||
|
||||
const result = await context.getTeamRankingsUseCase.execute({});
|
||||
|
||||
expect(result.teams).toHaveLength(3);
|
||||
expect(result.teams[0]).toMatchObject({
|
||||
rank: 1,
|
||||
id: 'team-1',
|
||||
name: 'Racing Team A',
|
||||
rating: 4.9,
|
||||
memberCount: 5,
|
||||
raceCount: 100,
|
||||
});
|
||||
expect(result.teams[0].rating).toBe(4.9);
|
||||
expect(result.teams[1].rating).toBe(4.7);
|
||||
expect(result.teams[2].rating).toBe(4.3);
|
||||
expect(context.eventPublisher.getTeamRankingsAccessedEventCount()).toBe(1);
|
||||
});
|
||||
|
||||
it('should retrieve teams with pagination', async () => {
|
||||
for (let i = 1; i <= 25; i++) {
|
||||
context.repository.addTeam({
|
||||
id: `team-${i}`,
|
||||
name: `Team ${i}`,
|
||||
rating: 5.0 - i * 0.1,
|
||||
memberCount: 2 + i,
|
||||
raceCount: 20 + i,
|
||||
});
|
||||
}
|
||||
|
||||
const result = await context.getTeamRankingsUseCase.execute({ page: 1, limit: 20 });
|
||||
|
||||
expect(result.teams).toHaveLength(20);
|
||||
expect(result.pagination.total).toBe(25);
|
||||
expect(result.pagination.page).toBe(1);
|
||||
expect(result.pagination.limit).toBe(20);
|
||||
expect(result.pagination.totalPages).toBe(2);
|
||||
expect(context.eventPublisher.getTeamRankingsAccessedEventCount()).toBe(1);
|
||||
});
|
||||
|
||||
it('should retrieve teams with accurate data', async () => {
|
||||
context.repository.addTeam({ id: 'team-1', name: 'Racing Team A', rating: 4.9, memberCount: 5, raceCount: 100 });
|
||||
|
||||
const result = await context.getTeamRankingsUseCase.execute({});
|
||||
|
||||
expect(result.teams[0].rating).toBeGreaterThan(0);
|
||||
expect(typeof result.teams[0].rating).toBe('number');
|
||||
expect(result.teams[0].rank).toBe(1);
|
||||
expect(result.teams[0].name).toBeTruthy();
|
||||
expect(typeof result.teams[0].name).toBe('string');
|
||||
expect(result.teams[0].memberCount).toBeGreaterThan(0);
|
||||
expect(context.eventPublisher.getTeamRankingsAccessedEventCount()).toBe(1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user