mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Fix for the issues raised in the code review
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user