diff --git a/packages/core/__tests__/database.test.js b/packages/core/__tests__/database.test.js index 24e1a6f24..027f52e4e 100644 --- a/packages/core/__tests__/database.test.js +++ b/packages/core/__tests__/database.test.js @@ -273,28 +273,28 @@ test("delete topic from notebook", () => test("delete note", () => noteTest().then(async ({ db, timestamp }) => { - await db.deleteNotes([{ dateCreated: timestamp }]); + expect(await db.deleteNotes({ dateCreated: timestamp })).toBe(true); let note = db.getNote(timestamp); expect(note).toBeUndefined(); })); test("delete notebook", () => notebookTest().then(async ({ db, timestamp }) => { - await db.deleteNotebooks([{ dateCreated: timestamp }]); + expect(await db.deleteNotebooks({ dateCreated: timestamp })).toBe(true); let notebook = db.getNotebook(timestamp); expect(notebook).toBeUndefined(); })); test("trash should not be empty", () => notebookTest().then(async ({ db, timestamp }) => { - await db.deleteNotebooks([{ dateCreated: timestamp }]); + expect(await db.deleteNotebooks({ dateCreated: timestamp })).toBe(true); let trash = db.getTrash(); expect(trash.length).toBeGreaterThan(0); })); test("restore an item from trash", () => notebookTest().then(async ({ db, timestamp }) => { - await db.deleteNotebooks([{ dateCreated: timestamp }]); + expect(await db.deleteNotebooks({ dateCreated: timestamp })).toBe(true); let trash = db.getTrash(); expect(trash.length).toBeGreaterThan(0); await db.restoreItem(timestamp); @@ -304,7 +304,7 @@ test("restore an item from trash", () => test("clear trash should clear the trash", () => notebookTest().then(async ({ db, timestamp }) => { - await db.deleteNotebooks([{ dateCreated: timestamp }]); + expect(await db.deleteNotebooks({ dateCreated: timestamp })).toBe(true); let trash = db.getTrash(); expect(trash.length).toBeGreaterThan(0); await db.clearTrash(); @@ -340,15 +340,9 @@ test("empty notebook should not be added", () => expect(res).toBeUndefined(); })); -test("deletion of unknown item should return false", () => - databaseTest().then(async db => { - let res = await db.deleteNotes(undefined); - expect(res).toBe(false); - })); - test("deletion of invalid items should cause continue and return true", () => databaseTest().then(async db => { - let res = await db.deleteNotes([null, null, "something"]); + let res = await db.deleteNotes(null, null, "something"); expect(res).toBe(true); })); diff --git a/packages/core/api/database.js b/packages/core/api/database.js index d6b998f11..a9e54bad6 100644 --- a/packages/core/api/database.js +++ b/packages/core/api/database.js @@ -120,15 +120,23 @@ class Database { } } - async addNote(note) { - if (!note) return; - let timestamp = note.dateCreated || Date.now(); - note = { ...this.notes[timestamp], ...note }; + async addNote(_note) { + if (!_note || !_note.content) return; + let timestamp = _note.dateCreated || Date.now(); + let note = { ...this.notes[timestamp], ..._note }; if ( - !note.title && + !this.notes[timestamp] && + (note.content.text.length <= 0 || !note.content.delta) && + (!note.title || note.title.length <= 0) + ) { + return; + } + + if ( + (!note.title || note.title.length <= 0) && !note.locked && - (!note.content || !note.content.text || !note.content.delta) && + note.content.text.length <= 0 && this.notes[timestamp] ) { //delete the note @@ -433,8 +441,10 @@ class Database { export default Database; async function deleteItems(items, key) { - if (!items || items.length <= 0 || !this[key] || this[key].length <= 0) + if (!items || items.length <= 0 || !this[key] || this[key].length <= 0) { + console.log(items, items.length); return false; + } for (let item of items) { if (!item) continue; if (this[key].hasOwnProperty(item.dateCreated)) { diff --git a/packages/core/package.json b/packages/core/package.json index 422a50abf..e6e8acb33 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -17,6 +17,7 @@ }, "dependencies": { "fuzzysearch": "^1.0.3", - "transfun": "^1.0.2" + "transfun": "^1.0.2", + "node-fetch": "^2.6.0" } }