92 lines
2.3 KiB
TypeScript
92 lines
2.3 KiB
TypeScript
/**
|
|
* Integration Test: Race Results Import API
|
|
*
|
|
* Tests the race results import endpoint with various scenarios.
|
|
*/
|
|
|
|
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
|
import { ApiClient } from '../harness/api-client';
|
|
import { DockerManager } from '../harness/docker-manager';
|
|
|
|
describe('Race Results Import - 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 return 404 for non-existent race', async () => {
|
|
const nonExistentRaceId = 'non-existent-race-123';
|
|
const results = [
|
|
{
|
|
driverId: 'driver-1',
|
|
position: 1,
|
|
fastestLap: 100,
|
|
incidents: 0,
|
|
startPosition: 1,
|
|
},
|
|
];
|
|
|
|
await expect(
|
|
api.post(`/races/${nonExistentRaceId}/import-results`, {
|
|
resultsFileContent: JSON.stringify(results),
|
|
raceId: nonExistentRaceId,
|
|
})
|
|
).rejects.toThrow();
|
|
});
|
|
|
|
it('should handle invalid JSON gracefully', async () => {
|
|
const raceId = 'test-race-1';
|
|
|
|
await expect(
|
|
api.post(`/races/${raceId}/import-results`, {
|
|
resultsFileContent: 'invalid json {',
|
|
raceId,
|
|
})
|
|
).rejects.toThrow();
|
|
});
|
|
|
|
it('should reject empty results array', async () => {
|
|
const raceId = 'test-race-1';
|
|
const emptyResults: unknown[] = [];
|
|
|
|
await expect(
|
|
api.post(`/races/${raceId}/import-results`, {
|
|
resultsFileContent: JSON.stringify(emptyResults),
|
|
raceId,
|
|
})
|
|
).rejects.toThrow();
|
|
});
|
|
|
|
it('should handle missing required fields', async () => {
|
|
const raceId = 'test-race-1';
|
|
const invalidResults = [
|
|
{
|
|
// Missing required fields
|
|
driverId: 'driver-1',
|
|
position: 1,
|
|
},
|
|
];
|
|
|
|
await expect(
|
|
api.post(`/races/${raceId}/import-results`, {
|
|
resultsFileContent: JSON.stringify(invalidResults),
|
|
raceId,
|
|
})
|
|
).rejects.toThrow();
|
|
});
|
|
|
|
it('should verify API health endpoint works', async () => {
|
|
const isHealthy = await api.health();
|
|
expect(isHealthy).toBe(true);
|
|
});
|
|
}); |