From 63a2f7b7a5400f5341f75b520dcbeb7943a18ae7 Mon Sep 17 00:00:00 2001 From: mic704b Date: Mon, 16 Mar 2020 08:53:49 +1100 Subject: [PATCH] All: Fix calls to non-existent function (#2675) * Fix calls to non-existent function * Add tests. * Fix travis lint problems. --- CliClient/tests/integration_ShowAllNotes.js | 16 ++++++++-------- CliClient/tests/models_BaseItem.js | 8 ++++---- CliClient/tests/models_Note.js | 21 +++++++++++++++++++++ ReactNativeClient/lib/models/Note.js | 4 ++-- 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/CliClient/tests/integration_ShowAllNotes.js b/CliClient/tests/integration_ShowAllNotes.js index 6b2d7c7ab..37912b04f 100644 --- a/CliClient/tests/integration_ShowAllNotes.js +++ b/CliClient/tests/integration_ShowAllNotes.js @@ -93,10 +93,10 @@ describe('integration_ShowAllNotes', function() { it('should support note duplication', asyncTest(async () => { // setup - let folder1 = await Folder.save({ title: 'folder1' }); - let folder2 = await Folder.save({ title: 'folder2' }); - let note1 = await Note.save({ title: 'note1', parent_id: folder1.id }); - let note2 = await Note.save({ title: 'note2', parent_id: folder2.id }); + const folder1 = await Folder.save({ title: 'folder1' }); + const folder2 = await Folder.save({ title: 'folder2' }); + const note1 = await Note.save({ title: 'note1', parent_id: folder1.id }); + const note2 = await Note.save({ title: 'note2', parent_id: folder2.id }); testApp.dispatch({ type: 'FOLDER_SELECT', id: folder1.id }); // active folder await time.msleep(100); testApp.dispatch({ type: 'NOTE_SELECT', id: note1.id }); @@ -130,10 +130,10 @@ describe('integration_ShowAllNotes', function() { it('should support changing the note parent', asyncTest(async () => { // setup - let folder1 = await Folder.save({ title: 'folder1' }); - let folder2 = await Folder.save({ title: 'folder2' }); - let note1 = await Note.save({ title: 'note1', parent_id: folder1.id }); - let note2 = await Note.save({ title: 'note1', parent_id: folder2.id }); + const folder1 = await Folder.save({ title: 'folder1' }); + const folder2 = await Folder.save({ title: 'folder2' }); + const note1 = await Note.save({ title: 'note1', parent_id: folder1.id }); + const note2 = await Note.save({ title: 'note1', parent_id: folder2.id }); testApp.dispatch({ type: 'FOLDER_SELECT', id: folder1.id }); // active folder await time.msleep(100); testApp.dispatch({ type: 'NOTE_SELECT', id: note1.id }); diff --git a/CliClient/tests/models_BaseItem.js b/CliClient/tests/models_BaseItem.js index 205f1be97..8226c464a 100644 --- a/CliClient/tests/models_BaseItem.js +++ b/CliClient/tests/models_BaseItem.js @@ -58,11 +58,11 @@ describe('models_BaseItem', function() { })); it('should correctly unserialize note timestamps', asyncTest(async () => { - let folder = await Folder.save({ title: 'folder' }); - let note = await Note.save({ title: 'note', parent_id: folder.id }); + const folder = await Folder.save({ title: 'folder' }); + const note = await Note.save({ title: 'note', parent_id: folder.id }); - let serialized = await Note.serialize(note); - let unserialized = await Note.unserialize(serialized); + const serialized = await Note.serialize(note); + const unserialized = await Note.unserialize(serialized); expect(unserialized.created_time).toEqual(note.created_time); expect(unserialized.updated_time).toEqual(note.updated_time); diff --git a/CliClient/tests/models_Note.js b/CliClient/tests/models_Note.js index 55435e24a..d779617dd 100644 --- a/CliClient/tests/models_Note.js +++ b/CliClient/tests/models_Note.js @@ -195,4 +195,25 @@ describe('models_Note', function() { expect(sortedIds(afterDelete)).toEqual(sortedIds(beforeDelete)); })); + + it('should not move to conflict folder', asyncTest(async () => { + const folder1 = await Folder.save({ title: 'Folder' }); + const folder2 = await Folder.save({ title: Folder.conflictFolderTitle(), id: Folder.conflictFolderId() }); + const note1 = await Note.save({ title: 'note', parent_id: folder1.id }); + + const hasThrown = await checkThrowAsync(async () => await Folder.moveToFolder(note1.id, folder2.id)); + expect(hasThrown).toBe(true); + + const note = await Note.load(note1.id); + expect(note.parent_id).toEqual(folder1.id); + })); + + it('should not copy to conflict folder', asyncTest(async () => { + const folder1 = await Folder.save({ title: 'Folder' }); + const folder2 = await Folder.save({ title: Folder.conflictFolderTitle(), id: Folder.conflictFolderId() }); + const note1 = await Note.save({ title: 'note', parent_id: folder1.id }); + + const hasThrown = await checkThrowAsync(async () => await Folder.copyToFolder(note1.id, folder2.id)); + expect(hasThrown).toBe(true); + })); }); diff --git a/ReactNativeClient/lib/models/Note.js b/ReactNativeClient/lib/models/Note.js index f56114cc2..20a33190b 100644 --- a/ReactNativeClient/lib/models/Note.js +++ b/ReactNativeClient/lib/models/Note.js @@ -448,7 +448,7 @@ class Note extends BaseItem { } static async copyToFolder(noteId, folderId) { - if (folderId == this.getClass('Folder').conflictFolderId()) throw new Error(_('Cannot copy note to "%s" notebook', this.getClass('Folder').conflictFolderIdTitle())); + if (folderId == this.getClass('Folder').conflictFolderId()) throw new Error(_('Cannot copy note to "%s" notebook', this.getClass('Folder').conflictFolderTitle())); return Note.duplicate(noteId, { changes: { @@ -459,7 +459,7 @@ class Note extends BaseItem { } static async moveToFolder(noteId, folderId) { - if (folderId == this.getClass('Folder').conflictFolderId()) throw new Error(_('Cannot move note to "%s" notebook', this.getClass('Folder').conflictFolderIdTitle())); + if (folderId == this.getClass('Folder').conflictFolderId()) throw new Error(_('Cannot move note to "%s" notebook', this.getClass('Folder').conflictFolderTitle())); // When moving a note to a different folder, the user timestamp is not updated. // However updated_time is updated so that the note can be synced later on.