Some checks failed
CI / lint-typecheck (pull_request) Failing after 12s
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
56 lines
2.2 KiB
TypeScript
56 lines
2.2 KiB
TypeScript
import { describe, it, expect, beforeEach } from 'vitest';
|
|
import { TeamsTestContext } from '../TeamsTestContext';
|
|
import { Team } from '../../../../core/racing/domain/entities/Team';
|
|
|
|
describe('GetAllTeamsUseCase', () => {
|
|
const context = new TeamsTestContext();
|
|
const getAllTeamsUseCase = context.createGetAllTeamsUseCase();
|
|
|
|
beforeEach(() => {
|
|
context.clear();
|
|
});
|
|
|
|
describe('Success Path', () => {
|
|
it('should retrieve complete teams list with all teams and enrichment', async () => {
|
|
const team1 = Team.create({ id: 't1', name: 'Team 1', tag: 'T1', description: 'Desc 1', ownerId: 'o1', leagues: [] });
|
|
const team2 = Team.create({ id: 't2', name: 'Team 2', tag: 'T2', description: 'Desc 2', 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: 't1', driverId: 'd2', role: 'driver', status: 'active', joinedAt: new Date() });
|
|
await context.membershipRepository.saveMembership({ teamId: 't2', driverId: 'd3', role: 'owner', status: 'active', joinedAt: new Date() });
|
|
|
|
await context.statsRepository.saveTeamStats('t1', {
|
|
totalWins: 5,
|
|
totalRaces: 20,
|
|
rating: 1500,
|
|
performanceLevel: 'intermediate',
|
|
specialization: 'sprint',
|
|
region: 'EU',
|
|
languages: ['en']
|
|
});
|
|
|
|
const result = await getAllTeamsUseCase.execute({});
|
|
|
|
expect(result.isOk()).toBe(true);
|
|
const { teams, totalCount } = result.unwrap();
|
|
expect(totalCount).toBe(2);
|
|
|
|
const enriched1 = teams.find(t => t.team.id.toString() === 't1');
|
|
expect(enriched1?.memberCount).toBe(2);
|
|
expect(enriched1?.totalWins).toBe(5);
|
|
expect(enriched1?.rating).toBe(1500);
|
|
});
|
|
|
|
it('should handle empty teams list', async () => {
|
|
const result = await getAllTeamsUseCase.execute({});
|
|
|
|
expect(result.isOk()).toBe(true);
|
|
const { teams, totalCount } = result.unwrap();
|
|
expect(totalCount).toBe(0);
|
|
expect(teams).toHaveLength(0);
|
|
});
|
|
});
|
|
});
|