mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 06:59:31 +01:00
test: fix backup tests
This commit is contained in:
@@ -43,6 +43,7 @@ function encrypt(password, data) {
|
||||
function decrypt(key, data) {
|
||||
if (
|
||||
!key ||
|
||||
!data.key ||
|
||||
key.password === data.key.password ||
|
||||
key.key.password === data.key.password
|
||||
)
|
||||
@@ -62,8 +63,8 @@ async function hash(password, userId) {
|
||||
return password;
|
||||
}
|
||||
|
||||
async function generateCryptoKey(password) {
|
||||
return password;
|
||||
async function generateCryptoKey(password, salt) {
|
||||
return { password, salt };
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
} from "./utils";
|
||||
import v52Backup from "./__fixtures__/backup.v5.2.json";
|
||||
import v52BackupCopy from "./__fixtures__/backup.v5.2.copy.json";
|
||||
import { qclone } from "qclone";
|
||||
|
||||
beforeEach(() => {
|
||||
StorageInterface.clear();
|
||||
@@ -37,7 +38,7 @@ test("import backup", () =>
|
||||
notebookTest().then(async ({ db, id }) => {
|
||||
const exp = await db.backup.export("node");
|
||||
StorageInterface.clear();
|
||||
await db.backup.import(exp);
|
||||
await db.backup.import(JSON.parse(exp));
|
||||
expect(db.notebooks.notebook(id).data.id).toBe(id);
|
||||
})
|
||||
));
|
||||
@@ -47,7 +48,7 @@ test("import encrypted backup", () =>
|
||||
notebookTest().then(async ({ db, id }) => {
|
||||
const exp = await db.backup.export("node", true);
|
||||
StorageInterface.clear();
|
||||
await db.backup.import(exp);
|
||||
await db.backup.import(JSON.parse(exp), "password");
|
||||
expect(db.notebooks.notebook(id).data.id).toBe(id);
|
||||
})
|
||||
));
|
||||
@@ -59,9 +60,7 @@ test("import tempered backup", () =>
|
||||
StorageInterface.clear();
|
||||
const backup = JSON.parse(exp);
|
||||
backup.data.hello = "world";
|
||||
await expect(
|
||||
db.backup.import(JSON.stringify(backup))
|
||||
).rejects.toThrowError(/tempered/);
|
||||
await expect(db.backup.import(backup)).rejects.toThrowError(/tempered/);
|
||||
})
|
||||
));
|
||||
|
||||
@@ -71,7 +70,7 @@ describe.each([
|
||||
])("testing backup version: %s", (version, data) => {
|
||||
test(`import ${version} backup`, () => {
|
||||
return databaseTest().then(async (db) => {
|
||||
await db.backup.import(JSON.stringify(data));
|
||||
await db.backup.import(qclone(data));
|
||||
|
||||
expect(db.settings.raw.id).toBeDefined();
|
||||
expect(db.settings.raw.dateModified).toBeDefined();
|
||||
@@ -131,7 +130,7 @@ describe.each([
|
||||
|
||||
test(`verify indices of ${version} backup`, () => {
|
||||
return databaseTest().then(async (db) => {
|
||||
await db.backup.import(JSON.stringify(data));
|
||||
await db.backup.import(qclone(data));
|
||||
|
||||
verifyIndex(data, db, "notes", "notes");
|
||||
verifyIndex(data, db, "notebooks", "notebooks");
|
||||
|
||||
Reference in New Issue
Block a user