From a3e46fb70eba20c61386b9890ccb9c919a7bf791 Mon Sep 17 00:00:00 2001 From: Henry H Date: Sat, 17 Feb 2024 08:26:53 -0800 Subject: [PATCH] Fix README written to wrong location when revisions are enabled --- __test__/backup.test.ts | 53 ++++++++++++++++++++++------------------- src/Backup.ts | 2 +- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/__test__/backup.test.ts b/__test__/backup.test.ts index 49e6832..5695db0 100644 --- a/__test__/backup.test.ts +++ b/__test__/backup.test.ts @@ -52,7 +52,10 @@ describe("Backup", function () { when(spyOnsSettingsValue) .mockImplementation(() => Promise.resolve("no mockImplementation")) .calledWith("fileLogLevel").mockImplementation(() => Promise.resolve("error")) - .calledWith("path").mockImplementation(() => Promise.resolve(testPath.backupBasePath)); + .calledWith("path").mockImplementation(() => Promise.resolve(testPath.backupBasePath)) + .calledWith("zipArchive").mockImplementation(() => "no") + .calledWith("execFinishCmd").mockImplementation(() => "") + .calledWith("usePassword").mockImplementation(() => false); /* prettier-ignore */ when(spyOnGlobalValue) @@ -1025,30 +1028,30 @@ describe("Backup", function () { }); describe("create backup readme", () => { - it("should create a README.md in the backup directory", async () => { - backup.backupStartTime = null; - backup.passwordEnabled = false; - - when(spyOnsSettingsValue) - .calledWith("zipArchive") - .mockImplementation(() => "no"); - when(spyOnsSettingsValue) - .calledWith("execFinishCmd") - .mockImplementation(() => ""); - - await backup.start(); - - // Should exist and be non-empty - const readmePath = path.join( - testPath.backupBasePath, - "JoplinBackup", - "README.md" - ); - expect(await fs.pathExists(readmePath)).toBe(true); - expect(await fs.readFile(readmePath, "utf8")).not.toBe(""); + it.each([{ backupRetention: 1 }, { backupRetention: 2 }])( + "should create a README.md in the backup directory (case %#)", + async ({ backupRetention }) => { + when(spyOnsSettingsValue) + .calledWith("backupRetention") + .mockImplementation(async () => backupRetention) + .calledWith("backupInfo") + .mockImplementation(() => Promise.resolve("[]")); + + backup.backupStartTime = null; + await backup.start(); + + // Should exist and be non-empty + const readmePath = path.join( + testPath.backupBasePath, + "JoplinBackup", + "README.md" + ); + expect(await fs.pathExists(readmePath)).toBe(true); + expect(await fs.readFile(readmePath, "utf8")).not.toBe(""); - // Prevent "open handle" errors - backup.stopTimer(); - }); + // Prevent "open handle" errors + backup.stopTimer(); + } + ); }); }); diff --git a/src/Backup.ts b/src/Backup.ts index 6fec441..36416a9 100644 --- a/src/Backup.ts +++ b/src/Backup.ts @@ -477,8 +477,8 @@ class Backup { await this.backupNotebooks(); const backupDst = await this.makeBackupSet(); - await this.writeReadme(backupDst); + await this.writeReadme(this.backupBasePath); await joplin.settings.setValue( "lastBackup", this.backupStartTime.getTime()