#!/usr/bin/env node
const https = require('https');
const axios = require('axios');
const axiosInstance = axios.create({
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
timeout: 30000 // 30 second timeout
});
async function testSaola() {
console.log('\nββββββββββββββββββββββββββββββββββββββββ');
console.log(' π SAOLA TEST RESULTS');
console.log('ββββββββββββββββββββββββββββββββββββββββ');
const baseUrl = 'https://api.umbrellacost.io/api/v1';
try {
console.log('\nπ 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);
// Get SAOLA account
const userResponse = await axiosInstance.get(`${baseUrl}/users`, {
headers: { 'Authorization': token }
});
const saolaAccount = userResponse.data.accounts?.find(acc =>
acc.accountKey === '9350' || acc.accountKey === 9350
);
const apiKey = `${userKey}:${saolaAccount?.accountKey || '9350'}:0`;
console.log('\nπ Querying SAOLA costs March-July 2025...');
const params = new URLSearchParams({
startDate: '2025-03-01',
endDate: '2025-07-31',
periodGranLevel: 'month',
groupBy: 'usagedate',
'costType': 'cost'
});
const response = await axiosInstance.get(`${baseUrl}/invoices/caui?${params}`, {
headers: {
'Authorization': token,
'apikey': apiKey
}
});
if (response.data && response.data.length > 0) {
console.log('\nβ
SAOLA Monthly Costs:');
console.log('ββββββββββββββββββββββββββββββββββββ');
response.data.forEach(item => {
const month = item.usage_date;
const monthName = {
'2025-03': 'March',
'2025-04': 'April',
'2025-05': 'May',
'2025-06': 'June',
'2025-07': 'July'
}[month];
if (monthName) {
console.log(`${monthName} 2025: $${item.total_cost.toFixed(2)}`);
}
});
console.log('ββββββββββββββββββββββββββββββββββββ');
console.log(`Account ID: ${response.data[0].account_id}`);
// Expected values
const expected = {
'2025-03': 104755.07,
'2025-04': 111340.42,
'2025-05': 149774.24,
'2025-06': 165666.57,
'2025-07': 183920.58
};
let allMatch = true;
for (const item of response.data) {
if (expected[item.usage_date]) {
const diff = Math.abs(item.total_cost - expected[item.usage_date]);
if (diff > 1) allMatch = false;
}
}
console.log(`\n${allMatch ? 'β
SAOLA TEST PASSED!' : 'β Some values differ from expected'}`);
}
} catch (error) {
console.error('β Error:', error.message);
}
}
testSaola();