Complete test coverage implementation for errors.bitreport.pt: admin-ui (98 tests): - test/components/: AppShell, DataAlert, IncidentNotes, KpiCard, SeverityBadge, StateBadge - test/lib/: format, demo-incidents, incidents-data, incidents-data-api, stats-data, stats-data-api - vitest.config.ts with jsdom + v8 coverage + @vitejs/plugin-react api route tests (54 tests): - src/routes/admin/auth.test.ts (15 tests) - src/routes/admin/incidents.test.ts (11 tests) - src/routes/admin/stats.test.ts (18 tests) - src/routes/public/errorMonitoringStats.test.ts (10 tests) collector-worker db/scheduler tests (22 tests): - src/db/collectorRunWriter.test.ts (10 tests) - src/db/loadActiveSources.test.ts (6 tests) - src/scheduler/runHttpSourceOnce.test.ts (6 tests) ingest-api service tests (13 tests): - src/buildApp.test.ts, plugins/prometheus.test.ts - services/ingestAuth.test.ts, services/processIngestBatch.utils.test.ts Total: 187 additional tests (255 total across all modules). All pass. Paperclip-Issue: BIT-15744 Co-Authored-By: Paperclip <[email protected]>
68 lines
2.4 KiB
TypeScript
68 lines
2.4 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest';
|
|
import { aggregateIncidentKpisFromSummary } from '@/lib/stats-data';
|
|
import type { StatsSummaryPayload } from '@/lib/stats-data';
|
|
|
|
import { fetchOperationalStats } from '@/lib/stats-data';
|
|
|
|
vi.mock('next/headers', () => ({
|
|
cookies: vi.fn().mockResolvedValue({ get: vi.fn().mockReturnValue(undefined) }),
|
|
}));
|
|
|
|
describe('fetchOperationalStats — not_configured', () => {
|
|
it('returns error when API is not configured', async () => {
|
|
delete process.env.ERROR_REPORTING_ADMIN_API_BASE;
|
|
const result = await fetchOperationalStats();
|
|
expect(result.ok).toBe(false);
|
|
if (!result.ok) {
|
|
expect(typeof result.message).toBe('string');
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('aggregateIncidentKpisFromSummary', () => {
|
|
it('returns zeros for empty byProject list', () => {
|
|
const summary: StatsSummaryPayload = { byProject: [] };
|
|
const result = aggregateIncidentKpisFromSummary(summary);
|
|
expect(result).toEqual({ total: 0, open: 0, investigating: 0, resolved: 0, ignored: 0 });
|
|
});
|
|
|
|
it('sums across a single project', () => {
|
|
const summary: StatsSummaryPayload = {
|
|
byProject: [
|
|
{ projectSlug: 'proj-a', total: 10, open: 3, investigating: 2, resolved: 4, ignored: 1 },
|
|
],
|
|
};
|
|
const result = aggregateIncidentKpisFromSummary(summary);
|
|
expect(result.total).toBe(10);
|
|
expect(result.open).toBe(3);
|
|
expect(result.investigating).toBe(2);
|
|
expect(result.resolved).toBe(4);
|
|
expect(result.ignored).toBe(1);
|
|
});
|
|
|
|
it('sums across multiple projects', () => {
|
|
const summary: StatsSummaryPayload = {
|
|
byProject: [
|
|
{ projectSlug: 'proj-a', total: 5, open: 2, investigating: 1, resolved: 1, ignored: 1 },
|
|
{ projectSlug: 'proj-b', total: 8, open: 4, investigating: 2, resolved: 2, ignored: 0 },
|
|
],
|
|
};
|
|
const result = aggregateIncidentKpisFromSummary(summary);
|
|
expect(result.total).toBe(13);
|
|
expect(result.open).toBe(6);
|
|
expect(result.investigating).toBe(3);
|
|
expect(result.resolved).toBe(3);
|
|
expect(result.ignored).toBe(1);
|
|
});
|
|
|
|
it('handles projects with all zeros', () => {
|
|
const summary: StatsSummaryPayload = {
|
|
byProject: [
|
|
{ projectSlug: 'empty', total: 0, open: 0, investigating: 0, resolved: 0, ignored: 0 },
|
|
],
|
|
};
|
|
const result = aggregateIncidentKpisFromSummary(summary);
|
|
expect(result.total).toBe(0);
|
|
});
|
|
});
|