feat(manager): Devices page — pair by code, app, name, sign-in mode, link, change app, remove

Platform-v2 step 2.6d:
- /devices (core.devices.manage, sidebar): devices from /api/devices with
  status (online / last seen / waiting for the device / app turned off /
  removed), app, sign-in mode (own or venue default), linked device; usage per
  device app against the license limit (devices)
- pair dialog: code as typed (normalized), app (only apps that are on, "all in
  use" when the limit is reached), name, sign-in mode for apps with a choice,
  optional linked device; license.limit_reached explained with the app's limit
- edit (name, sign-in mode, link), change app (signs out whoever is on it),
  remove with confirm (the device goes back to pairing), show removed
- manager_dashboard gets node --test (tests/platform.test.mjs: module states,
  dependents, device status/usage/room/links), added to run-all
- e2e manager.mjs: 54 checks (+ wrong code, normalized code, pair, the device
  picks up its token, online, rename, change app, remove → device.revoked)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 23:22:43 +02:00
co-authored by Claude Opus 5.5
parent 1f28016122
commit cc00ec39c7
12 changed files with 638 additions and 5 deletions
+64
View File
@@ -0,0 +1,64 @@
// Pure logic of the platform pages (plan steps 2.6c, 2.6d).
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { deviceStatus, deviceUsage, hasRoom, linkTargets, normalizeCode } from '../src/pages/platform/devicesLogic.js'
import { moduleState, stoppedBy } from '../src/pages/platform/modulesLogic.js'
const mod = (key, extra = {}) => ({ key, depends: [], can_disable: true, entitled: true, enabled: true, effective: true, limits: [], device_app: null, ...extra })
test('module state', () => {
assert.equal(moduleState(mod('core', { can_disable: false })), 'always')
assert.equal(moduleState(mod('kds', { entitled: false, effective: false })), 'not_licensed')
assert.equal(moduleState(mod('kds')), 'on')
assert.equal(moduleState(mod('kds', { effective: false })), 'waiting')
assert.equal(moduleState(mod('kds', { enabled: false, effective: false })), 'off')
})
test('turning a module off stops what depends on it, directly or not (only those that are on)', () => {
const modules = [
mod('catalog'), mod('ordering', { depends: ['catalog'] }), mod('kds', { depends: ['ordering'] }),
mod('pos_counter', { depends: ['ordering'] }), mod('customer_display', { depends: ['pos_counter'] }),
mod('pricing', { depends: ['ordering'], effective: false }), mod('notes'),
]
assert.deepEqual(stoppedBy('ordering', modules).map(m => m.key).sort(), ['customer_display', 'kds', 'pos_counter'])
assert.deepEqual(stoppedBy('notes', modules), [])
})
test('device status', () => {
const now = Date.parse('2026-11-13T12:00:00Z')
const d = { claimed: true, revoked_at: null, last_seen_at: '2026-11-13T11:58:30Z' }
assert.equal(deviceStatus(d, { now }), 'online')
assert.equal(deviceStatus({ ...d, last_seen_at: '2026-11-13T11:50:00Z' }, { now }), 'offline')
assert.equal(deviceStatus({ ...d, last_seen_at: null }, { now }), 'offline')
assert.equal(deviceStatus({ ...d, claimed: false }, { now }), 'waiting')
assert.equal(deviceStatus(d, { now, appOn: false }), 'app_off')
assert.equal(deviceStatus({ ...d, revoked_at: '2026-11-13T11:00:00Z' }, { now }), 'removed')
})
test('pairing codes as typed', () => {
assert.equal(normalizeCode(' ab-c d2e '), 'ABCD2E')
assert.equal(normalizeCode('k7m9pq2x'), 'K7M9PQ')
assert.equal(normalizeCode(null), '')
})
test('device usage against the license limit', () => {
const modules = [
mod('kds', { device_app: {}, limits: [{ key: 'devices', value: 2 }] }),
mod('signage', { device_app: {}, limits: [{ key: 'devices', value: null }] }),
mod('notes'),
]
const devices = [
{ app_key: 'kds', revoked_at: null }, { app_key: 'kds', revoked_at: '2026-01-01T00:00:00Z' },
{ app_key: 'kds', revoked_at: null }, { app_key: 'signage', revoked_at: null },
]
const usage = deviceUsage(devices, modules)
assert.deepEqual(usage, { kds: { used: 2, max: 2 }, signage: { used: 1, max: null } })
assert.equal(hasRoom(usage, 'kds'), false)
assert.equal(hasRoom(usage, 'kds', { moving: true }), true)
assert.equal(hasRoom(usage, 'signage'), true)
})
test('link targets: not itself, not removed', () => {
const devices = [{ id: 1, revoked_at: null }, { id: 2, revoked_at: 'x' }, { id: 3, revoked_at: null }]
assert.deepEqual(linkTargets(devices, 1).map(d => d.id), [3])
})