@@ -529,7 +529,8 @@ describe('ledger api unit tests', function () {
529
529
} ) )
530
530
. setIn ( [ 'ledger' , 'synopsis' , 'publishers' , publisherKey ] , Immutable . fromJS ( {
531
531
visits : 1 ,
532
- duration : 1000
532
+ duration : 1000 ,
533
+ providerName : 'YouTube'
533
534
} ) )
534
535
535
536
beforeEach ( function ( ) {
@@ -636,10 +637,26 @@ describe('ledger api unit tests', function () {
636
637
ignoreMinTime : true
637
638
} ) . calledOnce )
638
639
} )
640
+
641
+ it ( 'state for this publisher is corrupted, so we need to fetch it again' , function ( ) {
642
+ const badState = defaultAppState
643
+ . setIn ( [ 'cache' , 'ledgerVideos' , videoId ] , Immutable . fromJS ( {
644
+ publisher : publisherKey
645
+ } ) )
646
+ . setIn ( [ 'ledger' , 'synopsis' , 'publishers' , publisherKey ] , Immutable . fromJS ( {
647
+ options : {
648
+ excluded : false
649
+ }
650
+ } ) )
651
+
652
+ ledgerApi . onMediaRequest ( badState , xhr , ledgerMediaProviders . YOUTUBE , 10 )
653
+ assert ( mediaSpy . calledOnce )
654
+ assert ( saveVisitSpy . notCalled )
655
+ } )
639
656
} )
640
657
641
658
describe ( 'onMediaPublisher' , function ( ) {
642
- let saveVisitSpy , verifiedPStub
659
+ let saveVisitSpy , verifiedPStub , setPublisherSpy
643
660
644
661
const expectedState = Immutable . fromJS ( {
645
662
cache : {
@@ -668,12 +685,18 @@ describe('ledger api unit tests', function () {
668
685
migrations : { }
669
686
} )
670
687
671
- before ( function ( ) {
672
- verifiedPStub = sinon . stub ( ledgerApi , 'verifiedP' , ( state , publisherKey , fn ) => state )
688
+ const response = Immutable . fromJS ( {
689
+ publisher : publisherKey ,
690
+ faviconName : 'Brave' ,
691
+ faviconURL : 'data:image/jpeg;base64,...' ,
692
+ publisherURL : 'https://brave.com' ,
693
+ providerName : 'Youtube'
673
694
} )
674
695
675
- after ( function ( ) {
676
- verifiedPStub . restore ( )
696
+ before ( function ( ) {
697
+ verifiedPStub = sinon . stub ( ledgerApi , 'verifiedP' , ( state , publisherKey , fn ) => state )
698
+ saveVisitSpy = sinon . spy ( ledgerApi , 'saveVisit' )
699
+ setPublisherSpy = sinon . spy ( ledgerState , 'setPublisher' )
677
700
} )
678
701
679
702
beforeEach ( function ( ) {
@@ -686,33 +709,92 @@ describe('ledger api unit tests', function () {
686
709
options : {
687
710
exclude : true
688
711
} ,
689
- providerName : 'Youtube '
712
+ providerName : 'YouTube '
690
713
}
691
714
}
692
715
} )
693
- saveVisitSpy = sinon . spy ( ledgerApi , 'saveVisit' )
716
+ } )
717
+
718
+ after ( function ( ) {
719
+ verifiedPStub . restore ( )
720
+ saveVisitSpy . restore ( )
721
+ setPublisherSpy . restore ( )
694
722
} )
695
723
696
724
afterEach ( function ( ) {
697
725
ledgerApi . setSynopsis ( undefined )
698
- saveVisitSpy . restore ( )
726
+ verifiedPStub . reset ( )
727
+ saveVisitSpy . reset ( )
728
+ setPublisherSpy . reset ( )
699
729
} )
700
730
701
731
it ( 'null case' , function ( ) {
702
732
const result = ledgerApi . onMediaPublisher ( defaultAppState )
703
733
assert . deepEqual ( result . toJS ( ) , defaultAppState . toJS ( ) )
734
+ assert ( setPublisherSpy . notCalled )
735
+ assert ( saveVisitSpy . notCalled )
704
736
} )
705
737
706
- it ( 'create publisher if new and add cache' , function ( ) {
707
- const response = Immutable . fromJS ( {
708
- publisher : publisherKey ,
709
- faviconName : 'Brave' ,
710
- faviconURL : 'data:image/jpeg;base64,...' ,
711
- publisherURL : 'https://brave.com' ,
712
- providerName : 'Youtube'
738
+ it ( 'we do not have publisher in the synopsis' , function ( ) {
739
+ ledgerApi . setSynopsis ( {
740
+ initPublisher : ( ) => {
741
+ ledgerApi . setSynopsis ( {
742
+ initPublisher : ( ) => { } ,
743
+ addPublisher : ( ) => { } ,
744
+ publishers : {
745
+ [ publisherKey ] : {
746
+ exclude : false ,
747
+ options : {
748
+ exclude : true
749
+ } ,
750
+ providerName : 'YouTube'
751
+ }
752
+ }
753
+ } )
754
+ } ,
755
+ addPublisher : ( ) => { } ,
756
+ publishers : { }
713
757
} )
714
758
759
+ const newState = Immutable . fromJS ( {
760
+ cache : {
761
+ ledgerVideos : {
762
+ 'youtube_kLiLOkzLetE' : {
763
+ publisher : 'youtube#channel:UCFNTTISby1c_H-rm5Ww5rZg' ,
764
+ faviconName : 'Brave' ,
765
+ providerName : 'Youtube' ,
766
+ faviconURL : 'data:image/jpeg;base64,...' ,
767
+ publisherURL : 'https://brave.com'
768
+ }
769
+ }
770
+ } ,
771
+ ledger : {
772
+ synopsis : {
773
+ publishers : {
774
+ 'youtube#channel:UCFNTTISby1c_H-rm5Ww5rZg' : {
775
+ options : {
776
+ exclude : true
777
+ } ,
778
+ faviconName : 'old Brave' ,
779
+ faviconURL : 'data:image/jpeg;base64,...' ,
780
+ publisherURL : 'https://brave.io' ,
781
+ providerName : 'Youtube'
782
+ }
783
+ }
784
+ }
785
+ } ,
786
+ migrations : { }
787
+ } )
788
+
789
+ const state = ledgerApi . onMediaPublisher ( newState , videoId , response , 1000 , false )
790
+ assert ( saveVisitSpy . calledOnce )
791
+ assert ( setPublisherSpy . calledTwice )
792
+ assert . deepEqual ( state . toJS ( ) , expectedState . toJS ( ) )
793
+ } )
794
+
795
+ it ( 'create publisher if new and add cache' , function ( ) {
715
796
const state = ledgerApi . onMediaPublisher ( defaultAppState , videoId , response , 1000 , false )
797
+ assert ( setPublisherSpy . calledTwice )
716
798
assert ( saveVisitSpy . calledOnce )
717
799
assert . deepEqual ( state . toJS ( ) , expectedState . toJS ( ) )
718
800
} )
@@ -748,15 +830,8 @@ describe('ledger api unit tests', function () {
748
830
migrations : { }
749
831
} )
750
832
751
- const response = Immutable . fromJS ( {
752
- publisher : publisherKey ,
753
- faviconName : 'Brave' ,
754
- faviconURL : 'data:image/jpeg;base64,...' ,
755
- publisherURL : 'https://brave.com' ,
756
- providerName : 'Youtube'
757
- } )
758
-
759
833
const state = ledgerApi . onMediaPublisher ( newState , videoId , response , 1000 , false )
834
+ assert ( setPublisherSpy . calledOnce )
760
835
assert ( saveVisitSpy . calledOnce )
761
836
assert . deepEqual ( state . toJS ( ) , expectedState . toJS ( ) )
762
837
} )
0 commit comments