/** * Integration Test: League Schedule Lifecycle API * * Tests publish/unpublish/republish lifecycle endpoints. */ import { describe, it, expect, beforeAll, afterAll } from 'vitest'; import { ApiClient } from '../harness/api-client'; import { DockerManager } from '../harness/docker-manager'; describe('League Schedule Lifecycle - API Integration', () => { let api: ApiClient; let docker: DockerManager; beforeAll(async () => { docker = DockerManager.getInstance(); await docker.start(); api = new ApiClient({ baseUrl: 'http://localhost:3101', timeout: 60000 }); await api.waitForReady(); }, 120000); afterAll(async () => { docker.stop(); }, 30000); it('should handle publish endpoint for non-existent league', async () => { const nonExistentLeagueId = 'non-existent-league'; const nonExistentSeasonId = 'non-existent-season'; await expect( api.post(`/leagues/${nonExistentLeagueId}/seasons/${nonExistentSeasonId}/publish`, {}) ).rejects.toThrow(); }); it('should handle unpublish endpoint for non-existent league', async () => { const nonExistentLeagueId = 'non-existent-league'; const nonExistentSeasonId = 'non-existent-season'; await expect( api.post(`/leagues/${nonExistentLeagueId}/seasons/${nonExistentSeasonId}/unpublish`, {}) ).rejects.toThrow(); }); it('should handle create schedule race endpoint for non-existent league', async () => { const nonExistentLeagueId = 'non-existent-league'; const nonExistentSeasonId = 'non-existent-season'; await expect( api.post(`/leagues/${nonExistentLeagueId}/seasons/${nonExistentSeasonId}/schedule/races`, { track: 'Laguna Seca', car: 'Formula Ford', scheduledAtIso: new Date().toISOString(), }) ).rejects.toThrow(); }); it('should reject invalid date format', async () => { const leagueId = 'test-league'; const seasonId = 'test-season'; await expect( api.post(`/leagues/${leagueId}/seasons/${seasonId}/schedule/races`, { track: 'Laguna Seca', car: 'Formula Ford', scheduledAtIso: 'invalid-date', }) ).rejects.toThrow(); }); it('should reject missing required fields for race creation', async () => { const leagueId = 'test-league'; const seasonId = 'test-season'; await expect( api.post(`/leagues/${leagueId}/seasons/${seasonId}/schedule/races`, { track: 'Laguna Seca', // Missing car and scheduledAtIso }) ).rejects.toThrow(); }); });