Refractoring Stage 2 Add Refractor plan.md

This commit is contained in:
2026-10-16 16:27:09 +03:00
parent e5391dbb62
commit e398bc4e1a
23 changed files with 1259 additions and 370 deletions
+38
View File
@@ -0,0 +1,38 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { createAccountStore } = require('../desktop/account-store.cjs');
test('account store migrates a legacy single-account record and persists its generated id', async () => {
let stored = { email: 'user@example.com', password: 'secret' };
let saves = 0;
const repository = createAccountStore({
async load() { return stored; },
async save(value) { stored = value; saves += 1; }
}, { createId: () => 'migrated-account' });
assert.deepEqual(await repository.load(), {
accounts: [{ email: 'user@example.com', password: 'secret', id: 'migrated-account' }],
activeId: 'migrated-account'
});
assert.equal(saves, 1);
assert.equal(stored.activeId, 'migrated-account');
});
test('account store retains current account records without rewriting them', async () => {
const stored = { accounts: [{ id: 'account-1', email: 'user@example.com' }], activeId: 'account-1' };
let saves = 0;
const repository = createAccountStore({
async load() { return stored; },
async save() { saves += 1; }
});
assert.equal(await repository.load(), stored);
assert.equal(saves, 0);
});
test('account store distinguishes missing records from invalid store failures', async () => {
const missing = createAccountStore({ async load() { throw Object.assign(new Error('missing'), { code: 'ENOENT' }); } });
const broken = createAccountStore({ async load() { throw new Error('decrypt failed'); } });
assert.equal(await missing.load(), null);
await assert.rejects(() => broken.load(), /decrypt failed/);
});