// The waiter's cached bootstrap (plan step 4.1): offline it starts with the last bootstrap of // the same session only. import assert from 'node:assert/strict' import { test } from 'node:test' import { makeBootstrapCache } from '../src/logic/bootstrapCache.js' function memory() { const m = new Map() return { getItem: k => (m.has(k) ? m.get(k) : null), setItem: (k, v) => m.set(k, String(v)) } } test('the same session gets its saved bootstrap back; another session or none gets nothing', () => { const store = memory() const cache = makeBootstrapCache(store, () => 'xenia:site:bootstrap') assert.equal(cache.load('tok-a'), null) cache.save('tok-a', { user: { id: 7 }, permissions: ['ordering.orders.open'] }) assert.deepEqual(cache.load('tok-a'), { user: { id: 7 }, permissions: ['ordering.orders.open'] }) assert.equal(cache.load('tok-b'), null, "another waiter's session never sees it") assert.equal(cache.load(null), null) cache.save(null, { user: null }) assert.deepEqual(cache.load(null), { user: null }, 'signed out: the anonymous bootstrap') assert.equal(cache.load('tok-a'), null) }) test('a damaged entry is ignored', () => { const store = memory() store.setItem('k', '{not json') assert.equal(makeBootstrapCache(store, () => 'k').load('t'), null) })