51 lines
2.2 KiB
JavaScript
51 lines
2.2 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { Info, Store } from '../src/coreconfig.js';
|
|
|
|
test('store seeds from the fallback Info', () => {
|
|
const store = new Store({ authGuardUrl: 'http://auth.example.com', carrierNodeUrl: 'http://carrier.example.com' });
|
|
assert.equal(store.authGuardUrl, 'http://auth.example.com');
|
|
assert.equal(store.carrierNodeUrl, 'http://carrier.example.com');
|
|
assert.deepEqual(store.carrierNodeUrls, ['http://carrier.example.com']);
|
|
});
|
|
|
|
test('store defaults to empty with no fallback', () => {
|
|
const store = new Store();
|
|
assert.equal(store.authGuardUrl, '');
|
|
assert.deepEqual(store.carrierNodeUrls, []);
|
|
});
|
|
|
|
test('set ignores a blank authGuardUrl rather than clobbering the existing one', () => {
|
|
const store = new Store({ authGuardUrl: 'http://auth.example.com' });
|
|
store.set({ authGuardUrl: '', carrierNodeUrl: 'http://carrier.example.com' });
|
|
assert.equal(store.authGuardUrl, 'http://auth.example.com');
|
|
assert.equal(store.carrierNodeUrl, 'http://carrier.example.com');
|
|
});
|
|
|
|
test('set only replaces carrierNodeUrls when the push actually carries one', () => {
|
|
const store = new Store({ carrierNodeUrl: 'http://carrier.example.com' });
|
|
store.set({ authGuardUrl: 'http://auth.example.com' });
|
|
assert.equal(store.carrierNodeUrl, 'http://carrier.example.com');
|
|
assert.equal(store.authGuardUrl, 'http://auth.example.com');
|
|
});
|
|
|
|
test('onUpdate is called with the resulting Info after set', () => {
|
|
const store = new Store();
|
|
const seen = [];
|
|
store.onUpdate((info) => seen.push(info));
|
|
store.set({ authGuardUrl: 'http://auth.example.com' });
|
|
assert.equal(seen.length, 1);
|
|
assert.equal(seen[0].authGuardUrl, 'http://auth.example.com');
|
|
});
|
|
|
|
test('Info.fromJSON/toJSON round-trip the wire shape', () => {
|
|
const payload = {
|
|
authGuardUrl: 'http://auth.example.com',
|
|
carrierNodeUrl: 'http://carrier.example.com',
|
|
carrierNodeUrls: ['http://carrier.example.com', 'http://carrier2.example.com'],
|
|
};
|
|
const info = Info.fromJSON(payload);
|
|
assert.deepEqual(info.carrierNodeUrls, ['http://carrier.example.com', 'http://carrier2.example.com']);
|
|
assert.equal(info.toJSON().carrierNodeUrl, 'http://carrier.example.com');
|
|
});
|