@@ -578,6 +578,72 @@ it('should test that deleteAttachmentsNotPresentInNote does nothing if noteKey,
578
578
expect ( fs . unlink ) . not . toHaveBeenCalled ( )
579
579
} )
580
580
581
+ it ( 'should test that getAttachmentsPathAndStatus return null if noteKey, storageKey or noteContent was undefined' , function ( ) {
582
+ const noteKey = undefined
583
+ const storageKey = undefined
584
+ const markdownContent = ''
585
+
586
+ const result = systemUnderTest . getAttachmentsPathAndStatus ( markdownContent , storageKey , noteKey )
587
+ expect ( result ) . toBeNull ( )
588
+ } )
589
+
590
+ it ( 'should test that getAttachmentsPathAndStatus return null if noteKey, storageKey or noteContent was null' , function ( ) {
591
+ const noteKey = null
592
+ const storageKey = null
593
+ const markdownContent = ''
594
+
595
+ const result = systemUnderTest . getAttachmentsPathAndStatus ( markdownContent , storageKey , noteKey )
596
+ expect ( result ) . toBeNull ( )
597
+ } )
598
+
599
+ it ( 'should test that getAttachmentsPathAndStatus return the correct path and status for attachments' , async function ( ) {
600
+ const dummyStorage = { path : 'dummyStoragePath' }
601
+ const noteKey = 'noteKey'
602
+ const storageKey = 'storageKey'
603
+ const markdownContent =
604
+ 'Test input' +
605
+ ' \n'
606
+ const dummyFilesInFolder = [ 'file1.txt' , 'file2.pdf' , 'file3.jpg' ]
607
+
608
+ findStorage . findStorage = jest . fn ( ( ) => dummyStorage )
609
+ fs . existsSync = jest . fn ( ( ) => true )
610
+ fs . readdir = jest . fn ( ( paht , callback ) => callback ( undefined , dummyFilesInFolder ) )
611
+ fs . unlink = jest . fn ( )
612
+
613
+ const targetStorage = findStorage . findStorage ( storageKey )
614
+
615
+ const attachments = await systemUnderTest . getAttachmentsPathAndStatus ( markdownContent , storageKey , noteKey )
616
+ expect ( attachments . length ) . toBe ( 3 )
617
+ expect ( attachments [ 0 ] . isInUse ) . toBe ( false )
618
+ expect ( attachments [ 1 ] . isInUse ) . toBe ( true )
619
+ expect ( attachments [ 2 ] . isInUse ) . toBe ( false )
620
+
621
+ expect ( attachments [ 0 ] . path ) . toBe (
622
+ path . join (
623
+ targetStorage . path ,
624
+ systemUnderTest . DESTINATION_FOLDER ,
625
+ noteKey ,
626
+ dummyFilesInFolder [ 0 ]
627
+ )
628
+ )
629
+ expect ( attachments [ 1 ] . path ) . toBe (
630
+ path . join (
631
+ targetStorage . path ,
632
+ systemUnderTest . DESTINATION_FOLDER ,
633
+ noteKey ,
634
+ dummyFilesInFolder [ 1 ]
635
+ )
636
+ )
637
+ expect ( attachments [ 2 ] . path ) . toBe (
638
+ path . join (
639
+ targetStorage . path ,
640
+ systemUnderTest . DESTINATION_FOLDER ,
641
+ noteKey ,
642
+ dummyFilesInFolder [ 2 ]
643
+ )
644
+ )
645
+ } )
646
+
581
647
it ( 'should test that moveAttachments moves attachments only if the source folder existed' , function ( ) {
582
648
fse . existsSync = jest . fn ( ( ) => false )
583
649
fse . moveSync = jest . fn ( )
0 commit comments