test-create-data-element.js•2.21 kB
/**
* Test script for CreateDataElement MCP tool
* Tests the simplified workflow: POST with full body → Activate → Verify
*/
const {
initializeTestEnvironment,
getAllEnabledTestCases,
validateTransportRequest,
printTestHeader,
printTestParams,
printTestResult,
waitForConfirmation
} = require('./test-helper');
// Initialize test environment
initializeTestEnvironment();
const { handleCreateDataElement } = require('../dist/handlers/handleCreateDataElement');
async function testCreateDataElement() {
// Load all enabled test cases from YAML
const testCases = getAllEnabledTestCases('create_data_element');
console.log(`\n📋 Found ${testCases.length} enabled test case(s)\n`);
let passedTests = 0;
let failedTests = 0;
for (const testCase of testCases) {
printTestHeader('CreateDataElement', testCase);
// Test parameters from YAML
const testArgs = testCase.params;
// Validate transport request
if (!validateTransportRequest(testArgs)) {
await waitForConfirmation(
'⚠️ Using default transport request! Update test-config.yaml with a valid request.',
5
);
}
printTestParams(testArgs);
console.log('--- Starting data element creation flow ---\n');
try {
const result = await handleCreateDataElement(testArgs);
if (printTestResult(result, 'CreateDataElement')) {
passedTests++;
} else {
failedTests++;
}
} catch (error) {
console.error('❌ Unexpected error during data element creation:');
console.error(error);
failedTests++;
}
console.log('\n' + '='.repeat(60) + '\n');
}
// Print summary
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 test
testCreateDataElement()
.then(() => {
console.log('\n=== All tests completed successfully ===');
process.exit(0);
})
.catch(error => {
console.error('\n=== Tests failed ===');
console.error(error);
process.exit(1);
});