test-create-transport.jsā¢3.1 kB
/**
* Test CreateTransport handler
* Tests creating transport requests
*/
const {
initializeTestEnvironment,
getAllEnabledTestCases,
printTestHeader,
printTestParams,
printTestResult,
updateTransportRequestInConfig
} = require('./test-helper');
// Initialize test environment
initializeTestEnvironment();
const { handleCreateTransport } = require('../dist/handlers/handleCreateTransport');
async function testCreateTransport() {
const testCases = getAllEnabledTestCases('create_transport');
console.log(`\nš Found ${testCases.length} enabled test case(s)\n`);
let passedTests = 0;
let failedTests = 0;
for (const testCase of testCases) {
printTestHeader('CreateTransport', testCase);
const params = testCase.params;
// Add timestamp to description for uniqueness
const transportData = {
...params,
description: params.description + " - " + new Date().toISOString()
};
printTestParams(transportData);
console.log('--- Creating transport request ---\n');
try {
const result = await handleCreateTransport(transportData);
if (printTestResult(result, 'CreateTransport')) {
passedTests++;
// Extract transport number and update test-config.yaml
try {
if (result.content && result.content[0] && result.content[0].text) {
const parsedResult = JSON.parse(result.content[0].text);
if (parsedResult.transport_request) {
const transportNumber = parsedResult.transport_request;
console.log(`\nš” Transport number created: ${transportNumber}`);
// Automatically update test-config.yaml with the transport number
if (updateTransportRequestInConfig(transportNumber)) {
console.log(` ā
test-config.yaml updated - transport_request values replaced`);
console.log(` ā
You can now run other tests that require transport_request`);
} else {
console.log(` ā ļø Could not update test-config.yaml automatically`);
console.log(` š Please manually update transport_request: "${transportNumber}" in test-config.yaml`);
}
}
}
} catch (e) {
console.warn(`\nā ļø Could not extract transport number from result:`, e.message);
}
} else {
failedTests++;
}
} catch (error) {
console.error('ā Unexpected error:');
console.error(error);
failedTests++;
}
console.log('\n' + '='.repeat(60) + '\n');
}
console.log(`\nš Test Summary:`);
console.log(` ā
Passed: ${passedTests}`);
console.log(` ā Failed: ${failedTests}`);
console.log(` š Total: ${testCases.length}`);
if (failedTests > 0) {
process.exit(1);
}
}
// Run the test
testCreateTransport()
.then(() => {
console.log('\n=== All tests completed successfully ===');
process.exit(0);
})
.catch(error => {
console.error('\n=== Tests failed ===');
console.error(error);
process.exit(1);
});