#!/usr/bin/env node
// Test script specifically for the flight status tool
const { spawn } = require('child_process');
async function testFlightStatusTool() {
console.log('โ๏ธ Testing Flight Status Tool...\n');
const server = spawn('node', ['dist/index.js'], {
stdio: ['pipe', 'pipe', 'inherit']
});
// Helper function to send JSON-RPC request
function sendRequest(method, params = {}) {
return new Promise((resolve, reject) => {
const request = {
jsonrpc: '2.0',
id: Math.random().toString(36).substr(2, 9),
method,
params
};
let response = '';
const onData = (data) => {
response += data.toString();
try {
const parsed = JSON.parse(response);
server.stdout.off('data', onData);
resolve(parsed);
} catch (e) {
// Continue collecting data
}
};
server.stdout.on('data', onData);
server.stdin.write(JSON.stringify(request) + '\n');
setTimeout(() => {
server.stdout.off('data', onData);
reject(new Error('Request timeout'));
}, 5000);
});
}
try {
// Initialize server
await sendRequest('initialize', {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: { name: 'flight-test-client', version: '1.0.0' }
});
// Check if flight status tool is available
console.log('๐ Checking available tools...');
const toolsResponse = await sendRequest('tools/list');
const tools = toolsResponse.result.tools;
const flightTool = tools.find(t => t.name === 'get_flight_status');
if (!flightTool) {
throw new Error('Flight status tool not found in available tools');
}
console.log('โ
Flight status tool found:', flightTool.description);
// Test 1: Flight status with just flight number
console.log('\n๐งช Test 1: Flight status with flight number only');
const test1Response = await sendRequest('tools/call', {
name: 'get_flight_status',
arguments: { flightNumber: '1234' }
});
console.log('โ
Test 1 Result:');
console.log(test1Response.result.content[0].text);
// Test 2: Flight status with airline code
console.log('\n๐งช Test 2: Flight status with airline code');
const test2Response = await sendRequest('tools/call', {
name: 'get_flight_status',
arguments: {
flightNumber: '567',
airlineIata: 'AA'
}
});
console.log('โ
Test 2 Result:');
console.log(test2Response.result.content[0].text);
// Test 3: Error case - missing flight number
console.log('\n๐งช Test 3: Error handling - missing flight number');
const test3Response = await sendRequest('tools/call', {
name: 'get_flight_status',
arguments: {}
});
console.log('โ
Test 3 Result (Error expected):');
console.log(test3Response.result.content[0].text);
// Test 4: Different flight numbers to show variety
console.log('\n๐งช Test 4: Multiple flight lookups');
const flightNumbers = ['890', '123', '456'];
for (const flightNum of flightNumbers) {
const response = await sendRequest('tools/call', {
name: 'get_flight_status',
arguments: { flightNumber: flightNum }
});
console.log(`\n๐ Flight ${flightNum}:`);
const lines = response.result.content[0].text.split('\n');
console.log(lines[0]); // Flight header
console.log(lines[2]); // Status line
console.log(lines[8]); // Route line
}
console.log('\n๐ All flight status tool tests completed successfully!');
console.log('\n๐ Flight Status Tool Features:');
console.log(' โ๏ธ Mock flight data (when no API key provided)');
console.log(' ๐ International flights and airports');
console.log(' ๐ Real-time status updates (scheduled, active, landed, etc.)');
console.log(' ๐ Departure and arrival information');
console.log(' ๐ข Airline information');
console.log(' โ ๏ธ Error handling for invalid inputs');
console.log('\n๐ก To use real flight data:');
console.log(' 1. Get a free API key from https://aviationstack.com');
console.log(' 2. Set environment variable: AVIATIONSTACK_API_KEY=your_key');
console.log(' 3. Rebuild and run the server');
} catch (error) {
console.error('โ Flight status tool test failed:', error.message);
} finally {
server.kill();
}
}
testFlightStatusTool();