コード例 #1
0
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()
})
コード例 #2
0
it('should test that cloneAttachments modifies the content of the new note correctly', function () {
  const oldNote = {key: 'oldNoteKey', content: 'oldNoteContent', storage: 'storageKey', type: 'MARKDOWN_NOTE'}
  const newNote = {key: 'newNoteKey', content: 'oldNoteContent', storage: 'storageKey', type: 'MARKDOWN_NOTE'}
  const testInput =
    'Test input' +
    '![' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.win32.sep + oldNote.key + path.win32.sep + 'image.jpg](imageName}) \n' +
    '[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + oldNote.key + path.posix.sep + 'pdf.pdf](pdf})'
  newNote.content = testInput
  findStorage.findStorage = jest.fn()
  findStorage.findStorage.mockReturnValue({path: 'dummyStoragePath'})

  const expectedOutput =
    '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(oldNote, newNote)

  expect(newNote.content).toBe(expectedOutput)
})
コード例 #3
0
it('should test that cloneAttachments finds all attachments and copies them to the new location', function () {
  const storagePathOld = 'storagePathOld'
  const storagePathNew = 'storagePathNew'
  const dummyStorageOld = {path: storagePathOld}
  const dummyStorageNew = {path: storagePathNew}
  const oldNote = {key: 'oldNoteKey', content: 'oldNoteContent', storage: 'storageKeyOldNote', type: 'MARKDOWN_NOTE'}
  const newNote = {key: 'newNoteKey', content: 'oldNoteContent', storage: 'storageKeyNewNote', type: 'MARKDOWN_NOTE'}
  const testInput =
    'Test input' +
    '![' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.win32.sep + oldNote.key + path.win32.sep + 'image.jpg](imageName}) \n' +
    '[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + oldNote.key + path.posix.sep + 'pdf.pdf](pdf})'
  oldNote.content = testInput
  newNote.content = testInput

  const copyFileSyncResp = {to: jest.fn()}
  sander.copyFileSync = jest.fn()
  sander.copyFileSync.mockReturnValue(copyFileSyncResp)
  findStorage.findStorage = jest.fn()
  findStorage.findStorage.mockReturnValueOnce(dummyStorageOld)
  findStorage.findStorage.mockReturnValue(dummyStorageNew)

  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(storagePathOld, systemUnderTest.DESTINATION_FOLDER, oldNote.key, 'pdf.pdf')
  const pathAttachmentTwoTo = path.join(storagePathNew, systemUnderTest.DESTINATION_FOLDER, newNote.key, 'pdf.pdf')

  systemUnderTest.cloneAttachments(oldNote, newNote)

  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)
  expect(copyFileSyncResp.to.mock.calls[0][0]).toBe(pathAttachmentOneTo)
  expect(sander.copyFileSync.mock.calls[1][0]).toBe(pathAttachmentTwoFrom)
  expect(copyFileSyncResp.to.mock.calls[1][0]).toBe(pathAttachmentTwoTo)
})
コード例 #4
0
ファイル: index.js プロジェクト: narukami894/Boostnote
 .then((note) => {
   attachmentManagement.cloneAttachments(firstNote, note)
   return note
 })