"use strict"; /** * Contract test for GET /api/v1/hedging/sessions * Tests the API contract for listing hedging sessions */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const globals_1 = require("@jest/globals"); const axios_1 = __importDefault(require("axios")); (0, globals_1.describe)('GET /api/v1/hedging/sessions', () => { let client; const baseURL = 'http://localhost:3000/api/v1/hedging'; (0, globals_1.beforeAll)(() => { client = axios_1.default.create({ baseURL, headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer test-api-key' }, timeout: 5000 }); }); (0, globals_1.afterAll)(() => { // Cleanup if needed }); (0, globals_1.describe)('Basic Functionality', () => { (0, globals_1.it)('should return list of hedging sessions', async () => { try { const response = await client.get('/sessions'); // Should return 200 OK (0, globals_1.expect)(response.status).toBe(200); // Response should match schema const responseData = response.data; (0, globals_1.expect)(responseData.success).toBe(true); (0, globals_1.expect)(responseData.sessions).toBeDefined(); (0, globals_1.expect)(Array.isArray(responseData.sessions)).toBe(true); (0, globals_1.expect)(responseData.total).toBeDefined(); (0, globals_1.expect)(typeof responseData.total).toBe('number'); (0, globals_1.expect)(responseData.limit).toBeDefined(); (0, globals_1.expect)(responseData.offset).toBeDefined(); // Each session should have required fields responseData.sessions.forEach(session => { (0, globals_1.expect)(session.id).toBeDefined(); (0, globals_1.expect)(session.name).toBeDefined(); (0, globals_1.expect)(session.status).toBeDefined(); (0, globals_1.expect)(['pending', 'active', 'paused', 'completed', 'failed']).toContain(session.status); (0, globals_1.expect)(session.accounts).toBeDefined(); (0, globals_1.expect)(Array.isArray(session.accounts)).toBe(true); (0, globals_1.expect)(session.volumeTarget).toBeDefined(); (0, globals_1.expect)(session.volumeGenerated).toBeDefined(); (0, globals_1.expect)(session.startTime).toBeDefined(); }); } catch (error) { // This test should fail initially since the endpoint doesn't exist yet (0, globals_1.expect)(error.response?.status).toBe(404); } }); (0, globals_1.it)('should return empty list when no sessions exist', async () => { try { const response = await client.get('/sessions'); const responseData = response.data; (0, globals_1.expect)(responseData.success).toBe(true); (0, globals_1.expect)(responseData.sessions).toEqual([]); (0, globals_1.expect)(responseData.total).toBe(0); } catch (error) { // This test should fail initially since the endpoint doesn't exist yet (0, globals_1.expect)(error.response?.status).toBe(404); } }); }); (0, globals_1.describe)('Query Parameters', () => { (0, globals_1.it)('should filter sessions by status', async () => { try { const response = await client.get('/sessions?status=active'); (0, globals_1.expect)(response.status).toBe(200); const responseData = response.data; (0, globals_1.expect)(responseData.success).toBe(true); // All returned sessions should have active status responseData.sessions.forEach(session => { (0, globals_1.expect)(session.status).toBe('active'); }); } catch (error) { // This test should fail initially since the endpoint doesn't exist yet (0, globals_1.expect)(error.response?.status).toBe(404); } }); (0, globals_1.it)('should filter sessions by account ID', async () => { try { const response = await client.get('/sessions?accountId=account-1'); (0, globals_1.expect)(response.status).toBe(200); const responseData = response.data; (0, globals_1.expect)(responseData.success).toBe(true); // All returned sessions should include the specified account responseData.sessions.forEach(session => { (0, globals_1.expect)(session.accounts).toContain('account-1'); }); } catch (error) { // This test should fail initially since the endpoint doesn't exist yet (0, globals_1.expect)(error.response?.status).toBe(404); } }); (0, globals_1.it)('should support pagination with limit and offset', async () => { try { const response = await client.get('/sessions?limit=10&offset=20'); (0, globals_1.expect)(response.status).toBe(200); const responseData = response.data; (0, globals_1.expect)(responseData.success).toBe(true); (0, globals_1.expect)(responseData.limit).toBe(10); (0, globals_1.expect)(responseData.offset).toBe(20); (0, globals_1.expect)(responseData.sessions.length).toBeLessThanOrEqual(10); } catch (error) { // This test should fail initially since the endpoint doesn't exist yet (0, globals_1.expect)(error.response?.status).toBe(404); } }); (0, globals_1.it)('should use default pagination values', async () => { try { const response = await client.get('/sessions'); (0, globals_1.expect)(response.status).toBe(200); const responseData = response.data; (0, globals_1.expect)(responseData.success).toBe(true); (0, globals_1.expect)(responseData.limit).toBe(50); // Default limit (0, globals_1.expect)(responseData.offset).toBe(0); // Default offset } catch (error) { // This test should fail initially since the endpoint doesn't exist yet (0, globals_1.expect)(error.response?.status).toBe(404); } }); (0, globals_1.it)('should handle multiple query parameters', async () => { try { const response = await client.get('/sessions?status=active&accountId=account-1&limit=5&offset=0'); (0, globals_1.expect)(response.status).toBe(200); const responseData = response.data; (0, globals_1.expect)(responseData.success).toBe(true); (0, globals_1.expect)(responseData.limit).toBe(5); (0, globals_1.expect)(responseData.offset).toBe(0); // All returned sessions should match both filters responseData.sessions.forEach(session => { (0, globals_1.expect)(session.status).toBe('active'); (0, globals_1.expect)(session.accounts).toContain('account-1'); }); } catch (error) { // This test should fail initially since the endpoint doesn't exist yet (0, globals_1.expect)(error.response?.status).toBe(404); } }); }); (0, globals_1.describe)('Error Handling', () => { (0, globals_1.it)('should reject request without authorization header', async () => { const clientWithoutAuth = axios_1.default.create({ baseURL, headers: { 'Content-Type': 'application/json' } }); try { await clientWithoutAuth.get('/sessions'); fail('Should have rejected unauthorized request'); } catch (error) { (0, globals_1.expect)(error.response?.status).toBe(401); } }); (0, globals_1.it)('should reject request with invalid authorization token', async () => { const clientWithInvalidAuth = axios_1.default.create({ baseURL, headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer invalid-token' } }); try { await clientWithInvalidAuth.get('/sessions'); fail('Should have rejected request with invalid token'); } catch (error) { (0, globals_1.expect)(error.response?.status).toBe(401); } }); (0, globals_1.it)('should handle invalid query parameters gracefully', async () => { try { const response = await client.get('/sessions?status=invalid_status'); (0, globals_1.expect)(response.status).toBe(400); (0, globals_1.expect)(response.data.success).toBe(false); (0, globals_1.expect)(response.data.error.code).toBe('INVALID_QUERY_PARAMETER'); } catch (error) { // This test should fail initially since the endpoint doesn't exist yet (0, globals_1.expect)(error.response?.status).toBe(404); } }); (0, globals_1.it)('should handle invalid pagination parameters', async () => { try { const response = await client.get('/sessions?limit=-1&offset=-5'); (0, globals_1.expect)(response.status).toBe(400); (0, globals_1.expect)(response.data.success).toBe(false); (0, globals_1.expect)(response.data.error.code).toBe('INVALID_QUERY_PARAMETER'); } catch (error) { // This test should fail initially since the endpoint doesn't exist yet (0, globals_1.expect)(error.response?.status).toBe(404); } }); }); (0, globals_1.describe)('Rate Limiting', () => { (0, globals_1.it)('should handle rate limiting gracefully', async () => { // Make multiple requests quickly to test rate limiting const requests = Array(10).fill(null).map(() => client.get('/sessions')); try { const responses = await Promise.all(requests); // All requests should succeed (rate limit not exceeded) responses.forEach(response => { (0, globals_1.expect)(response.status).toBe(200); }); } catch (error) { // If rate limited, should return 429 if (error.response?.status === 429) { (0, globals_1.expect)(error.response.status).toBe(429); (0, globals_1.expect)(error.response.data.error.code).toBe('RATE_LIMIT_EXCEEDED'); } else { // Otherwise, endpoint doesn't exist yet (0, globals_1.expect)(error.response?.status).toBe(404); } } }); }); }); //# sourceMappingURL=test_hedging_sessions_get.js.map