import { strict as assert } from 'node:assert'; import test from 'node:test'; import { DashboardService } from '../../src/dashboard/dashboard.service'; test('DashboardService returns numeric counts and recent activity consistently', async () => { const recent = [{ id: 'event-id', occurredAt: new Date('2026-08-13T12:00:00.000Z'), actorUsername: 'admin', action: 'AUTH_LOGIN_SUCCESS', entityType: 'auth_session', entityId: 'session-id', }]; const manager = { query: async (sql: string) => { if (sql.includes('COUNT(*) FROM users')) { return [{ activeUsers: '4', inactiveUsers: '2', activeSessions: '3', totalAssets: '12', assetsNeedValidation: '4', assetsWithoutGeometry: '6', plannedInspections: '2', openFindings: '8', awaitingCompanyResponse: '5', overdueCompanyResponses: '2', companyResponsesDueNext7Days: '1', awaitingVerificationSchedule: '4', overdueControls: '2', controlsNext30Days: '3', }]; } if (sql.includes('FROM inspection_findings finding')) return []; return recent; }, }; const dataSource = { transaction: async (_isolation: string, operation: (value: typeof manager) => unknown) => operation(manager), }; const result = await new DashboardService(dataSource as never).summary(); assert.deepEqual(result.counts, { activeUsers: 4, inactiveUsers: 2, activeSessions: 3, totalAssets: 12, assetsNeedValidation: 4, assetsWithoutGeometry: 6, plannedInspections: 2, openFindings: 8, awaitingCompanyResponse: 5, overdueCompanyResponses: 2, companyResponsesDueNext7Days: 1, awaitingVerificationSchedule: 4, overdueControls: 2, controlsNext30Days: 3, }); assert.equal(result.recentAudit, recent); assert.deepEqual(result.upcomingControls, []); assert.equal(typeof result.generatedAt, 'string'); });