1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 01:36:22 +00:00

Attachment management should only become active on cloning notes if the note was of type MARKDOWN_NOTE -> No Stacktraces otherwise!

This commit is contained in:
ehhc
2018-05-23 19:24:03 +02:00
parent cd6233a3d7
commit bfcf349ffe
2 changed files with 35 additions and 15 deletions

View File

@@ -288,6 +288,7 @@ function deleteAttachmentsNotPresentInNote (markdownContent, storageKey, noteKey
* @param newNote Clone of the note * @param newNote Clone of the note
*/ */
function cloneAttachments (oldNote, newNote) { function cloneAttachments (oldNote, newNote) {
if (newNote.type === 'MARKDOWN_NOTE') {
const oldStorage = findStorage.findStorage(oldNote.storage) const oldStorage = findStorage.findStorage(oldNote.storage)
const newStorage = findStorage.findStorage(newNote.storage) const newStorage = findStorage.findStorage(newNote.storage)
const attachmentsPaths = getAbsolutePathsOfAttachmentsInContent(oldNote.content, oldStorage.path) || [] const attachmentsPaths = getAbsolutePathsOfAttachmentsInContent(oldNote.content, oldStorage.path) || []
@@ -302,6 +303,9 @@ function cloneAttachments (oldNote, newNote) {
sander.copyFileSync(attachment).to(destination) sander.copyFileSync(attachment).to(destination)
} }
newNote.content = replaceNoteKeyWithNewNoteKey(newNote.content, oldNote.key, newNote.key) newNote.content = replaceNoteKeyWithNewNoteKey(newNote.content, oldNote.key, newNote.key)
} else {
console.debug('Cloning of the attachment was skipped since it only works for MARKDOWN_NOTEs')
}
} }
module.exports = { module.exports = {

View File

@@ -396,8 +396,8 @@ it('should test that moveAttachments returns a correct modified content version'
}) })
it('should test that cloneAttachments modifies the content of the new note correctly', function () { it('should test that cloneAttachments modifies the content of the new note correctly', function () {
const oldNote = {key: 'oldNoteKey', content: 'oldNoteContent', storage: 'storageKey'} const oldNote = {key: 'oldNoteKey', content: 'oldNoteContent', storage: 'storageKey', type: 'MARKDOWN_NOTE'}
const newNote = {key: 'newNoteKey', content: 'oldNoteContent', storage: 'storageKey'} const newNote = {key: 'newNoteKey', content: 'oldNoteContent', storage: 'storageKey', type: 'MARKDOWN_NOTE'}
const testInput = const testInput =
'Test input' + 'Test input' +
'![' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + oldNote.key + path.sep + 'image.jpg](imageName}) \n' + '![' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + oldNote.key + path.sep + 'image.jpg](imageName}) \n' +
@@ -418,8 +418,8 @@ it('should test that cloneAttachments finds all attachments and copies them to t
const storagePathNew = 'storagePathNew' const storagePathNew = 'storagePathNew'
const dummyStorageOld = {path: storagePathOld} const dummyStorageOld = {path: storagePathOld}
const dummyStorageNew = {path: storagePathNew} const dummyStorageNew = {path: storagePathNew}
const oldNote = {key: 'oldNoteKey', content: 'oldNoteContent', storage: 'storageKeyOldNote'} const oldNote = {key: 'oldNoteKey', content: 'oldNoteContent', storage: 'storageKeyOldNote', type: 'MARKDOWN_NOTE'}
const newNote = {key: 'newNoteKey', content: 'oldNoteContent', storage: 'storageKeyNewNote'} const newNote = {key: 'newNoteKey', content: 'oldNoteContent', storage: 'storageKeyNewNote', type: 'MARKDOWN_NOTE'}
const testInput = const testInput =
'Test input' + 'Test input' +
'![' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + oldNote.key + path.sep + 'image.jpg](imageName}) \n' + '![' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + oldNote.key + path.sep + 'image.jpg](imageName}) \n' +
@@ -451,3 +451,19 @@ it('should test that cloneAttachments finds all attachments and copies them to t
expect(sander.copyFileSync.mock.calls[1][0]).toBe(pathAttachmentTwoFrom) expect(sander.copyFileSync.mock.calls[1][0]).toBe(pathAttachmentTwoFrom)
expect(copyFileSyncResp.to.mock.calls[1][0]).toBe(pathAttachmentTwoTo) expect(copyFileSyncResp.to.mock.calls[1][0]).toBe(pathAttachmentTwoTo)
}) })
it('should test that cloneAttachments finds all attachments and copies them to the new location', function () {
const oldNote = {key: 'oldNoteKey', content: 'oldNoteContent', storage: 'storageKeyOldNote', type: 'SOMETHING_ELSE'}
const newNote = {key: 'newNoteKey', content: 'oldNoteContent', storage: 'storageKeyNewNote', type: 'SOMETHING_ELSE'}
const testInput = 'Test input'
oldNote.content = testInput
newNote.content = testInput
sander.copyFileSync = jest.fn()
findStorage.findStorage = jest.fn()
systemUnderTest.cloneAttachments(oldNote, newNote)
expect(findStorage.findStorage).not.toHaveBeenCalled()
expect(sander.copyFileSync).not.toHaveBeenCalled()
})