diff --git a/browser/main/lib/dataApi/attachmentManagement.js b/browser/main/lib/dataApi/attachmentManagement.js index c83fc79d..09673541 100644 --- a/browser/main/lib/dataApi/attachmentManagement.js +++ b/browser/main/lib/dataApi/attachmentManagement.js @@ -232,7 +232,7 @@ function deleteAttachmentFolder (storageKey, noteKey) { * @param noteKey NoteKey of the current note. Is used to determine the belonging attachment folder. */ function deleteAttachmentsNotPresentInNote (markdownContent, storageKey, noteKey) { - if (storageKey && noteKey && markdownContent !== null && typeof markdownContent !== 'undefined') { + if (storageKey != null && noteKey != null && markdownContent != null) { const targetStorage = findStorage.findStorage(storageKey) const attachmentFolder = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey) const attachmentsInNote = getAttachmentsInContent(markdownContent) diff --git a/tests/dataApi/attachmentManagement.test.js b/tests/dataApi/attachmentManagement.test.js index feb9207c..1418bcfa 100644 --- a/tests/dataApi/attachmentManagement.test.js +++ b/tests/dataApi/attachmentManagement.test.js @@ -383,3 +383,35 @@ it('should test that moveAttachments returns a correct modified content version' const actualContent = systemUnderTest.moveAttachments(oldPath, newPath, oldNoteKey, newNoteKey, testInput) expect(actualContent).toBe(expectedOutput) }) + +it('should test that deleteAttachmentsNotPresentInNote does nothing if noteKey, storageKey or noteContent was null', function () { + const noteKey = null + const storageKey = null + const markdownContent = '' + + findStorage.findStorage = jest.fn() + fs.existsSync = jest.fn() + fs.readdir = jest.fn() + fs.unlink = jest.fn() + + systemUnderTest.deleteAttachmentsNotPresentInNote(markdownContent, storageKey, noteKey) + expect(fs.existsSync).not.toHaveBeenCalled() + expect(fs.readdir).not.toHaveBeenCalled() + expect(fs.unlink).not.toHaveBeenCalled() +}) + +it('should test that deleteAttachmentsNotPresentInNote does nothing if noteKey, storageKey or noteContent was undefined', function () { + const noteKey = undefined + const storageKey = undefined + const markdownContent = '' + + findStorage.findStorage = jest.fn() + fs.existsSync = jest.fn() + fs.readdir = jest.fn() + fs.unlink = jest.fn() + + systemUnderTest.deleteAttachmentsNotPresentInNote(markdownContent, storageKey, noteKey) + expect(fs.existsSync).not.toHaveBeenCalled() + expect(fs.readdir).not.toHaveBeenCalled() + expect(fs.unlink).not.toHaveBeenCalled() +})