120 lines
4.7 KiB
JavaScript
120 lines
4.7 KiB
JavaScript
// Generated, do not edit. sha256:48e4432f919c88e3f0adaad52e46a88287459c06124c6a46c43d717bfbc8d8d8
|
|
import { describe, it, beforeEach, mock } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
const opslag = new Map();
|
|
const sleutel = (scope, key) => `${scope}::${key}`;
|
|
let stand = null;
|
|
|
|
mock.module('../../client/data/_rpc.js', {
|
|
namedExports: {
|
|
async rpc(module, functie, ...args) {
|
|
if (module === 'license-status' && functie === 'licenseStatus') return stand;
|
|
if (module === 'preferences' && functie === 'getPref') {
|
|
const [scope, key, fallback] = args;
|
|
return opslag.has(sleutel(scope, key)) ? opslag.get(sleutel(scope, key)) : fallback;
|
|
}
|
|
if (module === 'preferences' && functie === 'setPref') {
|
|
const [scope, key, waarde] = args;
|
|
opslag.set(sleutel(scope, key), waarde);
|
|
return null;
|
|
}
|
|
throw new Error(`onverwachte aanroep in deze test: ${module}.${functie}`);
|
|
},
|
|
decodeer: v => v,
|
|
setRowGuard() {},
|
|
rowGuardAan: () => false,
|
|
},
|
|
});
|
|
|
|
const { loadLicense, licenseFingerprint, licenseChangedSinceSeen, markLicenseSeen, counterText } =
|
|
await import('../../client/license.js');
|
|
const { setLocale } = await import('../../client/i18n/index.js');
|
|
const { CONFIG } = await import('../../shared/config.js');
|
|
|
|
const GRATIS = {
|
|
level: 'free', why: 'none', enforced: true, version: '1.0.0', installed: null,
|
|
installedCovers: false, buyer: null, issued: null, max: { assets: 1 }, features: { ai: false },
|
|
};
|
|
const BETAALD = {
|
|
level: 'full', why: 'licensed', enforced: true, version: '1.0.0',
|
|
installed: { buyer: 'npub1abc', issued: '2026-09-21', majorFrom: 1, majorTo: 'unlimited' },
|
|
installedCovers: true, buyer: 'npub1abc', issued: '2026-09-21', max: null, features: null,
|
|
};
|
|
|
|
beforeEach(() => { opslag.clear(); stand = GRATIS; });
|
|
|
|
describe('de vingerafdruk van de licentie', () => {
|
|
it('is gelijk voor twee keer dezelfde stand', () => {
|
|
assert.equal(licenseFingerprint(GRATIS), licenseFingerprint({ ...GRATIS }));
|
|
});
|
|
|
|
it('verschilt als de stand omslaat', () => {
|
|
assert.notEqual(licenseFingerprint(GRATIS), licenseFingerprint(BETAALD));
|
|
});
|
|
|
|
it('verschilt als een ANDERE licentie op dezelfde stand staat', () => {
|
|
const ander = { ...BETAALD, buyer: 'npub1xyz', installed: { ...BETAALD.installed, buyer: 'npub1xyz' } };
|
|
assert.notEqual(licenseFingerprint(BETAALD), licenseFingerprint(ander));
|
|
});
|
|
|
|
it('verschilt als het bereik verschuift, ook bij dezelfde koper', () => {
|
|
const smaller = { ...BETAALD, installed: { ...BETAALD.installed, majorTo: 1 } };
|
|
assert.notEqual(licenseFingerprint(BETAALD), licenseFingerprint(smaller));
|
|
});
|
|
|
|
it('verschilt als de REDEN verandert bij dezelfde stand', () => {
|
|
assert.notEqual(licenseFingerprint(GRATIS), licenseFingerprint({ ...GRATIS, why: 'invalid' }));
|
|
});
|
|
|
|
it('geeft een lege afdruk zonder momentopname, en gooit niet', () => {
|
|
assert.equal(licenseFingerprint(null), '');
|
|
});
|
|
});
|
|
|
|
describe('is er iets te melden', () => {
|
|
it('MELDT NIETS op de eerste ronde en legt de stand stil vast', async () => {
|
|
assert.equal(await licenseChangedSinceSeen(), false);
|
|
assert.equal(opslag.get(sleutel('license', 'seen')), undefined, 'er is nog niets geladen');
|
|
|
|
await loadLicense();
|
|
assert.equal(await licenseChangedSinceSeen(), false, 'de eerste ronde meldt niets');
|
|
assert.equal(opslag.get(sleutel('license', 'seen')), licenseFingerprint(GRATIS),
|
|
'en hij legt de stand vast, anders meldt de tweede ronde het alsnog');
|
|
assert.equal(await licenseChangedSinceSeen(), false, 'de tweede ronde ook niet');
|
|
});
|
|
|
|
it('meldt het zodra de stand omslaat, en zwijgt weer als je gekeken hebt', async () => {
|
|
await loadLicense();
|
|
await licenseChangedSinceSeen();
|
|
|
|
stand = BETAALD;
|
|
await loadLicense();
|
|
assert.equal(await licenseChangedSinceSeen(), true, 'een nieuwe licentie is nieuws');
|
|
|
|
await markLicenseSeen();
|
|
assert.equal(await licenseChangedSinceSeen(), false);
|
|
});
|
|
});
|
|
|
|
describe('de teller naast de plus', () => {
|
|
it('noemt wat hij telt, voor elke grens van de gratis editie en in elke taal', async () => {
|
|
const max = Object.fromEntries(Object.keys(CONFIG.LICENSE.FREE.MAX).map(k => [k, 1]));
|
|
stand = { ...GRATIS, max };
|
|
await loadLicense();
|
|
try {
|
|
for (const taal of ['nl', 'en']) {
|
|
setLocale(taal);
|
|
for (const soort of Object.keys(max)) assert.match(counterText(soort, 0), /^\S.*: 0 \S+ 1$/, `${taal}, ${soort}`);
|
|
}
|
|
} finally { setLocale('nl'); }
|
|
assert.equal(counterText('assets', 1), 'Assets naast valuta in de gratis editie: 1 van 1');
|
|
});
|
|
|
|
it('valt weg zonder grens', async () => {
|
|
stand = BETAALD;
|
|
await loadLicense();
|
|
assert.equal(counterText('assets', 1), null);
|
|
});
|
|
});
|