-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-multiple-endpoints.js
More file actions
96 lines (85 loc) · 2.71 KB
/
test-multiple-endpoints.js
File metadata and controls
96 lines (85 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Test script for multiple Fantasy API endpoints
import axios from 'axios';
const API_KEY = '4ffc29cb-44d2-4231-aef8-af3a545af3a0';
const BASE_URL = 'https://api-v2.fantasy.top';
async function testEndpoint(endpoint, params = {}, description = '') {
try {
console.log(`\n=== Testing ${description || endpoint} ===`);
const url = `${BASE_URL}${endpoint}`;
console.log(`Making request to: ${url}`);
console.log('With params:', params);
const response = await axios.get(url, {
params: params,
headers: {
'x-api-key': API_KEY,
'accept': 'application/json'
},
validateStatus: status => true // Accept any status code
});
console.log('Response status:', response.status);
if (response.status >= 200 && response.status < 300) {
const data = response.data;
if (data && data.data && Array.isArray(data.data)) {
console.log(`Success! Got response with ${data.data.length} items`);
if (data.data.length > 0) {
console.log('First item preview:', JSON.stringify(data.data[0]).substring(0, 150) + '...');
}
} else {
console.log('Success! Response data preview:', JSON.stringify(data).substring(0, 150) + '...');
}
} else {
console.error('Error response:', response.data);
}
return response.status;
} catch (error) {
console.error('Error:', error.message);
return 0;
}
}
async function runTests() {
// Test various endpoints
const endpoints = [
{
endpoint: '/hero/stats',
params: { 'pagination[page]': 1, 'pagination[limit]': 5 },
description: 'Hero Stats Endpoint'
},
{
endpoint: '/hero/search/name',
params: { search: 'greg' },
description: 'Hero Search Endpoint'
},
{
endpoint: '/hero/feed',
params: { handle: 'DegenerateMoney' },
description: 'Hero Feed Endpoint (DegenerateMoney)'
},
{
endpoint: '/hero/feed',
params: { handle: 'greg16676935420' },
description: 'Hero Feed Endpoint (greg)'
},
{
endpoint: '/tournaments/next-tournaments',
params: {},
description: 'Tournaments Endpoint'
}
];
let results = [];
for (const test of endpoints) {
const status = await testEndpoint(test.endpoint, test.params, test.description);
results.push({
endpoint: test.endpoint,
params: test.params,
status: status,
success: status >= 200 && status < 300
});
}
// Summary
console.log('\n=== TEST SUMMARY ===');
results.forEach(result => {
console.log(`${result.endpoint} ${JSON.stringify(result.params)}: ${result.success ? 'SUCCESS' : 'FAILED'} (${result.status})`);
});
}
// Run the tests
runTests();