hub-roles-first-write-guard.test.mjs file-level

at sha256:8 · View file ↗ · Intel ↗

History
1 files
1 commits
0 hotspots
0 🧊 dead
0 💥 blast risk
sha256:9 feat(calendar): hosted bridge/gateway route parity and timeline noteRec… · aaronrene · Jun 19, 2026
1 /**
2 * First write to hub_roles.json must keep the acting user as admin so local operators
3 * are not locked out of Team / POST /api/v1/roles (see hub/roles.mjs + hub/server.mjs).
4 */
5 import { test } from 'node:test';
6 import assert from 'node:assert/strict';
7 import { ensureActorAdminOnFirstRolesPopulation } from '../hub/roles.mjs';
8
9 test('first population: adds actor as admin alongside new row', () => {
10 const out = ensureActorAdminOnFirstRolesPopulation(
11 0,
12 { 'google:999': 'viewer' },
13 'google:111',
14 );
15 assert.deepEqual(out, {
16 'google:999': 'viewer',
17 'google:111': 'admin',
18 });
19 });
20
21 test('first population: actor already in map keeps admin if set', () => {
22 const out = ensureActorAdminOnFirstRolesPopulation(
23 0,
24 { 'google:111': 'admin', 'google:999': 'editor' },
25 'google:111',
26 );
27 assert.equal(out['google:111'], 'admin');
28 assert.equal(out['google:999'], 'editor');
29 });
30
31 test('subsequent writes: does not inject admin row', () => {
32 const out = ensureActorAdminOnFirstRolesPopulation(
33 2,
34 { 'google:111': 'admin', 'google:999': 'evaluator' },
35 'google:111',
36 );
37 assert.deepEqual(out, { 'google:111': 'admin', 'google:999': 'evaluator' });
38 });
39
40 test('empty actor sub: unchanged', () => {
41 const row = { 'google:999': 'viewer' };
42 assert.deepEqual(ensureActorAdminOnFirstRolesPopulation(0, row, ''), row);
43 assert.deepEqual(ensureActorAdminOnFirstRolesPopulation(0, row, ' '), row);
44 });