const axios = require('axios');
async function testMcpUnblended() {
const BASE_URL = 'https://api.dev.umbrellacost.dev/api';
const USERNAME = 'elisha+testmcpdev@anodot.com';
const PASSWORD = 'Test123!';
const ACCOUNT_KEY = '111111639';
const DIVISION_ID = '0';
try {
console.log('🔐 Authenticating...\n');
const authResponse = await axios.post(`${BASE_URL}/v1/users/signin`, {
username: USERNAME,
password: PASSWORD
});
const token = authResponse.data.jwtToken;
const tokenPayload = JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString());
const userKey = tokenPayload.sub;
console.log('✅ Authenticated');
console.log(`User Key: ${userKey}\n`);
const startDate = '2025-01-01';
const endDate = '2025-10-08';
const apiKey = `${userKey}:${ACCOUNT_KEY}:${DIVISION_ID}`;
// Simulate what MCP sends for UNBLENDED cost calculation
console.log('═'.repeat(80));
console.log('TESTING: Unblended Cost Calculation (costCalculationType: "unblended")');
console.log('═'.repeat(80));
// After enum-to-boolean mapping, this becomes: isUnblended: true
const params = {
startDate,
endDate,
isUnblended: true,
costType: ['cost', 'discount'],
periodGranLevel: 'month',
groupBy: 'none',
// MSP parameters
customer_account_key: ACCOUNT_KEY,
customer_division_id: DIVISION_ID
};
console.log('Request params:', JSON.stringify(params, null, 2));
console.log('');
const response = await axios.get(`${BASE_URL}/v2/invoices/cost-and-usage`, {
params: params,
headers: {
'Authorization': token,
'apikey': apiKey
}
});
if (response.data.data && response.data.data.length > 0) {
console.log('📊 Jan 2025 Result:');
console.log(` MCP returned: $${response.data.data[0].total_cost.toFixed(2)}`);
console.log(` Expected: $141,625.94`);
if (Math.abs(response.data.data[0].total_cost - 141625.94) < 1) {
console.log('\n✅ SUCCESS! Unblended is now working correctly!');
} else if (Math.abs(response.data.data[0].total_cost - 120021.98) < 1) {
console.log('\n❌ BUG STILL EXISTS: Still returning wrong value ($120,021.98)');
} else if (Math.abs(response.data.data[0].total_cost - 145702.65) < 1) {
console.log('\n❌ BUG: Returning amortized value instead of unblended!');
} else {
console.log(`\n⚠️ UNEXPECTED VALUE: $${response.data.data[0].total_cost.toFixed(2)}`);
}
}
} catch (error) {
console.error('❌ Error:', error.message);
if (error.response) {
console.error('Status:', error.response.status);
console.error('Data:', JSON.stringify(error.response.data, null, 2));
}
}
}
testMcpUnblended();