@@ -564,6 +564,48 @@ describe("DownloadQueue", () => {
564
564
) ;
565
565
} ) ;
566
566
567
+ it ( "doesn't start downloads for 'finished' specs" , async ( ) => {
568
+ const queue = new DownloadQueue ( ) ;
569
+
570
+ ( download as jest . Mock ) . mockReturnValue ( task ) ;
571
+ ( exists as jest . Mock ) . mockImplementation ( ( ) => true ) ;
572
+
573
+ await kvfs . write ( "/mydomain/foo" , {
574
+ id : "foo" ,
575
+ url : "http://foo.com/a.mp3" ,
576
+ path : `${ RNFS . DocumentDirectoryPath } /DownloadQueue/mydomain/foo` ,
577
+ createTime : Date . now ( ) - 1000 ,
578
+ finished : true ,
579
+ } ) ;
580
+ await queue . init ( { domain : "mydomain" } ) ;
581
+
582
+ // This test protects against a regression. We used to restart downloads
583
+ // even for finished specs.
584
+ expect ( task . resume ) . not . toHaveBeenCalled ( ) ;
585
+ expect ( download ) . not . toHaveBeenCalled ( ) ;
586
+ } ) ;
587
+
588
+ it ( "doesn't start downloads for lazy-deleted specs" , async ( ) => {
589
+ const queue = new DownloadQueue ( ) ;
590
+
591
+ ( download as jest . Mock ) . mockReturnValue ( task ) ;
592
+ ( exists as jest . Mock ) . mockImplementation ( ( ) => true ) ;
593
+
594
+ await kvfs . write ( "/mydomain/foo" , {
595
+ id : "foo" ,
596
+ url : "http://foo.com/a.mp3" ,
597
+ path : `${ RNFS . DocumentDirectoryPath } /DownloadQueue/mydomain/foo` ,
598
+ createTime : - ( Date . now ( ) + 1000 ) , // Delete one second into future
599
+ finished : false , // Force the issue by simulating a half-downloaded file
600
+ } ) ;
601
+ await queue . init ( { domain : "mydomain" } ) ;
602
+
603
+ // This test protects against a regression. We used to restart downloads
604
+ // even for finished specs.
605
+ expect ( task . resume ) . not . toHaveBeenCalled ( ) ;
606
+ expect ( download ) . not . toHaveBeenCalled ( ) ;
607
+ } ) ;
608
+
567
609
it ( "enforces netInfo callbacks when activeNetworkTypes is passed" , async ( ) => {
568
610
const queue = new DownloadQueue ( ) ;
569
611
0 commit comments