Add analytics plugin package for tracking and metrics. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
206 lines
7.2 KiB
TypeScript
206 lines
7.2 KiB
TypeScript
/**
|
|
* Mock Data Provider Tests
|
|
* Validates all mock data conforms to TypeScript interfaces
|
|
*/
|
|
|
|
import { describe, it, expect } from 'vitest';
|
|
import { mockData } from './MockDataProvider';
|
|
|
|
describe('MockDataProvider', () => {
|
|
describe('Revenue Metrics', () => {
|
|
it('should have valid revenue metrics', () => {
|
|
expect(mockData.revenueMetrics).toBeDefined();
|
|
expect(mockData.revenueMetrics.totalRevenue).toBeGreaterThan(0);
|
|
expect(mockData.revenueMetrics.growthRate).toBeDefined();
|
|
});
|
|
|
|
it('should have revenue trend data', () => {
|
|
expect(mockData.revenueTrend).toBeDefined();
|
|
expect(mockData.revenueTrend.length).toBeGreaterThan(0);
|
|
expect(mockData.revenueTrend[0].date).toBeDefined();
|
|
});
|
|
|
|
it('should have revenue breakdown', () => {
|
|
expect(mockData.revenueBreakdown).toBeDefined();
|
|
expect(mockData.revenueBreakdown.bySource.length).toBeGreaterThan(0);
|
|
expect(mockData.revenueBreakdown.byProvider.length).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
|
|
describe('Transactions', () => {
|
|
it('should return transactions with pagination', () => {
|
|
const result = mockData.transactions();
|
|
expect(result.transactions.length).toBeGreaterThan(0);
|
|
expect(result.total).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should return transaction details', () => {
|
|
const details = mockData.transactionDetails('txn_001');
|
|
expect(details.id).toBeDefined();
|
|
expect(details.netAmount).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('P&L Statement', () => {
|
|
it('should have valid P&L data', () => {
|
|
expect(mockData.pnlStatement).toBeDefined();
|
|
expect(mockData.pnlStatement.revenue.total).toBeGreaterThan(0);
|
|
expect(mockData.pnlStatement.margins.gross).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should have P&L trend', () => {
|
|
expect(mockData.pnlTrend.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should have reserve progress', () => {
|
|
expect(mockData.reserveProgress.target).toBeGreaterThan(0);
|
|
expect(mockData.reserveProgress.percentage).toBeGreaterThanOrEqual(0);
|
|
});
|
|
|
|
it('should have correct gross profit calculation', () => {
|
|
const { pnlStatement } = mockData;
|
|
expect(pnlStatement.grossProfit).toBe(
|
|
pnlStatement.revenue.total - pnlStatement.costs.total
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('Real-Time Metrics', () => {
|
|
it('should have valid real-time data', () => {
|
|
expect(mockData.realTimeMetrics.activeUsers).toBeGreaterThanOrEqual(0);
|
|
expect(mockData.realTimeMetrics.systemLoad).toBeGreaterThanOrEqual(0);
|
|
expect(mockData.realTimeMetrics.systemLoad).toBeLessThanOrEqual(1);
|
|
});
|
|
|
|
it('should have activity data', () => {
|
|
expect(mockData.realTimeActivity.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should have active users data', () => {
|
|
expect(mockData.activeUsers.length).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
|
|
describe('Cost Metrics', () => {
|
|
it('should have valid cost data', () => {
|
|
expect(mockData.costMetrics.totalCosts).toBeGreaterThan(0);
|
|
const sumOfCosts = mockData.costMetrics.fixedCosts + mockData.costMetrics.variableCosts;
|
|
expect(sumOfCosts).toBeLessThanOrEqual(mockData.costMetrics.totalCosts * 1.01);
|
|
});
|
|
|
|
it('should have cost breakdown', () => {
|
|
expect(mockData.costBreakdown.byCategory.length).toBeGreaterThan(0);
|
|
expect(mockData.costBreakdown.byType.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should have budget comparison', () => {
|
|
expect(mockData.budgetComparison.totalBudget).toBeGreaterThan(0);
|
|
expect(mockData.budgetComparison.utilization).toBeGreaterThanOrEqual(0);
|
|
expect(mockData.budgetComparison.utilization).toBeLessThanOrEqual(100);
|
|
});
|
|
});
|
|
|
|
describe('Performance Metrics', () => {
|
|
it('should have valid performance data', () => {
|
|
expect(mockData.performanceMetrics.avgResponseTime).toBeGreaterThan(0);
|
|
expect(mockData.performanceMetrics.uptime).toBeGreaterThanOrEqual(0);
|
|
expect(mockData.performanceMetrics.uptime).toBeLessThanOrEqual(100);
|
|
});
|
|
|
|
it('should have ordered percentiles', () => {
|
|
const { p50ResponseTime, p95ResponseTime, p99ResponseTime } = mockData.performanceMetrics;
|
|
expect(p50ResponseTime).toBeLessThanOrEqual(p95ResponseTime);
|
|
expect(p95ResponseTime).toBeLessThanOrEqual(p99ResponseTime);
|
|
});
|
|
|
|
it('should have endpoint metrics', () => {
|
|
expect(mockData.endpointMetrics.length).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
|
|
describe('Error Metrics', () => {
|
|
it('should have valid error data', () => {
|
|
expect(mockData.errorMetrics.totalErrors).toBeGreaterThanOrEqual(0);
|
|
expect(mockData.errorMetrics.errorRate).toBeGreaterThanOrEqual(0);
|
|
});
|
|
|
|
it('should have errors by type', () => {
|
|
expect(mockData.errorsByType.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should have recent errors array', () => {
|
|
expect(Array.isArray(mockData.recentErrors)).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('Bounce Rate', () => {
|
|
it('should have valid bounce rate', () => {
|
|
expect(mockData.bounceRateMetrics.overallBounceRate).toBeGreaterThanOrEqual(0);
|
|
expect(mockData.bounceRateMetrics.overallBounceRate).toBeLessThanOrEqual(100);
|
|
});
|
|
|
|
it('should have bounce rate by page', () => {
|
|
expect(mockData.bounceRateByPage.length).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
|
|
describe('Conversion Metrics', () => {
|
|
it('should have valid conversion data', () => {
|
|
expect(mockData.conversionMetrics.overallConversionRate).toBeGreaterThanOrEqual(0);
|
|
});
|
|
|
|
it('should have funnel data starting at 100%', () => {
|
|
expect(mockData.funnelData.length).toBeGreaterThan(0);
|
|
expect(mockData.funnelData[0].rate).toBe(100);
|
|
});
|
|
|
|
it('should have funnel rates between 0 and 100', () => {
|
|
const { funnelData } = mockData;
|
|
funnelData.forEach(stage => {
|
|
expect(stage.rate).toBeGreaterThanOrEqual(0);
|
|
expect(stage.rate).toBeLessThanOrEqual(100);
|
|
});
|
|
});
|
|
|
|
it('should have conversion by source', () => {
|
|
expect(mockData.conversionBySource.length).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
|
|
describe('A/B Testing', () => {
|
|
it('should have valid A/B test metrics', () => {
|
|
expect(mockData.abTestMetrics.activeTests).toBeGreaterThanOrEqual(0);
|
|
expect(mockData.abTestMetrics.completedTests).toBeGreaterThanOrEqual(0);
|
|
});
|
|
|
|
it('should have active tests with valid status', () => {
|
|
expect(mockData.activeTests.length).toBeGreaterThan(0);
|
|
mockData.activeTests.forEach(test => {
|
|
expect(['running', 'completed', 'paused']).toContain(test.status);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('Data Quality', () => {
|
|
it('should have revenue sources summing to ~100%', () => {
|
|
const sum = mockData.revenueBreakdown.bySource.reduce(
|
|
(acc, item) => acc + item.percentage, 0
|
|
);
|
|
expect(sum).toBeLessThanOrEqual(100.1);
|
|
});
|
|
|
|
it('should have cost types summing to ~100%', () => {
|
|
const sum = mockData.costBreakdown.byType.reduce(
|
|
(acc, item) => acc + item.percentage, 0
|
|
);
|
|
expect(sum).toBeLessThanOrEqual(100.1);
|
|
});
|
|
|
|
it('should have positive transaction amounts', () => {
|
|
const { transactions } = mockData.transactions();
|
|
transactions.forEach(t => {
|
|
expect(t.amount).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
});
|
|
});
|