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

Move note with attachment to different storage Fix for #1788

This commit is contained in:
ehhc
2018-05-15 20:17:32 +02:00
parent 266323b90b
commit f10fa632ca
7 changed files with 115 additions and 64 deletions

View File

@@ -7,6 +7,7 @@ const findStorage = require('browser/lib/findStorage')
jest.mock('unique-slug')
const uniqueSlug = require('unique-slug')
const mdurl = require('mdurl')
const fse = require('fs-extra')
const systemUnderTest = require('browser/main/lib/dataApi/attachmentManagement')
@@ -312,3 +313,59 @@ it('should test that deleteAttachmentsNotPresentInNote does not delete reference
}
expect(fsUnlinkCallArguments.includes(path.join(attachmentFolderPath, dummyFilesInFolder[0]))).toBe(false)
})
it('should test that moveAttachments moves attachments only if the source folder existed', function () {
fse.existsSync = jest.fn(() => false)
fse.moveSync = jest.fn()
const oldPath = 'oldPath'
const newPath = 'newPath'
const oldNoteKey = 'oldNoteKey'
const newNoteKey = 'newNoteKey'
const content = ''
const expectedSource = path.join(oldPath, systemUnderTest.DESTINATION_FOLDER, oldNoteKey)
systemUnderTest.moveAttachments(oldPath, newPath, oldNoteKey, newNoteKey, content)
expect(fse.existsSync).toHaveBeenCalledWith(expectedSource)
expect(fse.moveSync).not.toHaveBeenCalled()
})
it('should test that moveAttachments moves attachments to the right destination', function () {
fse.existsSync = jest.fn(() => true)
fse.moveSync = jest.fn()
const oldPath = 'oldPath'
const newPath = 'newPath'
const oldNoteKey = 'oldNoteKey'
const newNoteKey = 'newNoteKey'
const content = ''
const expectedSource = path.join(oldPath, systemUnderTest.DESTINATION_FOLDER, oldNoteKey)
const expectedDestination = path.join(newPath, systemUnderTest.DESTINATION_FOLDER, newNoteKey)
systemUnderTest.moveAttachments(oldPath, newPath, oldNoteKey, newNoteKey, content)
expect(fse.existsSync).toHaveBeenCalledWith(expectedSource)
expect(fse.moveSync).toHaveBeenCalledWith(expectedSource, expectedDestination)
})
it('should test that moveAttachments returns a correct modified content version', function () {
fse.existsSync = jest.fn()
fse.moveSync = jest.fn()
const oldPath = 'oldPath'
const newPath = 'newPath'
const oldNoteKey = 'oldNoteKey'
const newNoteKey = 'newNoteKey'
const testInput =
'Test input' +
'![' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + oldNoteKey + path.sep + 'image.jpg](imageName}) \n' +
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + oldNoteKey + path.sep + 'pdf.pdf](pdf})'
const expectedOutput =
'Test input' +
'![' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + newNoteKey + path.sep + 'image.jpg](imageName}) \n' +
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + newNoteKey + path.sep + 'pdf.pdf](pdf})'
const actualContent = systemUnderTest.moveAttachments(oldPath, newPath, oldNoteKey, newNoteKey, testInput)
expect(actualContent).toBe(expectedOutput)
})