Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

ci: fix tests

thecodrr336b5c7d6920
diff --git a/packages/core/__tests__/notes.test.js b/packages/core/__tests__/notes.test.js
index d20097488..5fd2e50c8 100644
--- a/packages/core/__tests__/notes.test.js
+++ b/packages/core/__tests__/notes.test.js
@@ -224,17 +224,25 @@ test("favorite note", () =>
}));
test("lock and unlock note", () =>
- noteTest().then(async ({ db, id }) => {
+ noteTest({
+ content: {
+ delta: { ops: [{ insert: "I am a text", type: "text" }] },
+ text: "I am a text"
+ }
+ }).then(async ({ db, id }) => {
let note = db.notes.note(id);
await note.lock("password123");
expect(note.data.locked).toBe(true);
expect(note.data.content.iv).toBeDefined();
+ expect((await note.delta()).iv).toBeDefined();
note = await note.unlock("password123");
expect(note.id).toBe(id);
expect(note.content.text).toBe(TEST_NOTE.content.text);
+ expect(note.content.delta.ops).toBeDefined();
note = db.notes.note(id);
await note.unlock("password123", true);
note = db.notes.note(id);
+ expect((await note.delta()).ops).toBeDefined();
expect(note.data.locked).toBe(false);
}));
diff --git a/packages/core/models/note.js b/packages/core/models/note.js
index a40066c25..f9c078b4b 100644
--- a/packages/core/models/note.js
+++ b/packages/core/models/note.js
@@ -44,8 +44,7 @@ export default class Note {
}
delta() {
- if (this.note.locked) return [];
- return this.notes.deltaStorage.read(this.note.content.delta);
+ return this.notes.deltaStorage.read(this.note.id + "_delta");
}
color(color) {
@@ -81,15 +80,18 @@ export default class Note {
}
async lock(password) {
+ let delta = await this.delta();
+ if (delta) {
+ delta = await this.notes.collection.indexer.encrypt(
+ password,
+ JSON.stringify(delta)
+ );
+ await this.notes.deltaStorage.write(this.note.content.delta, delta);
+ }
this.note.content = await this.notes.collection.indexer.encrypt(
password,
JSON.stringify(this.note.content)
);
- let delta = await this.notes.collection.indexer.encrypt(
- password,
- JSON.stringify(await this.delta())
- );
- await this.notes.deltaStorage.write(this.note.content.delta, delta);
this.note.locked = true;
return await this.notes.collection.addItem(this.note);
}
@@ -109,7 +111,7 @@ export default class Note {
}
return {
...this.note,
- content: { ...decrypted, delta: delta }
+ content: { ...decrypted, delta }
};
}
}