#!/usr/bin/env node
const https = require('https');
const axios = require('axios');
const axiosInstance = axios.create({
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
timeout: 30000
});
async function testSaolaWithoutTax() {
console.log('\n═══════════════════════════════════════════════════════════════');
console.log(' SAOLA TEST - EXCLUDING TAX (Like MANUAL_ANSWERS.txt)');
console.log('═══════════════════════════════════════════════════════════════\n');
const baseUrl = 'https://api.umbrellacost.io/api/v1';
// Expected values from MANUAL_ANSWERS.txt (WITHOUT TAX)
const EXPECTED = {
'2025-03': 104755.07,
'2025-04': 111340.42,
'2025-05': 149774.24,
'2025-06': 165666.57,
'2025-07': 183920.58
};
try {
// Authenticate
console.log('Authenticating as david+saola@umbrellacost.com...');
const authResponse = await axiosInstance.post(`${baseUrl}/users/signin`, {
username: 'david+saola@umbrellacost.com',
password: 'Dsamsung1!'
});
const token = authResponse.data.jwtToken;
const tokenPayload = JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString());
const userKey = tokenPayload.username || tokenPayload.sub;
console.log('✅ Authenticated. User Key:', userKey);
const apiKey = `${userKey}:9350:0`;
console.log('\n📊 Query 1: With Tax Included (what I was sending):');
console.log(' costType: cost');
console.log(' excludeFilters: NONE');
const params1 = new URLSearchParams({
startDate: '2025-03-01',
endDate: '2025-07-31',
groupBy: 'usagedate',
costType: 'cost',
periodGranLevel: 'month'
});
const response1 = await axiosInstance.get(`${baseUrl}/invoices/caui?${params1}`, {
headers: {
'Authorization': token,
'apikey': apiKey
}
});
console.log('\nResults WITH tax:');
response1.data.slice(0, 2).forEach(item => {
console.log(` ${item.usage_date}: $${item.total_cost.toFixed(2)}`);
});
console.log('\n───────────────────────────────────────────────────────');
console.log('\n📊 Query 2: EXCLUDING Tax (like MANUAL_ANSWERS.txt):');
console.log(' costType: ["cost", "discount"]');
console.log(' excludeFilters[chargetype]: Tax');
const params2 = new URLSearchParams({
startDate: '2025-03-01',
endDate: '2025-07-31',
groupBy: 'usagedate',
costType: 'cost',
periodGranLevel: 'month',
'excludeFilters[chargetype]': 'Tax' // EXCLUDING TAX!
});
params2.append('costType', 'discount'); // Adding discount cost type
const response2 = await axiosInstance.get(`${baseUrl}/invoices/caui?${params2}`, {
headers: {
'Authorization': token,
'apikey': apiKey
}
});
console.log('\nResults WITHOUT tax:');
response2.data.forEach(item => {
const expected = EXPECTED[item.usage_date];
if (expected) {
const match = Math.abs(item.total_cost - expected) < 1;
console.log(` ${item.usage_date}: $${item.total_cost.toFixed(2)} (Expected: $${expected.toFixed(2)}) ${match ? '✅' : '❌'}`);
}
});
console.log('\n═══════════════════════════════════════════════════════════════');
console.log(' CONCLUSION');
console.log('═══════════════════════════════════════════════════════════════');
if (response2.data && response1.data) {
const taxIncluded = response1.data[0].total_cost;
const taxExcluded = response2.data[0].total_cost;
const taxAmount = taxIncluded - taxExcluded;
const taxPercent = (taxAmount / taxExcluded * 100).toFixed(1);
console.log(`\nMarch 2025 Analysis:`);
console.log(` With Tax: $${taxIncluded.toFixed(2)}`);
console.log(` Without Tax: $${taxExcluded.toFixed(2)}`);
console.log(` Tax Amount: $${taxAmount.toFixed(2)} (${taxPercent}%)`);
console.log(` Expected: $${EXPECTED['2025-03'].toFixed(2)}`);
if (Math.abs(taxExcluded - EXPECTED['2025-03']) < 1) {
console.log('\n✅ SUCCESS! When excluding tax, values match MANUAL_ANSWERS.txt!');
}
}
} catch (error) {
console.error('\n❌ Error:', error.message);
}
}
testSaolaWithoutTax().catch(console.error);