111 lines
2.7 KiB
JavaScript
111 lines
2.7 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
|
|
require('../src/common');
|
|
|
|
const registerClientsRoutes = require('../src/web/routes/signage/clients/routes');
|
|
const renderConnectedClientsPage = require('../src/web/routes/signage/clients/list');
|
|
|
|
function createHandlers() {
|
|
const handlers = {};
|
|
const app = {
|
|
get(path, ...routeHandlers) {
|
|
handlers[path] = routeHandlers;
|
|
}
|
|
};
|
|
|
|
return { app, handlers };
|
|
}
|
|
|
|
test('clients list defaults to client then ip ordering', async () => {
|
|
const { app, handlers } = createHandlers();
|
|
|
|
registerClientsRoutes(app, {
|
|
pool: {},
|
|
common: {
|
|
getSearchQuery() {
|
|
return '';
|
|
},
|
|
getSortQuery() {
|
|
return '';
|
|
},
|
|
getSortDirectionQuery() {
|
|
return 'asc';
|
|
}
|
|
},
|
|
pages: {
|
|
renderConnectedClientsPage(data) {
|
|
return JSON.stringify(data.clients.map(function (client) {
|
|
return {
|
|
client_name: client.client_name,
|
|
clientIp: client.clientIp
|
|
};
|
|
}));
|
|
}
|
|
},
|
|
buildDashboardState: async () => ({
|
|
screens: [],
|
|
clients: [
|
|
{ client_name: 'Beta', clientIp: '10.0.0.9' },
|
|
{ client_name: 'Alpha', clientIp: '10.0.0.20' },
|
|
{ client_name: 'Alpha', clientIp: '10.0.0.2' }
|
|
]
|
|
}),
|
|
requirePermission() {
|
|
return function (_req, _res, next) {
|
|
next();
|
|
};
|
|
}
|
|
});
|
|
|
|
const routeHandlers = handlers['/clients'];
|
|
assert.equal(Array.isArray(routeHandlers), true);
|
|
|
|
const response = {
|
|
statusCode: 200,
|
|
body: null,
|
|
send(value) {
|
|
this.body = value;
|
|
return this;
|
|
}
|
|
};
|
|
|
|
await routeHandlers[1]({
|
|
query: {},
|
|
currentUser: { id: 1 }
|
|
}, response, () => {});
|
|
|
|
assert.deepEqual(JSON.parse(response.body), [
|
|
{ client_name: 'Alpha', clientIp: '10.0.0.2' },
|
|
{ client_name: 'Alpha', clientIp: '10.0.0.20' },
|
|
{ client_name: 'Beta', clientIp: '10.0.0.9' }
|
|
]);
|
|
});
|
|
|
|
test('clients page renders action cells for clients with permission', () => {
|
|
const html = renderConnectedClientsPage(
|
|
{
|
|
screens: [],
|
|
clients: [
|
|
{
|
|
id: 'row-1',
|
|
clientId: 'client-1',
|
|
screen_slug: 'demo-lobby',
|
|
screen_name: 'Demo Lobby Screen',
|
|
client_name: 'Local Test',
|
|
clientIp: '192.168.0.1',
|
|
player_url: 'http://player.local',
|
|
connectedAt: new Date('2026-08-07T20:00:00Z'),
|
|
connectedAtLabel: 'Aug 07, 2026, 8:00:00 PM'
|
|
}
|
|
],
|
|
pagination: null
|
|
},
|
|
'',
|
|
{ id: 1, permissions: ['clients.read', 'clients.allow'] }
|
|
);
|
|
|
|
assert.match(html, /data-label="Actions"/);
|
|
assert.match(html, /Pause client/);
|
|
assert.match(html, /Blackout client/);
|
|
}); |