56 lines
2.1 KiB
TypeScript
56 lines
2.1 KiB
TypeScript
import { strict as assert } from 'node:assert';
|
|
import test from 'node:test';
|
|
import { DashboardService } from '../../src/dashboard/dashboard.service';
|
|
|
|
test('DashboardService returns F5 operational counts and inspector activity consistently', async () => {
|
|
const recent = [{
|
|
id: 'event-id',
|
|
occurredAt: new Date('2026-09-08T12:00:00.000Z'),
|
|
actorUsername: 'inspector1',
|
|
action: 'INSPECTION_STARTED',
|
|
entityType: 'inspection_visit',
|
|
entityId: 'visit-id',
|
|
}];
|
|
const manager = {
|
|
query: async (sql: string) => {
|
|
if (sql.includes('COUNT(*) FROM users')) {
|
|
return [{
|
|
activeUsers: '4', inactiveUsers: '2', activeSessions: '3',
|
|
totalAssets: '0', assetsNeedValidation: '0', assetsWithoutGeometry: '0', plannedInspections: '2',
|
|
openFindings: '8', actsInFollowUp: '6', findingsWithoutControlDate: '5', overdueControls: '2', controlsNext30Days: '3',
|
|
reportsWorking: '1', reportsOfficialized: '2', sealedActsWithoutReport: '4',
|
|
}];
|
|
}
|
|
if (sql.includes('FROM audit_events event')) return recent;
|
|
if (sql.includes('next_control_on AS "nextControlOn"')) return [];
|
|
throw new Error(`Unexpected DashboardService query in test: ${sql}`);
|
|
},
|
|
};
|
|
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, {
|
|
totalAssets: 0,
|
|
assetsNeedValidation: 0,
|
|
assetsWithoutGeometry: 0,
|
|
plannedInspections: 2,
|
|
activeUsers: 4,
|
|
inactiveUsers: 2,
|
|
activeSessions: 3,
|
|
openFindings: 8,
|
|
actsInFollowUp: 6,
|
|
findingsWithoutControlDate: 5,
|
|
overdueControls: 2,
|
|
controlsNext30Days: 3,
|
|
reportsWorking: 1,
|
|
reportsOfficialized: 2,
|
|
sealedActsWithoutReport: 4,
|
|
});
|
|
assert.deepEqual(result.recentInspectorActivity, recent);
|
|
assert.equal('recentAudit' in result, false);
|
|
assert.deepEqual(result.upcomingControls, []);
|
|
assert.equal(typeof result.generatedAt, 'string');
|
|
});
|