@@ -8,6 +8,7 @@ jest.mock('unique-slug')
8
8
const uniqueSlug = require ( 'unique-slug' )
9
9
const mdurl = require ( 'mdurl' )
10
10
const fse = require ( 'fs-extra' )
11
+ jest . mock ( 'sander' )
11
12
const sander = require ( 'sander' )
12
13
13
14
const systemUnderTest = require ( 'browser/main/lib/dataApi/attachmentManagement' )
@@ -393,3 +394,57 @@ it('should test that moveAttachments returns a correct modified content version'
393
394
const actualContent = systemUnderTest . moveAttachments ( oldPath , newPath , oldNoteKey , newNoteKey , testInput )
394
395
expect ( actualContent ) . toBe ( expectedOutput )
395
396
} )
397
+
398
+ it ( 'should test that cloneAttachments modifies the content of the new note correctly' , function ( ) {
399
+ const storageKey = 'storageKey'
400
+ const oldNote = { key : 'oldNoteKey' , content : 'oldNoteContent' }
401
+ const newNote = { key : 'newNoteKey' , content : 'oldNoteContent' }
402
+ const testInput =
403
+ 'Test input' +
404
+ ' \n' +
405
+ '[' + systemUnderTest . STORAGE_FOLDER_PLACEHOLDER + path . sep + oldNote . key + path . sep + 'pdf.pdf](pdf})'
406
+ newNote . content = testInput
407
+
408
+ const expectedOutput =
409
+ 'Test input' +
410
+ ' \n' +
411
+ '[' + systemUnderTest . STORAGE_FOLDER_PLACEHOLDER + path . sep + newNote . key + path . sep + 'pdf.pdf](pdf})'
412
+ systemUnderTest . cloneAttachments ( storageKey , oldNote , newNote )
413
+
414
+ expect ( newNote . content ) . toBe ( expectedOutput )
415
+ } )
416
+
417
+ it ( 'should test that cloneAttachments finds all attachments and copies them to the new location' , function ( ) {
418
+ const storageKey = 'storageKey'
419
+ const storagePath = 'storagePath'
420
+ const dummyStorage = { path : storagePath }
421
+ const oldNote = { key : 'oldNoteKey' , content : 'oldNoteContent' }
422
+ const newNote = { key : 'newNoteKey' , content : 'oldNoteContent' }
423
+ const testInput =
424
+ 'Test input' +
425
+ ' \n' +
426
+ '[' + systemUnderTest . STORAGE_FOLDER_PLACEHOLDER + path . sep + oldNote . key + path . sep + 'pdf.pdf](pdf})'
427
+ oldNote . content = testInput
428
+ newNote . content = testInput
429
+
430
+ const copyFileSyncResp = { to : jest . fn ( ) }
431
+ sander . copyFileSync = jest . fn ( )
432
+ sander . copyFileSync . mockReturnValue ( copyFileSyncResp )
433
+ findStorage . findStorage = jest . fn ( ( ) => dummyStorage )
434
+
435
+ const pathAttachmentOneFrom = path . join ( storagePath , systemUnderTest . DESTINATION_FOLDER , oldNote . key , 'image.jpg' )
436
+ const pathAttachmentOneTo = path . join ( storagePath , systemUnderTest . DESTINATION_FOLDER , newNote . key , 'image.jpg' )
437
+
438
+ const pathAttachmentTwoFrom = path . join ( storagePath , systemUnderTest . DESTINATION_FOLDER , oldNote . key , 'pdf.pdf' )
439
+ const pathAttachmentTwoTo = path . join ( storagePath , systemUnderTest . DESTINATION_FOLDER , newNote . key , 'pdf.pdf' )
440
+
441
+ systemUnderTest . cloneAttachments ( storageKey , oldNote , newNote )
442
+
443
+ expect ( findStorage . findStorage ) . toHaveBeenCalledWith ( storageKey )
444
+ expect ( sander . copyFileSync ) . toHaveBeenCalledTimes ( 2 )
445
+ expect ( copyFileSyncResp . to ) . toHaveBeenCalledTimes ( 2 )
446
+ expect ( sander . copyFileSync . mock . calls [ 0 ] [ 0 ] ) . toBe ( pathAttachmentOneFrom )
447
+ expect ( copyFileSyncResp . to . mock . calls [ 0 ] [ 0 ] ) . toBe ( pathAttachmentOneTo )
448
+ expect ( sander . copyFileSync . mock . calls [ 1 ] [ 0 ] ) . toBe ( pathAttachmentTwoFrom )
449
+ expect ( copyFileSyncResp . to . mock . calls [ 1 ] [ 0 ] ) . toBe ( pathAttachmentTwoTo )
450
+ } )
0 commit comments