Persist user GUI preferences and resize the shared media modal
DC CMS qualification / qualify (push) Successful in 2m22s

This commit is contained in:
DCCONSTRUCTIONS
2026-11-13 17:56:23 +03:00
parent ff90b633d9
commit 5d56f5fe21
19 changed files with 321 additions and 110 deletions
+33
View File
@@ -0,0 +1,33 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { mkdtemp, readdir, readFile, rm, stat } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { UserPreferencesStore } from '../server/user-preferences.mjs';
test('user GUI metadata is isolated, durable, private and merges independent writes', async t => {
const root = await mkdtemp(join(tmpdir(), 'cms-user-meta-')); t.after(() => rm(root, { recursive: true, force: true }));
const store = new UserPreferencesStore(root);
assert.equal((await store.read('alice')).exists, false);
await Promise.all([
store.patch('alice', { appearance: { theme: 'light', accent: '#AABBCC' } }),
store.patch('alice', { gui: { modals: { 'media-library': { width: 1250, height: 800 } } } }),
store.patch('bob', { gui: { modals: { 'media-library': { width: 640, height: 480 } } } }),
]);
const restarted = new UserPreferencesStore(root);
const alice = (await restarted.read('alice')).preferences;
assert.equal(alice.appearance.theme, 'light'); assert.equal(alice.appearance.accent, '#aabbcc');
assert.deepEqual(alice.gui.modals['media-library'], {width:1250,height:800});
assert.equal((await restarted.read('bob')).preferences.gui.modals['media-library'].width, 640);
assert.deepEqual((await restarted.patch('alice', { appearance: { theme: 'dark' } }, { ifAbsent: true })).preferences, alice);
const files = await readdir(join(root,'.user-meta')); assert.equal(files.length, 2);
for (const file of files) {
assert.match(file, /^[a-f\d]{64}\.json$/);
assert.equal((await stat(join(root,'.user-meta',file))).mode & 0o777, 0o600);
assert.ok(JSON.parse(await readFile(join(root,'.user-meta',file))).gui);
}
for (const patch of [{ user: 'bob' }, { gui: { modals: { '../evil': {width:900,height:600} } } }, { gui: {modals: {'media-library': {width:1e7,height:800}}} }, {appearance:{accent:'red'}}, JSON.parse('{"gui":{"modals":{"__proto__":null}}}')]) {
await assert.rejects(store.patch('alice', patch), {status:400});
}
await assert.rejects(store.read(''), { status: 401 });
assert.deepEqual((await store.read('alice')).preferences, alice);
});