@@ -421,7 +421,7 @@ describe('/libraries', () => {
421
421
const { status } = await request ( app )
422
422
. post ( `/libraries/${ library . id } /scan` )
423
423
. set ( 'Authorization' , `Bearer ${ admin . accessToken } ` )
424
- . send ( { refreshModifiedFiles : true } ) ;
424
+ . send ( ) ;
425
425
expect ( status ) . toBe ( 204 ) ;
426
426
427
427
await utils . waitForQueueFinish ( admin . accessToken , 'library' ) ;
@@ -453,7 +453,7 @@ describe('/libraries', () => {
453
453
const { status } = await request ( app )
454
454
. post ( `/libraries/${ library . id } /scan` )
455
455
. set ( 'Authorization' , `Bearer ${ admin . accessToken } ` )
456
- . send ( { refreshModifiedFiles : true } ) ;
456
+ . send ( ) ;
457
457
expect ( status ) . toBe ( 204 ) ;
458
458
459
459
await utils . waitForQueueFinish ( admin . accessToken , 'library' ) ;
@@ -577,7 +577,7 @@ describe('/libraries', () => {
577
577
] ) ;
578
578
} ) ;
579
579
580
- it ( 'should not trash an online asset' , async ( ) => {
580
+ it ( 'should not set an asset offline if its file exists, is in an import path, and not covered by an exclusion pattern ' , async ( ) => {
581
581
const library = await utils . createLibrary ( admin . accessToken , {
582
582
ownerId : admin . userId ,
583
583
importPaths : [ `${ testAssetDirInternal } /temp` ] ,
@@ -601,6 +601,195 @@ describe('/libraries', () => {
601
601
602
602
expect ( assets ) . toEqual ( assetsBefore ) ;
603
603
} ) ;
604
+
605
+ it ( 'should set an offline asset to online if its file exists, is in an import path, and not covered by an exclusion pattern' , async ( ) => {
606
+ utils . createImageFile ( `${ testAssetDir } /temp/offline/offline.png` ) ;
607
+
608
+ const library = await utils . createLibrary ( admin . accessToken , {
609
+ ownerId : admin . userId ,
610
+ importPaths : [ `${ testAssetDirInternal } /temp/offline` ] ,
611
+ } ) ;
612
+
613
+ await scan ( admin . accessToken , library . id ) ;
614
+ await utils . waitForQueueFinish ( admin . accessToken , 'library' ) ;
615
+
616
+ const { assets } = await utils . searchAssets ( admin . accessToken , { libraryId : library . id } ) ;
617
+
618
+ utils . renameImageFile ( `${ testAssetDir } /temp/offline/offline.png` , `${ testAssetDir } /temp/offline.png` ) ;
619
+
620
+ {
621
+ const { status } = await request ( app )
622
+ . post ( `/libraries/${ library . id } /scan` )
623
+ . set ( 'Authorization' , `Bearer ${ admin . accessToken } ` )
624
+ . send ( ) ;
625
+ expect ( status ) . toBe ( 204 ) ;
626
+ }
627
+
628
+ await utils . waitForQueueFinish ( admin . accessToken , 'library' ) ;
629
+
630
+ const offlineAsset = await utils . getAssetInfo ( admin . accessToken , assets . items [ 0 ] . id ) ;
631
+ expect ( offlineAsset . isTrashed ) . toBe ( true ) ;
632
+ expect ( offlineAsset . originalPath ) . toBe ( `${ testAssetDirInternal } /temp/offline/offline.png` ) ;
633
+ expect ( offlineAsset . isOffline ) . toBe ( true ) ;
634
+
635
+ {
636
+ const { assets } = await utils . searchAssets ( admin . accessToken , { libraryId : library . id , withDeleted : true } ) ;
637
+ expect ( assets . count ) . toBe ( 1 ) ;
638
+ }
639
+
640
+ utils . renameImageFile ( `${ testAssetDir } /temp/offline.png` , `${ testAssetDir } /temp/offline/offline.png` ) ;
641
+
642
+ {
643
+ const { status } = await request ( app )
644
+ . post ( `/libraries/${ library . id } /scan` )
645
+ . set ( 'Authorization' , `Bearer ${ admin . accessToken } ` )
646
+ . send ( ) ;
647
+ expect ( status ) . toBe ( 204 ) ;
648
+ }
649
+
650
+ await utils . waitForQueueFinish ( admin . accessToken , 'library' ) ;
651
+
652
+ const backOnlineAsset = await utils . getAssetInfo ( admin . accessToken , assets . items [ 0 ] . id ) ;
653
+
654
+ expect ( backOnlineAsset . isTrashed ) . toBe ( false ) ;
655
+ expect ( backOnlineAsset . originalPath ) . toBe ( `${ testAssetDirInternal } /temp/offline/offline.png` ) ;
656
+ expect ( backOnlineAsset . isOffline ) . toBe ( false ) ;
657
+
658
+ {
659
+ const { assets } = await utils . searchAssets ( admin . accessToken , { libraryId : library . id } ) ;
660
+ expect ( assets . count ) . toBe ( 1 ) ;
661
+ }
662
+ } ) ;
663
+
664
+ it ( 'should not set an offline asset to online if its file exists, is not covered by an exclusion pattern, but is outside of all import paths' , async ( ) => {
665
+ utils . createImageFile ( `${ testAssetDir } /temp/offline/offline.png` ) ;
666
+
667
+ const library = await utils . createLibrary ( admin . accessToken , {
668
+ ownerId : admin . userId ,
669
+ importPaths : [ `${ testAssetDirInternal } /temp/offline` ] ,
670
+ } ) ;
671
+
672
+ await scan ( admin . accessToken , library . id ) ;
673
+ await utils . waitForQueueFinish ( admin . accessToken , 'library' ) ;
674
+
675
+ const { assets } = await utils . searchAssets ( admin . accessToken , { libraryId : library . id } ) ;
676
+
677
+ utils . renameImageFile ( `${ testAssetDir } /temp/offline/offline.png` , `${ testAssetDir } /temp/offline.png` ) ;
678
+
679
+ {
680
+ const { status } = await request ( app )
681
+ . post ( `/libraries/${ library . id } /scan` )
682
+ . set ( 'Authorization' , `Bearer ${ admin . accessToken } ` )
683
+ . send ( ) ;
684
+ expect ( status ) . toBe ( 204 ) ;
685
+ }
686
+
687
+ await utils . waitForQueueFinish ( admin . accessToken , 'library' ) ;
688
+
689
+ {
690
+ const { assets } = await utils . searchAssets ( admin . accessToken , { libraryId : library . id , withDeleted : true } ) ;
691
+ expect ( assets . count ) . toBe ( 1 ) ;
692
+ }
693
+
694
+ const offlineAsset = await utils . getAssetInfo ( admin . accessToken , assets . items [ 0 ] . id ) ;
695
+
696
+ expect ( offlineAsset . isTrashed ) . toBe ( true ) ;
697
+ expect ( offlineAsset . originalPath ) . toBe ( `${ testAssetDirInternal } /temp/offline/offline.png` ) ;
698
+ expect ( offlineAsset . isOffline ) . toBe ( true ) ;
699
+
700
+ utils . renameImageFile ( `${ testAssetDir } /temp/offline.png` , `${ testAssetDir } /temp/offline/offline.png` ) ;
701
+
702
+ utils . createDirectory ( `${ testAssetDir } /temp/another-path/` ) ;
703
+
704
+ await utils . updateLibrary ( admin . accessToken , library . id , {
705
+ importPaths : [ `${ testAssetDirInternal } /temp/another-path` ] ,
706
+ } ) ;
707
+
708
+ {
709
+ const { status } = await request ( app )
710
+ . post ( `/libraries/${ library . id } /scan` )
711
+ . set ( 'Authorization' , `Bearer ${ admin . accessToken } ` )
712
+ . send ( ) ;
713
+ expect ( status ) . toBe ( 204 ) ;
714
+ }
715
+
716
+ await utils . waitForQueueFinish ( admin . accessToken , 'library' ) ;
717
+
718
+ const stillOfflineAsset = await utils . getAssetInfo ( admin . accessToken , assets . items [ 0 ] . id ) ;
719
+
720
+ expect ( stillOfflineAsset . isTrashed ) . toBe ( true ) ;
721
+ expect ( stillOfflineAsset . originalPath ) . toBe ( `${ testAssetDirInternal } /temp/offline/offline.png` ) ;
722
+ expect ( stillOfflineAsset . isOffline ) . toBe ( true ) ;
723
+
724
+ {
725
+ const { assets } = await utils . searchAssets ( admin . accessToken , { libraryId : library . id , withDeleted : true } ) ;
726
+ expect ( assets . count ) . toBe ( 1 ) ;
727
+ }
728
+
729
+ utils . removeDirectory ( `${ testAssetDir } /temp/another-path/` ) ;
730
+ } ) ;
731
+
732
+ it ( 'should not set an offline asset to online if its file exists, is in an import path, but is covered by an exclusion pattern' , async ( ) => {
733
+ utils . createImageFile ( `${ testAssetDir } /temp/offline/offline.png` ) ;
734
+
735
+ const library = await utils . createLibrary ( admin . accessToken , {
736
+ ownerId : admin . userId ,
737
+ importPaths : [ `${ testAssetDirInternal } /temp/offline` ] ,
738
+ } ) ;
739
+
740
+ await scan ( admin . accessToken , library . id ) ;
741
+ await utils . waitForQueueFinish ( admin . accessToken , 'library' ) ;
742
+
743
+ const { assets } = await utils . searchAssets ( admin . accessToken , { libraryId : library . id } ) ;
744
+
745
+ utils . renameImageFile ( `${ testAssetDir } /temp/offline/offline.png` , `${ testAssetDir } /temp/offline.png` ) ;
746
+
747
+ {
748
+ const { status } = await request ( app )
749
+ . post ( `/libraries/${ library . id } /scan` )
750
+ . set ( 'Authorization' , `Bearer ${ admin . accessToken } ` )
751
+ . send ( ) ;
752
+ expect ( status ) . toBe ( 204 ) ;
753
+ }
754
+
755
+ await utils . waitForQueueFinish ( admin . accessToken , 'library' ) ;
756
+
757
+ {
758
+ const { assets } = await utils . searchAssets ( admin . accessToken , { libraryId : library . id , withDeleted : true } ) ;
759
+ expect ( assets . count ) . toBe ( 1 ) ;
760
+ }
761
+
762
+ const offlineAsset = await utils . getAssetInfo ( admin . accessToken , assets . items [ 0 ] . id ) ;
763
+
764
+ expect ( offlineAsset . isTrashed ) . toBe ( true ) ;
765
+ expect ( offlineAsset . originalPath ) . toBe ( `${ testAssetDirInternal } /temp/offline/offline.png` ) ;
766
+ expect ( offlineAsset . isOffline ) . toBe ( true ) ;
767
+
768
+ utils . renameImageFile ( `${ testAssetDir } /temp/offline.png` , `${ testAssetDir } /temp/offline/offline.png` ) ;
769
+
770
+ await utils . updateLibrary ( admin . accessToken , library . id , { exclusionPatterns : [ '**/offline/**' ] } ) ;
771
+
772
+ {
773
+ const { status } = await request ( app )
774
+ . post ( `/libraries/${ library . id } /scan` )
775
+ . set ( 'Authorization' , `Bearer ${ admin . accessToken } ` )
776
+ . send ( ) ;
777
+ expect ( status ) . toBe ( 204 ) ;
778
+ }
779
+
780
+ await utils . waitForQueueFinish ( admin . accessToken , 'library' ) ;
781
+
782
+ const stillOfflineAsset = await utils . getAssetInfo ( admin . accessToken , assets . items [ 0 ] . id ) ;
783
+
784
+ expect ( stillOfflineAsset . isTrashed ) . toBe ( true ) ;
785
+ expect ( stillOfflineAsset . originalPath ) . toBe ( `${ testAssetDirInternal } /temp/offline/offline.png` ) ;
786
+ expect ( stillOfflineAsset . isOffline ) . toBe ( true ) ;
787
+
788
+ {
789
+ const { assets } = await utils . searchAssets ( admin . accessToken , { libraryId : library . id , withDeleted : true } ) ;
790
+ expect ( assets . count ) . toBe ( 1 ) ;
791
+ }
792
+ } ) ;
604
793
} ) ;
605
794
606
795
describe ( 'POST /libraries/:id/validate' , ( ) => {
0 commit comments