import assert from 'node:assert/strict'; import fs from 'node:fs/promises'; import os from 'node:os'; import path from 'node:path'; import { test } from 'node:test'; import { GameSystemsStore } from './gameSystemsStore'; import type { SystemDefinition } from '../../shared/characterSheet/types'; import { FORMAT_VERSION, SYSTEM_FORMAT } from '../../shared/characterSheet/types'; function sampleSystem(): SystemDefinition { return { format: SYSTEM_FORMAT, formatVersion: FORMAT_VERSION, id: 'shadowdark', name: 'Shadowdark', schemaVersion: 1, revision: 1, bricks: { attributes: [{ key: 'str', label: 'STR', scale: 'numeric', default: 10 }] }, creationRules: [], sheetLayout: { pageSize: 'fluid', grid: { size: 8 }, pages: [{ id: 'main', label: 'Main', widgets: [] }] }, }; } test('GameSystemsStore import list delete', async () => { const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'gs-')); const store = new GameSystemsStore(dir); await store.importSystem(sampleSystem()); const list = await store.list(); assert.equal(list.length, 1); assert.equal(list[0]!.id, 'shadowdark'); const bind = await store.bindSnapshot('shadowdark'); assert.ok(bind.snapshotHash.length === 64); const snap = await store.getSnapshot(bind.snapshotHash); assert.equal(snap?.id, 'shadowdark'); await store.delete('shadowdark'); assert.equal((await store.list()).length, 0); });