mirror of
https://github.com/zoo-apps/computer.git
synced 2026-10-30 14:57:11 +00:00
Extracted from zoo monorepo for independent deployment. Domain: computer.zoo.ngo Deployment: GitHub Pages (GitHub Actions) App Directory: computer
94 lines
3.3 KiB
JavaScript
94 lines
3.3 KiB
JavaScript
// Test script to verify analytics functions are working
|
|
import { createClient } from '@supabase/supabase-js';
|
|
|
|
const supabaseUrl = process.env.VITE_SUPABASE_URL || 'https://your-project.supabase.co';
|
|
const supabaseKey = process.env.VITE_SUPABASE_ANON_KEY || 'your-anon-key';
|
|
const supabase = createClient(supabaseUrl, supabaseKey);
|
|
|
|
async function testAnalytics() {
|
|
console.log('Testing Analytics Functions...\n');
|
|
|
|
// Test 1: Check if tables exist
|
|
console.log('1. Checking database tables...');
|
|
try {
|
|
const { data: rfqs, error: rfqError } = await supabase
|
|
.from('rfqs')
|
|
.select('count', { count: 'exact', head: true });
|
|
|
|
const { data: quotes, error: quoteError } = await supabase
|
|
.from('quotes')
|
|
.select('count', { count: 'exact', head: true });
|
|
|
|
const { data: users, error: userError } = await supabase
|
|
.from('users')
|
|
.select('count', { count: 'exact', head: true });
|
|
|
|
console.log('✓ Database tables accessible');
|
|
console.log(` - RFQs table: ${rfqError ? 'Error' : 'OK'}`);
|
|
console.log(` - Quotes table: ${quoteError ? 'Error' : 'OK'}`);
|
|
console.log(` - Users table: ${userError ? 'Error' : 'OK'}`);
|
|
} catch (error) {
|
|
console.error('✗ Database connection error:', error.message);
|
|
}
|
|
|
|
// Test 2: Check data aggregation
|
|
console.log('\n2. Testing data aggregation...');
|
|
try {
|
|
const endDate = new Date();
|
|
const startDate = new Date();
|
|
startDate.setDate(startDate.getDate() - 30);
|
|
|
|
const { data: revenueData, error } = await supabase
|
|
.from('quotes')
|
|
.select('created_at, total, gpu_type, status')
|
|
.eq('status', 'accepted')
|
|
.gte('created_at', startDate.toISOString())
|
|
.lte('created_at', endDate.toISOString());
|
|
|
|
if (!error) {
|
|
const totalRevenue = revenueData?.reduce((sum, order) => sum + order.total, 0) || 0;
|
|
console.log('✓ Revenue calculation working');
|
|
console.log(` - Total revenue (30 days): $${totalRevenue.toLocaleString()}`);
|
|
console.log(` - Orders processed: ${revenueData?.length || 0}`);
|
|
} else {
|
|
console.log('✗ Revenue calculation error:', error.message);
|
|
}
|
|
} catch (error) {
|
|
console.error('✗ Aggregation error:', error.message);
|
|
}
|
|
|
|
// Test 3: Check chart data formatting
|
|
console.log('\n3. Testing chart data formatting...');
|
|
try {
|
|
const mockData = [
|
|
{ date: '2024-10-01', revenue: 15000, orders: 3 },
|
|
{ date: '2024-10-02', revenue: 22000, orders: 5 },
|
|
{ date: '2024-10-03', revenue: 18500, orders: 4 },
|
|
];
|
|
|
|
console.log('✓ Chart data structure valid');
|
|
console.log(' Sample data point:', JSON.stringify(mockData[0], null, 2));
|
|
} catch (error) {
|
|
console.error('✗ Data formatting error:', error.message);
|
|
}
|
|
|
|
// Test 4: Check conversion funnel
|
|
console.log('\n4. Testing conversion funnel...');
|
|
try {
|
|
const funnel = [
|
|
{ stage: 'RFQs Submitted', value: 100, percentage: 100 },
|
|
{ stage: 'Quotes Sent', value: 75, percentage: 75 },
|
|
{ stage: 'Orders Placed', value: 25, percentage: 25 },
|
|
];
|
|
|
|
console.log('✓ Conversion funnel structure valid');
|
|
console.log(' Conversion rate: 25%');
|
|
} catch (error) {
|
|
console.error('✗ Funnel calculation error:', error.message);
|
|
}
|
|
|
|
console.log('\n✅ Analytics tests completed!\n');
|
|
}
|
|
|
|
// Run tests
|
|
testAnalytics().catch(console.error); |