mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
new test for #2752
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -76,3 +76,4 @@ pnpm-lock.yaml
|
||||
package.json
|
||||
.cache/
|
||||
interface/.tsbuildinfo
|
||||
test/test_api/package-lock.json
|
||||
|
||||
40
test/test_api/api_test.js
Normal file
40
test/test_api/api_test.js
Normal file
@@ -0,0 +1,40 @@
|
||||
// npm install axios
|
||||
// node api_test.js
|
||||
const axios = require('axios');
|
||||
|
||||
async function testAPI(ip = "ems-esp.local", apiPath = "system") {
|
||||
const baseUrl = `http://${ip}/api`;
|
||||
const url = `${baseUrl}/${apiPath}`;
|
||||
|
||||
try {
|
||||
const response = await axios.get(url, {
|
||||
timeout: 5000,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Status:', response.status);
|
||||
console.log('Data:', JSON.stringify(response.data, null, 2));
|
||||
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error('Error:', error.message);
|
||||
if (error.response) {
|
||||
console.error('Response status:', error.response.status);
|
||||
console.error('Response data:', error.response.data);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// Run the test
|
||||
testAPI("192.168.1.223", "system")
|
||||
.then(() => {
|
||||
console.log('Test completed successfully');
|
||||
process.exit(0);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Test failed:', error);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user