const test = require('node:test'); const assert = require('node:assert/strict'); require('../src/common'); const registerAuditLogRoutes = require('../src/web/routes/settings/audit-log'); test('audit log uses its own read permission and shared pagination partial', async () => { const handlers = {}; const app = { get(path, ...routeHandlers) { handlers[path] = routeHandlers; } }; registerAuditLogRoutes(app, { pool: { async query(sql) { if (String(sql).includes('FROM o_audit_events')) { return [[ { id: 1, occurred_at: '2026-08-16T12:00:00.000Z', category: 'authentication', event_type: 'login.success', target_label: 'newer', details_json: JSON.stringify({ changes: { content: { from: { title: 'Same', body: { color: 'red', keep: 'same' } }, to: { title: 'Same', body: { color: 'blue', keep: 'same' } } }, permissions: { from: ['dashboard.read', 'screens.read'], to: ['screens.read', 'playlists.read'] }, backgroundColor: { from: null, to: '#111111' }, logoPath: { from: '', to: '/media/logo.png' } } }) }, { id: 2, occurred_at: '2026-08-15T12:00:00.000Z', category: 'authentication', event_type: 'login.failed', target_label: 'older', details_json: null } ]]; } return [[]]; } }, formatDashboardDate() { return 'Aug 16, 2026'; } }); assert.ok(handlers['/settings/audit-log']); const request = { currentUser: { id: 7, permissions: ['audit-log.read', 'audit-log.allow'] }, query: {} }; let continued = false; handlers['/settings/audit-log'][0](request, {}, function () { continued = true; }); assert.equal(continued, true); const response = { send(value) { this.body = value; } }; await handlers['/settings/audit-log'][1](request, response, function (error) { throw error; }); assert.match(response.body, /Audit log/); assert.ok(response.body.indexOf('>All categories') < response.body.indexOf('>announcements')); assert.ok(response.body.indexOf('>announcements') < response.body.indexOf('>api-sources')); assert.ok(response.body.indexOf('>api-sources') < response.body.indexOf('>canvas-sizes')); assert.match(response.body, /table-pagination/); assert.match(response.body, /data-local-datetime/); assert.match(response.body, /audit-event-type-options/); assert.match(response.body, /login\.success/); assert.match(response.body, /content\.body\.color/); assert.match(response.body, />redblueExport