1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

Cloning of a note should also clone its attachments -> works if the notes are in different storages now

This commit is contained in:
ehhc
2018-05-20 15:49:15 +02:00
parent f76224bd17
commit cd6233a3d7
3 changed files with 26 additions and 23 deletions

View File

@@ -396,9 +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 () {
const storageKey = 'storageKey'
const oldNote = {key: 'oldNoteKey', content: 'oldNoteContent'}
const newNote = {key: 'newNoteKey', content: 'oldNoteContent'}
const oldNote = {key: 'oldNoteKey', content: 'oldNoteContent', storage: 'storageKey'}
const newNote = {key: 'newNoteKey', content: 'oldNoteContent', storage: 'storageKey'}
const testInput =
'Test input' +
'![' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + oldNote.key + path.sep + 'image.jpg](imageName}) \n' +
@@ -409,17 +408,18 @@ it('should test that cloneAttachments modifies the content of the new note corre
'Test input' +
'![' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + newNote.key + path.sep + 'image.jpg](imageName}) \n' +
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + newNote.key + path.sep + 'pdf.pdf](pdf})'
systemUnderTest.cloneAttachments(storageKey, oldNote, newNote)
systemUnderTest.cloneAttachments(oldNote, newNote)
expect(newNote.content).toBe(expectedOutput)
})
it('should test that cloneAttachments finds all attachments and copies them to the new location', function () {
const storageKey = 'storageKey'
const storagePath = 'storagePath'
const dummyStorage = {path: storagePath}
const oldNote = {key: 'oldNoteKey', content: 'oldNoteContent'}
const newNote = {key: 'newNoteKey', content: 'oldNoteContent'}
const storagePathOld = 'storagePathOld'
const storagePathNew = 'storagePathNew'
const dummyStorageOld = {path: storagePathOld}
const dummyStorageNew = {path: storagePathNew}
const oldNote = {key: 'oldNoteKey', content: 'oldNoteContent', storage: 'storageKeyOldNote'}
const newNote = {key: 'newNoteKey', content: 'oldNoteContent', storage: 'storageKeyNewNote'}
const testInput =
'Test input' +
'![' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + oldNote.key + path.sep + 'image.jpg](imageName}) \n' +
@@ -430,17 +430,20 @@ it('should test that cloneAttachments finds all attachments and copies them to t
const copyFileSyncResp = {to: jest.fn()}
sander.copyFileSync = jest.fn()
sander.copyFileSync.mockReturnValue(copyFileSyncResp)
findStorage.findStorage = jest.fn(() => dummyStorage)
findStorage.findStorage = jest.fn()
findStorage.findStorage.mockReturnValueOnce(dummyStorageOld)
findStorage.findStorage.mockReturnValue(dummyStorageNew)
const pathAttachmentOneFrom = path.join(storagePath, systemUnderTest.DESTINATION_FOLDER, oldNote.key, 'image.jpg')
const pathAttachmentOneTo = path.join(storagePath, systemUnderTest.DESTINATION_FOLDER, newNote.key, 'image.jpg')
const pathAttachmentOneFrom = path.join(storagePathOld, systemUnderTest.DESTINATION_FOLDER, oldNote.key, 'image.jpg')
const pathAttachmentOneTo = path.join(storagePathNew, systemUnderTest.DESTINATION_FOLDER, newNote.key, 'image.jpg')
const pathAttachmentTwoFrom = path.join(storagePath, systemUnderTest.DESTINATION_FOLDER, oldNote.key, 'pdf.pdf')
const pathAttachmentTwoTo = path.join(storagePath, systemUnderTest.DESTINATION_FOLDER, newNote.key, 'pdf.pdf')
const pathAttachmentTwoFrom = path.join(storagePathOld, systemUnderTest.DESTINATION_FOLDER, oldNote.key, 'pdf.pdf')
const pathAttachmentTwoTo = path.join(storagePathNew, systemUnderTest.DESTINATION_FOLDER, newNote.key, 'pdf.pdf')
systemUnderTest.cloneAttachments(storageKey, oldNote, newNote)
systemUnderTest.cloneAttachments(oldNote, newNote)
expect(findStorage.findStorage).toHaveBeenCalledWith(storageKey)
expect(findStorage.findStorage).toHaveBeenCalledWith(oldNote.storage)
expect(findStorage.findStorage).toHaveBeenCalledWith(newNote.storage)
expect(sander.copyFileSync).toHaveBeenCalledTimes(2)
expect(copyFileSyncResp.to).toHaveBeenCalledTimes(2)
expect(sander.copyFileSync.mock.calls[0][0]).toBe(pathAttachmentOneFrom)