test-update-data-element.jsā¢2.28 kB
/**
* Test script for UpdateDataElement MCP tool
* Tests the complete flow: lock, update, unlock, activate, verify
*
* Configuration is loaded from tests/test-config.yaml
*/
const {
initializeTestEnvironment,
getAllEnabledTestCases,
validateTransportRequest,
printTestHeader,
printTestParams,
printTestResult,
waitForConfirmation
} = require('./test-helper');
// Initialize test environment before importing handlers
initializeTestEnvironment();
const { handleUpdateDataElement } = require('../dist/handlers/handleUpdateDataElement');
async function testUpdateDataElement() {
// Load all enabled test cases from YAML
const testCases = getAllEnabledTestCases('update_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('UpdateDataElement', 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 update flow ---\n');
try {
const result = await handleUpdateDataElement(testArgs);
if (printTestResult(result, 'UpdateDataElement')) {
passedTests++;
} else {
failedTests++;
}
} catch (error) {
console.error('ā Unexpected error during data element update:');
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 the test
testUpdateDataElement()
.then(() => {
console.log('\n=== All tests completed successfully ===');
process.exit(0);
})
.catch(error => {
console.error('\n=== Tests failed ===');
console.error(error);
process.exit(1);
});