Files
support_backend/tests/unit/platform/reports/rate-helpers.test.ts
T
saqib mirandClaude Sonnet 5 d65683641a feat(015-reporting-dashboards): four real reporting/analytics endpoints
Wires the pre-scaffolded, unused platform/reports module (ReportsService
.generateSummaryReport previously returned {}) into four real, admin-
gated dashboards matching docs/09-testing-observability-cicd.md's own
table:

- GET /admin/reports/management: total cases, AI-resolved, human-
  escalated, resolved/open, SLA compliance/breaches, escalation count,
  average response/resolution time.
- GET /admin/reports/product/:externalProductId: support volume,
  problem-category breakdown, recurring problems, AI-resolution/human-
  escalation rate, top error codes.
- GET /admin/reports/support: current per-agent workload, SLA at-risk/
  breached counts, escalation count, response/resolution performance.
- GET /admin/reports/ai: AI resolution/human-handoff rate, failed-
  troubleshooting-then-escalated rate, knowledge-match rate, confidence
  distribution (reusing 005-ai-support's own decideConfidenceBand),
  tool invocation success/failure.

Every rate/average is number|null -- null means no qualifying data in
range, never a computed NaN or a misleading 0. Adds one new durable
table, ErrorCodeLookup, since 014-full-observability's own equivalent
metric is a process-lifetime Prometheus counter unusable for a
historical "top errors" report.

Verified end-to-end against real Postgres/Redis: every figure checked
against hand-computed expected values, including a no-activity range
(all-zero counts, all-null rates) and cross-product isolation.

Also fixes a real regression the new ErrorCodeLookup FK caused in the
pre-existing known-issues.test.ts (its afterAll deleted ErrorCode rows
before the now-referencing lookup rows).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-09 11:59:38 +05:30

28 lines
977 B
TypeScript

import { describe, it, expect } from 'vitest';
import { computeRate, computeAverageSeconds } from '@/modules/platform/reports/mapper';
describe('computeRate (015-reporting-dashboards research.md §3)', () => {
it('returns null when the denominator is zero — never NaN, never a computed 0', () => {
expect(computeRate(0, 0)).toBeNull();
expect(computeRate(5, 0)).toBeNull();
});
it('computes a real rate when there is qualifying data', () => {
expect(computeRate(3, 12)).toBe(0.25);
});
it('returns a real 0 when the numerator is legitimately zero but the denominator is not', () => {
expect(computeRate(0, 10)).toBe(0);
});
});
describe('computeAverageSeconds', () => {
it('returns null for an empty list — no fabricated average', () => {
expect(computeAverageSeconds([])).toBeNull();
});
it('averages a list of millisecond durations into seconds', () => {
expect(computeAverageSeconds([1000, 2000, 3000])).toBe(2);
});
});