diff --git a/src/services/db.test.ts b/src/services/db.test.ts index 3139dc4..f305085 100644 --- a/src/services/db.test.ts +++ b/src/services/db.test.ts @@ -933,6 +933,67 @@ describe("cleanLogLine: the known folders first, then withoutFolders (#497)", () }); }); +describe("the four Journal sites of db.ts take both curtains (#497)", () => { + // Glued to `;`, which starts no path: withoutFolders alone keeps `jean`. + const GLUED = "x;/home/jean dupont/notes/x.db"; + + beforeEach(() => { + setKnownFolders({ home: "/home/jean dupont" }); + vi.mocked(logWarn).mockClear(); + vi.mocked(logError).mockClear(); + }); + afterEach(() => { + setKnownFolders({}); + }); + + it("a failed close of the previous connection", async () => { + vi.mocked(h.fakeDb.close).mockImplementation(async () => { + throw new Error(`close refused for ${GLUED}`); + }); + h.fakeDb = makeFakeDb("next"); + + await connectToProfile("next.db"); + + expect(vi.mocked(logWarn).mock.calls.map((call) => call[0])).toEqual([ + "DB: closing the previous connection failed, continuing without it: close refused for x.db", + ]); + }); + + it("a failed checksum repair", async () => { + vi.mocked(invoke).mockImplementationOnce(async () => { + throw `Cannot open database: unable to open database file: ${GLUED}`; + }); + + await connectToProfile("profile_0a1b2c3d.db"); + + expect(vi.mocked(logError).mock.calls.map((call) => call[0])).toEqual([ + "Migration repair failed: Cannot open database: unable to open database file: x.db", + ]); + }); + + it("a stopped catch-up, and the copy it names", () => { + const lines = describePreparation( + "x.db", + report({ catch_up_error: `backup_failed: unable to open database: ${GLUED}`, catch_up_backup: GLUED }) + ); + expect(lines.errors).toEqual([ + "Profile x.db: database update stopped: backup_failed: unable to open database: x.db; copy of the previous state kept as x.db", + ]); + }); + + it("a failed preparation", async () => { + h.prepare = async () => { + throw new Error(`Cannot read ${GLUED}`); + }; + + await connectToProfile("profile_0a1b2c3d.db"); + + expect(vi.mocked(logError).mock.calls.map((call) => call[0])).toEqual([ + "Profile profile_0a1b2c3d.db: database preparation failed: Cannot read x.db", + ]); + }); +}); + // --------------------------------------------------------------------------- // connectToProfile waits for the known folders (#497). initKnownFolders() // runs once per module instance, so each test takes a fresh db.ts with its own