Files
gridpilot.gg/tests/integration/leagues/sponsorships/SponsorshipManagement.test.ts
2026-01-23 14:51:33 +01:00

117 lines
3.7 KiB
TypeScript

import { beforeEach, describe, expect, it } from 'vitest';
import { LeaguesTestContext } from '../LeaguesTestContext';
import { League } from '../../../../core/racing/domain/entities/League';
import { Season } from '../../../../core/racing/domain/entities/season/Season';
import { SeasonSponsorship } from '../../../../core/racing/domain/entities/season/SeasonSponsorship';
import { Money } from '../../../../core/racing/domain/value-objects/Money';
describe('League Sponsorships - Sponsorship Management', () => {
let context: LeaguesTestContext;
beforeEach(() => {
context = new LeaguesTestContext();
context.clear();
});
const seedLeagueAndSeason = async (params: { leagueId: string; seasonId: string }) => {
const league = League.create({
id: params.leagueId,
name: 'League 1',
description: 'League used for sponsorship integration tests',
ownerId: 'owner-1',
});
await context.racingLeagueRepository.create(league);
const season = Season.create({
id: params.seasonId,
leagueId: params.leagueId,
gameId: 'iracing',
name: 'Season 1',
status: 'active',
startDate: new Date('2025-01-01T00:00:00.000Z'),
endDate: new Date('2025-02-01T00:00:00.000Z'),
});
await context.seasonRepository.create(season);
return { league, season };
};
it('adds a season sponsorship to the repository', async () => {
const leagueId = 'league-1';
const seasonId = 'season-1';
await seedLeagueAndSeason({ leagueId, seasonId });
const sponsorship = SeasonSponsorship.create({
id: 'sponsorship-1',
seasonId,
leagueId,
sponsorId: 'sponsor-1',
tier: 'main',
pricing: Money.create(1000, 'USD'),
status: 'active',
});
await context.seasonSponsorshipRepository.create(sponsorship);
const found = await context.seasonSponsorshipRepository.findById('sponsorship-1');
expect(found).not.toBeNull();
expect(found?.id).toBe('sponsorship-1');
expect(found?.seasonId).toBe(seasonId);
expect(found?.leagueId).toBe(leagueId);
});
it('edits sponsorship pricing via repository update', async () => {
const leagueId = 'league-1';
const seasonId = 'season-1';
await seedLeagueAndSeason({ leagueId, seasonId });
const sponsorship = SeasonSponsorship.create({
id: 'sponsorship-1',
seasonId,
leagueId,
sponsorId: 'sponsor-1',
tier: 'main',
pricing: Money.create(1000, 'USD'),
status: 'active',
});
await context.seasonSponsorshipRepository.create(sponsorship);
const updated = sponsorship.withPricing(Money.create(1500, 'USD'));
await context.seasonSponsorshipRepository.update(updated);
const found = await context.seasonSponsorshipRepository.findById('sponsorship-1');
expect(found).not.toBeNull();
expect(found?.pricing.amount).toBe(1500);
expect(found?.pricing.currency).toBe('USD');
});
it('deletes a sponsorship from the repository', async () => {
const leagueId = 'league-1';
const seasonId = 'season-1';
await seedLeagueAndSeason({ leagueId, seasonId });
const sponsorship = SeasonSponsorship.create({
id: 'sponsorship-1',
seasonId,
leagueId,
sponsorId: 'sponsor-1',
tier: 'main',
pricing: Money.create(1000, 'USD'),
status: 'active',
});
await context.seasonSponsorshipRepository.create(sponsorship);
expect(await context.seasonSponsorshipRepository.exists('sponsorship-1')).toBe(true);
await context.seasonSponsorshipRepository.delete('sponsorship-1');
expect(await context.seasonSponsorshipRepository.exists('sponsorship-1')).toBe(false);
const found = await context.seasonSponsorshipRepository.findById('sponsorship-1');
expect(found).toBeNull();
});
});