@@ -635,20 +635,21 @@ describe('/libraries', () => {
635
635
it ( 'should remove offline files' , async ( ) => {
636
636
const library = await utils . createLibrary ( admin . accessToken , {
637
637
ownerId : admin . userId ,
638
- importPaths : [ `${ testAssetDirInternal } /temp/offline2 ` ] ,
638
+ importPaths : [ `${ testAssetDirInternal } /temp/offline ` ] ,
639
639
} ) ;
640
640
641
- utils . createImageFile ( `${ testAssetDir } /temp/offline2/assetA.png` ) ;
641
+ utils . createImageFile ( `${ testAssetDir } /temp/offline/online.png` ) ;
642
+ utils . createImageFile ( `${ testAssetDir } /temp/offline/offline.png` ) ;
642
643
643
644
await scan ( admin . accessToken , library . id ) ;
644
645
await utils . waitForQueueFinish ( admin . accessToken , 'library' ) ;
645
646
646
647
const { assets : initialAssets } = await utils . metadataSearch ( admin . accessToken , {
647
648
libraryId : library . id ,
648
649
} ) ;
649
- expect ( initialAssets . count ) . toBe ( 1 ) ;
650
+ expect ( initialAssets . count ) . toBe ( 2 ) ;
650
651
651
- utils . removeImageFile ( `${ testAssetDir } /temp/offline2/assetA .png` ) ;
652
+ utils . removeImageFile ( `${ testAssetDir } /temp/offline/offline .png` ) ;
652
653
653
654
await scan ( admin . accessToken , library . id ) ;
654
655
await utils . waitForQueueFinish ( admin . accessToken , 'library' ) ;
@@ -669,7 +670,54 @@ describe('/libraries', () => {
669
670
670
671
const { assets } = await utils . metadataSearch ( admin . accessToken , { libraryId : library . id } ) ;
671
672
672
- expect ( assets . count ) . toBe ( 0 ) ;
673
+ expect ( assets . count ) . toBe ( 1 ) ;
674
+
675
+ utils . removeImageFile ( `${ testAssetDir } /temp/offline/online.png` ) ;
676
+ } ) ;
677
+
678
+ it ( 'should remove offline files from trash' , async ( ) => {
679
+ const library = await utils . createLibrary ( admin . accessToken , {
680
+ ownerId : admin . userId ,
681
+ importPaths : [ `${ testAssetDirInternal } /temp/offline` ] ,
682
+ } ) ;
683
+
684
+ utils . createImageFile ( `${ testAssetDir } /temp/offline/online.png` ) ;
685
+ utils . createImageFile ( `${ testAssetDir } /temp/offline/offline.png` ) ;
686
+
687
+ await scan ( admin . accessToken , library . id ) ;
688
+ await utils . waitForQueueFinish ( admin . accessToken , 'library' ) ;
689
+
690
+ const { assets : initialAssets } = await utils . metadataSearch ( admin . accessToken , {
691
+ libraryId : library . id ,
692
+ } ) ;
693
+
694
+ expect ( initialAssets . count ) . toBe ( 2 ) ;
695
+ utils . removeImageFile ( `${ testAssetDir } /temp/offline/offline.png` ) ;
696
+
697
+ await scan ( admin . accessToken , library . id ) ;
698
+ await utils . waitForQueueFinish ( admin . accessToken , 'library' ) ;
699
+
700
+ const { assets : offlineAssets } = await utils . metadataSearch ( admin . accessToken , {
701
+ libraryId : library . id ,
702
+ isOffline : true ,
703
+ } ) ;
704
+ expect ( offlineAssets . count ) . toBe ( 1 ) ;
705
+
706
+ const { status } = await request ( app )
707
+ . post ( `/libraries/${ library . id } /removeOffline` )
708
+ . set ( 'Authorization' , `Bearer ${ admin . accessToken } ` )
709
+ . send ( ) ;
710
+ expect ( status ) . toBe ( 204 ) ;
711
+ await utils . waitForQueueFinish ( admin . accessToken , 'library' ) ;
712
+ await utils . waitForQueueFinish ( admin . accessToken , 'backgroundTask' ) ;
713
+
714
+ const { assets } = await utils . metadataSearch ( admin . accessToken , { libraryId : library . id } ) ;
715
+
716
+ expect ( assets . count ) . toBe ( 1 ) ;
717
+ expect ( assets . items [ 0 ] . isOffline ) . toBe ( false ) ;
718
+ expect ( assets . items [ 0 ] . originalPath ) . toEqual ( `${ testAssetDirInternal } /temp/offline/online.png` ) ;
719
+
720
+ utils . removeImageFile ( `${ testAssetDir } /temp/offline/online.png` ) ;
673
721
} ) ;
674
722
675
723
it ( 'should not remove online files' , async ( ) => {
0 commit comments