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:
107
tests/integration/harness/infrastructure/api-client.test.ts
Normal file
107
tests/integration/harness/infrastructure/api-client.test.ts
Normal file
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* Integration Test: ApiClient
|
||||
*
|
||||
* Tests the ApiClient infrastructure for making HTTP requests
|
||||
*/
|
||||
|
||||
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
||||
import { ApiClient } from '../api-client';
|
||||
|
||||
describe('ApiClient - Infrastructure Tests', () => {
|
||||
let apiClient: ApiClient;
|
||||
let mockServer: { close: () => void; port: number };
|
||||
|
||||
beforeAll(async () => {
|
||||
// Create a mock HTTP server for testing
|
||||
const http = require('http');
|
||||
const server = http.createServer((req: any, res: any) => {
|
||||
if (req.url === '/health') {
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ status: 'ok' }));
|
||||
} else if (req.url === '/api/data') {
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ message: 'success', data: { id: 1, name: 'test' } }));
|
||||
} else if (req.url === '/api/error') {
|
||||
res.writeHead(500, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ error: 'Internal Server Error' }));
|
||||
} else if (req.url === '/api/slow') {
|
||||
// Simulate slow response
|
||||
setTimeout(() => {
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ message: 'slow response' }));
|
||||
}, 2000);
|
||||
} else {
|
||||
res.writeHead(404);
|
||||
res.end('Not Found');
|
||||
}
|
||||
});
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
server.listen(0, () => {
|
||||
const port = (server.address() as any).port;
|
||||
mockServer = { close: () => server.close(), port };
|
||||
apiClient = new ApiClient({ baseUrl: `http://localhost:${port}`, timeout: 5000 });
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
if (mockServer) {
|
||||
mockServer.close();
|
||||
}
|
||||
});
|
||||
|
||||
describe('HTTP Methods', () => {
|
||||
it('should successfully make a GET request', async () => {
|
||||
const result = await apiClient.get<{ message: string; data: { id: number; name: string } }>('/api/data');
|
||||
expect(result.message).toBe('success');
|
||||
expect(result.data.id).toBe(1);
|
||||
});
|
||||
|
||||
it('should successfully make a POST request with body', async () => {
|
||||
const result = await apiClient.post<{ message: string }>('/api/data', { name: 'test' });
|
||||
expect(result.message).toBe('success');
|
||||
});
|
||||
|
||||
it('should successfully make a PUT request with body', async () => {
|
||||
const result = await apiClient.put<{ message: string }>('/api/data', { id: 1 });
|
||||
expect(result.message).toBe('success');
|
||||
});
|
||||
|
||||
it('should successfully make a PATCH request with body', async () => {
|
||||
const result = await apiClient.patch<{ message: string }>('/api/data', { name: 'patched' });
|
||||
expect(result.message).toBe('success');
|
||||
});
|
||||
|
||||
it('should successfully make a DELETE request', async () => {
|
||||
const result = await apiClient.delete<{ message: string }>('/api/data');
|
||||
expect(result.message).toBe('success');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Error Handling & Timeouts', () => {
|
||||
it('should handle HTTP errors gracefully', async () => {
|
||||
await expect(apiClient.get('/api/error')).rejects.toThrow('API Error 500');
|
||||
});
|
||||
|
||||
it('should handle timeout errors', async () => {
|
||||
const shortTimeoutClient = new ApiClient({
|
||||
baseUrl: `http://localhost:${mockServer.port}`,
|
||||
timeout: 100,
|
||||
});
|
||||
await expect(shortTimeoutClient.get('/api/slow')).rejects.toThrow('Request timeout after 100ms');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Health & Readiness', () => {
|
||||
it('should successfully check health endpoint', async () => {
|
||||
expect(await apiClient.health()).toBe(true);
|
||||
});
|
||||
|
||||
it('should wait for API to be ready', async () => {
|
||||
await apiClient.waitForReady(5000);
|
||||
expect(true).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* Integration Test: DataFactory
|
||||
*
|
||||
* Tests the DataFactory infrastructure for creating test data
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { setupHarnessTest } from '../HarnessTestContext';
|
||||
|
||||
describe('DataFactory - Infrastructure Tests', () => {
|
||||
const context = setupHarnessTest();
|
||||
|
||||
describe('Entity Creation', () => {
|
||||
it('should create a league entity', async () => {
|
||||
const league = await context.factory.createLeague({
|
||||
name: 'Test League',
|
||||
description: 'Test Description',
|
||||
});
|
||||
|
||||
expect(league).toBeDefined();
|
||||
expect(league.name).toBe('Test League');
|
||||
});
|
||||
|
||||
it('should create a season entity', async () => {
|
||||
const league = await context.factory.createLeague();
|
||||
const season = await context.factory.createSeason(league.id.toString(), {
|
||||
name: 'Test Season',
|
||||
});
|
||||
|
||||
expect(season).toBeDefined();
|
||||
expect(season.leagueId).toBe(league.id.toString());
|
||||
expect(season.name).toBe('Test Season');
|
||||
});
|
||||
|
||||
it('should create a driver entity', async () => {
|
||||
const driver = await context.factory.createDriver({
|
||||
name: 'Test Driver',
|
||||
});
|
||||
|
||||
expect(driver).toBeDefined();
|
||||
expect(driver.name.toString()).toBe('Test Driver');
|
||||
});
|
||||
|
||||
it('should create a race entity', async () => {
|
||||
const league = await context.factory.createLeague();
|
||||
const race = await context.factory.createRace({
|
||||
leagueId: league.id.toString(),
|
||||
track: 'Laguna Seca',
|
||||
});
|
||||
|
||||
expect(race).toBeDefined();
|
||||
expect(race.track).toBe('Laguna Seca');
|
||||
});
|
||||
|
||||
it('should create a result entity', async () => {
|
||||
const league = await context.factory.createLeague();
|
||||
const race = await context.factory.createRace({ leagueId: league.id.toString() });
|
||||
const driver = await context.factory.createDriver();
|
||||
|
||||
const result = await context.factory.createResult(race.id.toString(), driver.id.toString(), {
|
||||
position: 1,
|
||||
});
|
||||
|
||||
expect(result).toBeDefined();
|
||||
expect(result.position).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Scenarios', () => {
|
||||
it('should create a complete test scenario', async () => {
|
||||
const scenario = await context.factory.createTestScenario();
|
||||
|
||||
expect(scenario.league).toBeDefined();
|
||||
expect(scenario.season).toBeDefined();
|
||||
expect(scenario.drivers).toHaveLength(3);
|
||||
expect(scenario.races).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Integration Test: DatabaseManager
|
||||
*
|
||||
* Tests the DatabaseManager infrastructure for database operations
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { setupHarnessTest } from '../HarnessTestContext';
|
||||
|
||||
describe('DatabaseManager - Infrastructure Tests', () => {
|
||||
const context = setupHarnessTest();
|
||||
|
||||
describe('Query Execution', () => {
|
||||
it('should execute simple SELECT query', async () => {
|
||||
const result = await context.db.query('SELECT 1 as test_value');
|
||||
expect(result.rows[0].test_value).toBe(1);
|
||||
});
|
||||
|
||||
it('should execute query with parameters', async () => {
|
||||
const result = await context.db.query('SELECT $1 as param_value', ['test']);
|
||||
expect(result.rows[0].param_value).toBe('test');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Transaction Handling', () => {
|
||||
it('should begin, commit and rollback transactions', async () => {
|
||||
// These methods should not throw
|
||||
await context.db.begin();
|
||||
await context.db.commit();
|
||||
await context.db.begin();
|
||||
await context.db.rollback();
|
||||
expect(true).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Table Operations', () => {
|
||||
it('should truncate all tables', async () => {
|
||||
// This verifies the truncate logic doesn't have syntax errors
|
||||
await context.db.truncateAllTables();
|
||||
expect(true).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user