1import assert from 'node:assert/strict';2import test from 'node:test';34import {5 formatInvitationExpiry,6 grantLabel,7 normalizeInvitationSummary,8 shortPeerFingerprint,9} from './enrollment.mjs';1011const HOST = '12'.repeat(32);12const PEER = 'ab'.repeat(32);1314test('normalizes only a bounded public invitation summary', () => {15 const summary = normalizeInvitationSummary({16 host_node_id: HOST,17 peer_node_id: PEER,18 expires_at_unix: 1_100,19 grants: ['view', 'gamepad'],20 }, 1_000);21 assert.equal(summary.hostFingerprint, '12121212…12121212');22 assert.equal(summary.peerFingerprint, 'abababab…abababab');23 assert.deepEqual(summary.grants, ['view', 'gamepad']);24 assert.equal('token' in summary, false);25});2627test('rejects expired, malformed, duplicate, unknown, and raw-token-bearing summaries', () => {28 const base = { host_node_id: HOST, peer_node_id: PEER, expires_at_unix: 1_100, grants: ['view'] };29 assert.throws(() => normalizeInvitationSummary({ ...base, expires_at_unix: 1_000 }, 1_000));30 assert.throws(() => normalizeInvitationSummary({ ...base, host_node_id: 'nope' }, 1_000));31 assert.throws(() => normalizeInvitationSummary({ ...base, grants: ['view', 'view'] }, 1_000));32 assert.throws(() => normalizeInvitationSummary({ ...base, grants: ['admin'] }, 1_000));33 assert.throws(() => normalizeInvitationSummary({ ...base, token: 'secret' }, 1_000));34});3536test('formats fingerprints, grants, and bounded expiry copy', () => {37 assert.equal(shortPeerFingerprint(PEER), 'abababab…abababab');38 assert.equal(grantLabel('pointer_keyboard'), 'keyboard + mouse');39 assert.equal(formatInvitationExpiry(1_030, 1_000), 'expires in under 2 minutes');40 assert.equal(formatInvitationExpiry(1_121, 1_000), 'expires in 3 minutes');41 assert.equal(formatInvitationExpiry(999, 1_000), 'expired');42});