36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
|
|
const {
|
|
clearPublicSystemConfigCache,
|
|
getPublicSystemConfigCache,
|
|
getStalePublicSystemConfigCache,
|
|
setPublicSystemConfigCache,
|
|
} = require('../src/services/publicSystemConfigCache');
|
|
|
|
test.afterEach(() => {
|
|
clearPublicSystemConfigCache();
|
|
});
|
|
|
|
test('returns a cached website config before its expiry', () => {
|
|
const config = { site_name: '脉象' };
|
|
setPublicSystemConfigCache(config, 5000, 1000);
|
|
|
|
assert.equal(getPublicSystemConfigCache(5999), config);
|
|
});
|
|
|
|
test('does not return an expired website config', () => {
|
|
const config = { site_name: '旧名称' };
|
|
setPublicSystemConfigCache(config, 5000, 1000);
|
|
|
|
assert.equal(getPublicSystemConfigCache(6000), null);
|
|
assert.equal(getStalePublicSystemConfigCache(), config);
|
|
});
|
|
|
|
test('clears the cached website config after an update', () => {
|
|
setPublicSystemConfigCache({ site_name: '旧名称' }, 5000, 1000);
|
|
clearPublicSystemConfigCache();
|
|
|
|
assert.equal(getPublicSystemConfigCache(1001), null);
|
|
});
|