Files
SHiNE-server/shine-UI/tests/pending-header-identity.test.mjs
T

16 lines
1.0 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {savePendingHeaderIdentity,readPendingHeaderIdentity,clearPendingHeaderIdentity} from '../js/services/pending-header-identity.js';
test('pending HEADER declaration survives module reload and remains bound to login and key',async()=>{
const m=new Map();globalThis.localStorage={setItem:(k,v)=>m.set(k,v),getItem:k=>m.get(k),removeItem:k=>m.delete(k)};
const declaration={accountType:1,previousAccounts:['Bob@free']};
savePendingHeaderIdentity('Alice@shine','a+/=',declaration);
const fresh=await import('../js/services/pending-header-identity.js?reload');
assert.deepEqual(fresh.readPendingHeaderIdentity('alice@shine','a-_'),declaration);
assert.equal(fresh.readPendingHeaderIdentity('alice@shine','other'),null);
assert.equal(fresh.readPendingHeaderIdentity('bob@shine','a-_'),null);
clearPendingHeaderIdentity('Alice@shine','a+/=');
assert.equal(fresh.readPendingHeaderIdentity('alice@shine','a-_'),null);
delete globalThis.localStorage;
});