Update tests
This commit is contained in:
parent
9445bbd21f
commit
4e315e052a
2 changed files with 1385 additions and 147 deletions
48
frontend/sync-client/src/persistence/database.test.ts
Normal file
48
frontend/sync-client/src/persistence/database.test.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import { Database, createEmptyDatabase } from "./database";
|
||||
|
||||
test("current state keeps absent optional fields absent across save and reload", async () => {
|
||||
const initial = createEmptyDatabase("vault");
|
||||
initial.local = { local: "local.md", remote: "remote.md" };
|
||||
initial.documents = {
|
||||
local: { observedHash: "local" },
|
||||
remote: { remote: { vaultUpdateId: 1, contentSize: 3 } },
|
||||
empty: {}
|
||||
};
|
||||
let saved = structuredClone(initial);
|
||||
const restart = (): Database =>
|
||||
new Database(
|
||||
saved,
|
||||
async (next) => {
|
||||
saved = structuredClone(next);
|
||||
},
|
||||
"vault",
|
||||
async () => structuredClone(saved)
|
||||
);
|
||||
const db = restart();
|
||||
assert.deepEqual(db.state, initial);
|
||||
await db.save();
|
||||
assert.deepEqual(saved, initial);
|
||||
assert.deepEqual(restart().state, initial);
|
||||
});
|
||||
|
||||
test("current reset state is restored after an uncertain save", async () => {
|
||||
const saved = createEmptyDatabase("vault");
|
||||
saved.local = { note: "note.md" };
|
||||
saved.documents.note = {
|
||||
base: { vaultUpdateId: null, hash: "clean" },
|
||||
observedHash: "clean"
|
||||
};
|
||||
const db = new Database(
|
||||
undefined,
|
||||
async () => {
|
||||
throw new Error("interrupted");
|
||||
},
|
||||
"vault",
|
||||
async () => structuredClone(saved)
|
||||
);
|
||||
await assert.rejects(db.save(), /interrupted/);
|
||||
await db.recoverPersistence();
|
||||
assert.deepEqual(db.state, saved);
|
||||
});
|
||||
|
|
@ -9,7 +9,7 @@ describe("Settings logging", () => {
|
|||
const settings = new Settings(
|
||||
logger,
|
||||
{ token: "loaded-secret" },
|
||||
async () => {}
|
||||
async () => undefined
|
||||
);
|
||||
await settings.setSettings({ token: "updated-secret" });
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ it("owns settings arrays instead of sharing them with callers and listeners", as
|
|||
const settings = new Settings(
|
||||
new Logger(),
|
||||
{ ignorePatterns: original },
|
||||
async () => {}
|
||||
async () => undefined
|
||||
);
|
||||
original.push("external mutation");
|
||||
assert.deepEqual(settings.getSettings().ignorePatterns, ["original"]);
|
||||
|
|
@ -67,7 +67,9 @@ it("file eligibility follows successfully saved settings", async () => {
|
|||
maxFileSizeMB: 1
|
||||
},
|
||||
async () => {
|
||||
if (fail) throw new Error("save failed");
|
||||
if (fail) {
|
||||
throw new Error("save failed");
|
||||
}
|
||||
}
|
||||
);
|
||||
assert(settings.isIgnored("private/note.md"));
|
||||
|
|
|
|||
Loading…
Reference in a new issue