( method: string, path: string, body?: any, )
| 32 | const results: TestResult[] = []; |
| 33 | |
| 34 | async function makeRequest( |
| 35 | method: string, |
| 36 | path: string, |
| 37 | body?: any, |
| 38 | ): Promise<TestResult> { |
| 39 | const url = `${API_BASE_URL}${path}`; |
| 40 | const headers: Record<string, string> = { |
| 41 | 'openpanel-client-id': CLIENT_ID, |
| 42 | 'openpanel-client-secret': CLIENT_SECRET, |
| 43 | }; |
| 44 | |
| 45 | // Only set Content-Type if there's a body |
| 46 | if (body) { |
| 47 | headers['Content-Type'] = 'application/json'; |
| 48 | } |
| 49 | |
| 50 | try { |
| 51 | const response = await fetch(url, { |
| 52 | method, |
| 53 | headers, |
| 54 | body: body ? JSON.stringify(body) : undefined, |
| 55 | }); |
| 56 | |
| 57 | const data = await response.json().catch(() => ({})); |
| 58 | |
| 59 | return { |
| 60 | name: `${method} ${path}`, |
| 61 | method, |
| 62 | url, |
| 63 | status: response.status, |
| 64 | success: response.ok, |
| 65 | error: response.ok ? undefined : data.message || 'Request failed', |
| 66 | data: response.ok ? data : undefined, |
| 67 | }; |
| 68 | } catch (error) { |
| 69 | return { |
| 70 | name: `${method} ${path}`, |
| 71 | method, |
| 72 | url, |
| 73 | status: 0, |
| 74 | success: false, |
| 75 | error: error instanceof Error ? error.message : 'Unknown error', |
| 76 | }; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | async function testProjects() { |
| 81 | console.log('\n📁 Testing Projects endpoints...\n'); |
no test coverage detected