297 lines
11 KiB
JavaScript
297 lines
11 KiB
JavaScript
#!/usr/bin/env node
|
|
'use strict';
|
|
|
|
/**
|
|
* Test script to discover actual SatLoc API error responses for ALL endpoints
|
|
* Tests GetAircraftList, GetAircraftLogs, UploadJobData with wrong credentials
|
|
*/
|
|
|
|
const axios = require('axios');
|
|
|
|
const BASE_URL = 'https://www.satloccloudfc.com/api/Satloc';
|
|
|
|
async function testAllEndpoints() {
|
|
console.log('='.repeat(80));
|
|
console.log('Testing ALL SatLoc API Endpoints with Invalid Data');
|
|
console.log('='.repeat(80));
|
|
console.log('This tests what happens with wrong userId, companyId, aircraftId, etc.\n');
|
|
|
|
// Test data - all intentionally wrong
|
|
const validUserId = 'a2991888-5c7f-4101-8e0d-0a390c26720c'; // From docs
|
|
const validCompanyId = '36c0f342-e4e2-4fcb-b219-9cd1fad2c1ff'; // From docs
|
|
const validAircraftId = '23bee7aa-c949-4089-854a-2ab58b40294f'; // From docs
|
|
|
|
const wrongUserId = 'wrong-0000-0000-0000-000000000000';
|
|
const wrongCompanyId = 'wrong-0000-0000-0000-000000000000';
|
|
const wrongAircraftId = 'wrong-0000-0000-0000-000000000000';
|
|
|
|
// ========================================================================
|
|
// Test 1: GetAircraftList with wrong userId
|
|
// ========================================================================
|
|
console.log('='.repeat(80));
|
|
console.log('TEST 1: GetAircraftList - Wrong UserId');
|
|
console.log('='.repeat(80));
|
|
console.log(`UserId: ${wrongUserId}`);
|
|
console.log(`CompanyId: ${validCompanyId}\n`);
|
|
|
|
try {
|
|
const response = await axios.get(`${BASE_URL}/GetAircraftList`, {
|
|
params: {
|
|
userId: wrongUserId,
|
|
companyId: validCompanyId
|
|
},
|
|
timeout: 30000,
|
|
validateStatus: (status) => status < 500
|
|
});
|
|
|
|
console.log('✓ Request succeeded (no exception)');
|
|
console.log(` Status: ${response.status}`);
|
|
console.log(` Status Text: ${response.statusText}`);
|
|
console.log(` Data Type: ${typeof response.data}`);
|
|
console.log(` Data:`, JSON.stringify(response.data, null, 2));
|
|
} catch (error) {
|
|
console.log('✗ Request threw exception');
|
|
console.log(` Status: ${error.response?.status}`);
|
|
console.log(` Status Text: ${error.response?.statusText}`);
|
|
console.log(` Data:`, JSON.stringify(error.response?.data, null, 2));
|
|
}
|
|
console.log('\n');
|
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
|
|
// ========================================================================
|
|
// Test 2: GetAircraftList with wrong companyId
|
|
// ========================================================================
|
|
console.log('='.repeat(80));
|
|
console.log('TEST 2: GetAircraftList - Wrong CompanyId');
|
|
console.log('='.repeat(80));
|
|
console.log(`UserId: ${validUserId}`);
|
|
console.log(`CompanyId: ${wrongCompanyId}\n`);
|
|
|
|
try {
|
|
const response = await axios.get(`${BASE_URL}/GetAircraftList`, {
|
|
params: {
|
|
userId: validUserId,
|
|
companyId: wrongCompanyId
|
|
},
|
|
timeout: 30000,
|
|
validateStatus: (status) => status < 500
|
|
});
|
|
|
|
console.log('✓ Request succeeded (no exception)');
|
|
console.log(` Status: ${response.status}`);
|
|
console.log(` Status Text: ${response.statusText}`);
|
|
console.log(` Data Type: ${typeof response.data}`);
|
|
console.log(` Data:`, JSON.stringify(response.data, null, 2));
|
|
} catch (error) {
|
|
console.log('✗ Request threw exception');
|
|
console.log(` Status: ${error.response?.status}`);
|
|
console.log(` Status Text: ${error.response?.statusText}`);
|
|
console.log(` Data:`, JSON.stringify(error.response?.data, null, 2));
|
|
}
|
|
console.log('\n');
|
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
|
|
// ========================================================================
|
|
// Test 3: GetAircraftList with empty userId
|
|
// ========================================================================
|
|
console.log('='.repeat(80));
|
|
console.log('TEST 3: GetAircraftList - Empty UserId');
|
|
console.log('='.repeat(80));
|
|
console.log(`UserId: (empty)`);
|
|
console.log(`CompanyId: ${validCompanyId}\n`);
|
|
|
|
try {
|
|
const response = await axios.get(`${BASE_URL}/GetAircraftList`, {
|
|
params: {
|
|
userId: '',
|
|
companyId: validCompanyId
|
|
},
|
|
timeout: 30000,
|
|
validateStatus: (status) => status < 500
|
|
});
|
|
|
|
console.log('✓ Request succeeded (no exception)');
|
|
console.log(` Status: ${response.status}`);
|
|
console.log(` Status Text: ${response.statusText}`);
|
|
console.log(` Data Type: ${typeof response.data}`);
|
|
console.log(` Data:`, JSON.stringify(response.data, null, 2));
|
|
} catch (error) {
|
|
console.log('✗ Request threw exception');
|
|
console.log(` Status: ${error.response?.status}`);
|
|
console.log(` Status Text: ${error.response?.statusText}`);
|
|
console.log(` Data:`, JSON.stringify(error.response?.data, null, 2));
|
|
}
|
|
console.log('\n');
|
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
|
|
// ========================================================================
|
|
// Test 4: GetAircraftLogs with wrong userId
|
|
// ========================================================================
|
|
console.log('='.repeat(80));
|
|
console.log('TEST 4: GetAircraftLogs - Wrong UserId');
|
|
console.log('='.repeat(80));
|
|
console.log(`UserId: ${wrongUserId}`);
|
|
console.log(`AircraftId: ${validAircraftId}\n`);
|
|
|
|
try {
|
|
const response = await axios.get(`${BASE_URL}/GetAircraftLogs`, {
|
|
params: {
|
|
userId: wrongUserId,
|
|
aircraftId: validAircraftId
|
|
},
|
|
timeout: 30000,
|
|
validateStatus: (status) => status < 500
|
|
});
|
|
|
|
console.log('✓ Request succeeded (no exception)');
|
|
console.log(` Status: ${response.status}`);
|
|
console.log(` Status Text: ${response.statusText}`);
|
|
console.log(` Data Type: ${typeof response.data}`);
|
|
console.log(` Data:`, JSON.stringify(response.data, null, 2));
|
|
} catch (error) {
|
|
console.log('✗ Request threw exception');
|
|
console.log(` Status: ${error.response?.status}`);
|
|
console.log(` Status Text: ${error.response?.statusText}`);
|
|
console.log(` Data:`, JSON.stringify(error.response?.data, null, 2));
|
|
}
|
|
console.log('\n');
|
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
|
|
// ========================================================================
|
|
// Test 5: GetAircraftLogs with wrong aircraftId
|
|
// ========================================================================
|
|
console.log('='.repeat(80));
|
|
console.log('TEST 5: GetAircraftLogs - Wrong AircraftId');
|
|
console.log('='.repeat(80));
|
|
console.log(`UserId: ${validUserId}`);
|
|
console.log(`AircraftId: ${wrongAircraftId}\n`);
|
|
|
|
try {
|
|
const response = await axios.get(`${BASE_URL}/GetAircraftLogs`, {
|
|
params: {
|
|
userId: validUserId,
|
|
aircraftId: wrongAircraftId
|
|
},
|
|
timeout: 30000,
|
|
validateStatus: (status) => status < 500
|
|
});
|
|
|
|
console.log('✓ Request succeeded (no exception)');
|
|
console.log(` Status: ${response.status}`);
|
|
console.log(` Status Text: ${response.statusText}`);
|
|
console.log(` Data Type: ${typeof response.data}`);
|
|
console.log(` Data:`, JSON.stringify(response.data, null, 2));
|
|
} catch (error) {
|
|
console.log('✗ Request threw exception');
|
|
console.log(` Status: ${error.response?.status}`);
|
|
console.log(` Status Text: ${error.response?.statusText}`);
|
|
console.log(` Data:`, JSON.stringify(error.response?.data, null, 2));
|
|
}
|
|
console.log('\n');
|
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
|
|
// ========================================================================
|
|
// Test 6: UploadJobData with wrong userId/companyId
|
|
// ========================================================================
|
|
console.log('='.repeat(80));
|
|
console.log('TEST 6: UploadJobData - Wrong UserId/CompanyId');
|
|
console.log('='.repeat(80));
|
|
console.log(`UserId: ${wrongUserId}`);
|
|
console.log(`CompanyId: ${wrongCompanyId}`);
|
|
console.log(`AircraftId: ${validAircraftId}\n`);
|
|
|
|
try {
|
|
const payload = {
|
|
CompanyId: wrongCompanyId,
|
|
UserId: wrongUserId,
|
|
JobDataList: [
|
|
{
|
|
AircraftId: validAircraftId,
|
|
JobName: "test.job",
|
|
Notes: "Test job",
|
|
JobData: "AAAAAAAAAAAA", // Dummy base64 data
|
|
Overwrite: true
|
|
}
|
|
]
|
|
};
|
|
|
|
const response = await axios.post(`${BASE_URL}/UploadJobData`, payload, {
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
timeout: 30000,
|
|
validateStatus: (status) => status < 500
|
|
});
|
|
|
|
console.log('✓ Request succeeded (no exception)');
|
|
console.log(` Status: ${response.status}`);
|
|
console.log(` Status Text: ${response.statusText}`);
|
|
console.log(` Data Type: ${typeof response.data}`);
|
|
console.log(` Data:`, JSON.stringify(response.data, null, 2));
|
|
} catch (error) {
|
|
console.log('✗ Request threw exception');
|
|
console.log(` Status: ${error.response?.status}`);
|
|
console.log(` Status Text: ${error.response?.statusText}`);
|
|
console.log(` Data:`, JSON.stringify(error.response?.data, null, 2));
|
|
}
|
|
console.log('\n');
|
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
|
|
// ========================================================================
|
|
// Test 7: UploadJobData with wrong aircraftId
|
|
// ========================================================================
|
|
console.log('='.repeat(80));
|
|
console.log('TEST 7: UploadJobData - Wrong AircraftId');
|
|
console.log('='.repeat(80));
|
|
console.log(`UserId: ${validUserId}`);
|
|
console.log(`CompanyId: ${validCompanyId}`);
|
|
console.log(`AircraftId: ${wrongAircraftId}\n`);
|
|
|
|
try {
|
|
const payload = {
|
|
CompanyId: validCompanyId,
|
|
UserId: validUserId,
|
|
JobDataList: [
|
|
{
|
|
AircraftId: wrongAircraftId,
|
|
JobName: "test.job",
|
|
Notes: "Test job",
|
|
JobData: "AAAAAAAAAAAA",
|
|
Overwrite: true
|
|
}
|
|
]
|
|
};
|
|
|
|
const response = await axios.post(`${BASE_URL}/UploadJobData`, payload, {
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
timeout: 30000,
|
|
validateStatus: (status) => status < 500
|
|
});
|
|
|
|
console.log('✓ Request succeeded (no exception)');
|
|
console.log(` Status: ${response.status}`);
|
|
console.log(` Status Text: ${response.statusText}`);
|
|
console.log(` Data Type: ${typeof response.data}`);
|
|
console.log(` Data:`, JSON.stringify(response.data, null, 2));
|
|
} catch (error) {
|
|
console.log('✗ Request threw exception');
|
|
console.log(` Status: ${error.response?.status}`);
|
|
console.log(` Status Text: ${error.response?.statusText}`);
|
|
console.log(` Data:`, JSON.stringify(error.response?.data, null, 2));
|
|
}
|
|
|
|
console.log('\n');
|
|
console.log('='.repeat(80));
|
|
console.log('All Tests Complete!');
|
|
console.log('='.repeat(80));
|
|
}
|
|
|
|
testAllEndpoints()
|
|
.then(() => process.exit(0))
|
|
.catch(error => {
|
|
console.error('Test failed:', error);
|
|
process.exit(1);
|
|
});
|