Skip to content

Commit

Permalink
Add automated test
Browse files Browse the repository at this point in the history
  • Loading branch information
personalizedrefrigerator committed Feb 15, 2024
1 parent b4f7612 commit b779203
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
37 changes: 37 additions & 0 deletions __test__/backup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ let spyOnLogWarn = null;
let spyOnLogError = null;
let spyOnShowError = null;
let spyOnSaveBackupInfo = null;
let spyOnDataGet = null;

const spyOnsSettingsValue = jest.spyOn(joplin.settings, "value");
const spyOnGlobalValue = jest.spyOn(joplin.settings, "globalValue");
Expand Down Expand Up @@ -60,6 +61,13 @@ describe("Backup", function () {
.calledWith("locale").mockImplementation(() => Promise.resolve("en_US"))
.calledWith("templateDir").mockImplementation(() => Promise.resolve(testPath.templates));

spyOnDataGet = jest
.spyOn(joplin.data, "get")
.mockImplementation(async (_path, _query) => ({
items: [],
hasMore: false,
}));

await createTestStructure();
backup = new Backup() as any;
backup.backupStartTime = new Date();
Expand Down Expand Up @@ -93,6 +101,7 @@ describe("Backup", function () {
spyOnShowError.mockReset();
spyOnsSettingsValue.mockReset();
spyOnGlobalValue.mockReset();
spyOnDataGet.mockReset();
spyOnSaveBackupInfo.mockReset();
});

Expand Down Expand Up @@ -1014,4 +1023,32 @@ describe("Backup", function () {
expect(backup.log.warn).toHaveBeenCalledTimes(0);
});
});

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("");

// Prevent "open handle" errors
backup.stopTimer();
});
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"husky": "^6.0.0",
"jest": "^27.0.4",
"jest-when": "^3.3.1",
"joplinplugindevtools": "^1.0.15",
"joplinplugindevtools": "^1.0.16",
"lint-staged": "^11.0.0",
"mime": "^2.5.2",
"on-build-webpack": "^0.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"description": "Execute command when backup is finished"
}
},
"backupReadme": "# Joplin Backup\n\nThe backups in this folder were created with the Simple Backup plugin for Joplin. The most recent backup was created on %s.\n\nSee the [Simple Backup documentation](https://joplinapp.org/plugins/plugin/io.github.jackgruber.backup/#restore) for information about how to restore from this backup.",
"backupReadme": "# Joplin Backup\n\nThis folder contains one or more backups of data from the Joplin note taking application. The most recent backup was created on %s.\n\nSee the [Simple Backup documentation](https://joplinapp.org/plugins/plugin/io.github.jackgruber.backup/#restore) for information about how to restore from this backup.",
"command": {
"createBackup": "Create backup"
}
Expand Down

0 comments on commit b779203

Please sign in to comment.