@@ -591,7 +591,8 @@ describe('ledger api unit tests', function () {
591
591
} ) )
592
592
. setIn ( [ 'ledger' , 'synopsis' , 'publishers' , publisherKey ] , Immutable . fromJS ( {
593
593
visits : 1 ,
594
- duration : 1000
594
+ duration : 1000 ,
595
+ providerName : 'YouTube'
595
596
} ) )
596
597
597
598
beforeEach ( function ( ) {
@@ -698,10 +699,26 @@ describe('ledger api unit tests', function () {
698
699
ignoreMinTime : true
699
700
} ) . calledOnce )
700
701
} )
702
+
703
+ it ( 'state for this publisher is corrupted, so we need to fetch it again' , function ( ) {
704
+ const badState = defaultAppState
705
+ . setIn ( [ 'cache' , 'ledgerVideos' , videoId ] , Immutable . fromJS ( {
706
+ publisher : publisherKey
707
+ } ) )
708
+ . setIn ( [ 'ledger' , 'synopsis' , 'publishers' , publisherKey ] , Immutable . fromJS ( {
709
+ options : {
710
+ excluded : false
711
+ }
712
+ } ) )
713
+
714
+ ledgerApi . onMediaRequest ( badState , xhr , ledgerMediaProviders . YOUTUBE , 10 )
715
+ assert ( mediaSpy . calledOnce )
716
+ assert ( saveVisitSpy . notCalled )
717
+ } )
701
718
} )
702
719
703
720
describe ( 'onMediaPublisher' , function ( ) {
704
- let saveVisitSpy , verifiedPStub
721
+ let saveVisitSpy , verifiedPStub , setPublisherSpy
705
722
706
723
const expectedState = Immutable . fromJS ( {
707
724
cache : {
@@ -730,12 +747,18 @@ describe('ledger api unit tests', function () {
730
747
migrations : { }
731
748
} )
732
749
733
- before ( function ( ) {
734
- verifiedPStub = sinon . stub ( ledgerApi , 'verifiedP' , ( state , publisherKey , fn ) => state )
750
+ const response = Immutable . fromJS ( {
751
+ publisher : publisherKey ,
752
+ faviconName : 'Brave' ,
753
+ faviconURL : 'data:image/jpeg;base64,...' ,
754
+ publisherURL : 'https://brave.com' ,
755
+ providerName : 'Youtube'
735
756
} )
736
757
737
- after ( function ( ) {
738
- verifiedPStub . restore ( )
758
+ before ( function ( ) {
759
+ verifiedPStub = sinon . stub ( ledgerApi , 'verifiedP' , ( state , publisherKey , fn ) => state )
760
+ saveVisitSpy = sinon . spy ( ledgerApi , 'saveVisit' )
761
+ setPublisherSpy = sinon . spy ( ledgerState , 'setPublisher' )
739
762
} )
740
763
741
764
beforeEach ( function ( ) {
@@ -748,33 +771,92 @@ describe('ledger api unit tests', function () {
748
771
options : {
749
772
exclude : true
750
773
} ,
751
- providerName : 'Youtube '
774
+ providerName : 'YouTube '
752
775
}
753
776
}
754
777
} )
755
- saveVisitSpy = sinon . spy ( ledgerApi , 'saveVisit' )
778
+ } )
779
+
780
+ after ( function ( ) {
781
+ verifiedPStub . restore ( )
782
+ saveVisitSpy . restore ( )
783
+ setPublisherSpy . restore ( )
756
784
} )
757
785
758
786
afterEach ( function ( ) {
759
787
ledgerApi . setSynopsis ( undefined )
760
- saveVisitSpy . restore ( )
788
+ verifiedPStub . reset ( )
789
+ saveVisitSpy . reset ( )
790
+ setPublisherSpy . reset ( )
761
791
} )
762
792
763
793
it ( 'null case' , function ( ) {
764
794
const result = ledgerApi . onMediaPublisher ( defaultAppState )
765
795
assert . deepEqual ( result . toJS ( ) , defaultAppState . toJS ( ) )
796
+ assert ( setPublisherSpy . notCalled )
797
+ assert ( saveVisitSpy . notCalled )
766
798
} )
767
799
768
- it ( 'create publisher if new and add cache' , function ( ) {
769
- const response = Immutable . fromJS ( {
770
- publisher : publisherKey ,
771
- faviconName : 'Brave' ,
772
- faviconURL : 'data:image/jpeg;base64,...' ,
773
- publisherURL : 'https://brave.com' ,
774
- providerName : 'Youtube'
800
+ it ( 'we do not have publisher in the synopsis' , function ( ) {
801
+ ledgerApi . setSynopsis ( {
802
+ initPublisher : ( ) => {
803
+ ledgerApi . setSynopsis ( {
804
+ initPublisher : ( ) => { } ,
805
+ addPublisher : ( ) => { } ,
806
+ publishers : {
807
+ [ publisherKey ] : {
808
+ exclude : false ,
809
+ options : {
810
+ exclude : true
811
+ } ,
812
+ providerName : 'YouTube'
813
+ }
814
+ }
815
+ } )
816
+ } ,
817
+ addPublisher : ( ) => { } ,
818
+ publishers : { }
775
819
} )
776
820
821
+ const newState = Immutable . fromJS ( {
822
+ cache : {
823
+ ledgerVideos : {
824
+ 'youtube_kLiLOkzLetE' : {
825
+ publisher : 'youtube#channel:UCFNTTISby1c_H-rm5Ww5rZg' ,
826
+ faviconName : 'Brave' ,
827
+ providerName : 'Youtube' ,
828
+ faviconURL : 'data:image/jpeg;base64,...' ,
829
+ publisherURL : 'https://brave.com'
830
+ }
831
+ }
832
+ } ,
833
+ ledger : {
834
+ synopsis : {
835
+ publishers : {
836
+ 'youtube#channel:UCFNTTISby1c_H-rm5Ww5rZg' : {
837
+ options : {
838
+ exclude : true
839
+ } ,
840
+ faviconName : 'old Brave' ,
841
+ faviconURL : 'data:image/jpeg;base64,...' ,
842
+ publisherURL : 'https://brave.io' ,
843
+ providerName : 'Youtube'
844
+ }
845
+ }
846
+ }
847
+ } ,
848
+ migrations : { }
849
+ } )
850
+
851
+ const state = ledgerApi . onMediaPublisher ( newState , videoId , response , 1000 , false )
852
+ assert ( saveVisitSpy . calledOnce )
853
+ assert ( setPublisherSpy . calledTwice )
854
+ assert . deepEqual ( state . toJS ( ) , expectedState . toJS ( ) )
855
+ } )
856
+
857
+ it ( 'create publisher if new and add cache' , function ( ) {
777
858
const state = ledgerApi . onMediaPublisher ( defaultAppState , videoId , response , 1000 , false )
859
+ assert ( setPublisherSpy . calledTwice )
778
860
assert ( saveVisitSpy . calledOnce )
779
861
assert . deepEqual ( state . toJS ( ) , expectedState . toJS ( ) )
780
862
} )
@@ -810,15 +892,8 @@ describe('ledger api unit tests', function () {
810
892
migrations : { }
811
893
} )
812
894
813
- const response = Immutable . fromJS ( {
814
- publisher : publisherKey ,
815
- faviconName : 'Brave' ,
816
- faviconURL : 'data:image/jpeg;base64,...' ,
817
- publisherURL : 'https://brave.com' ,
818
- providerName : 'Youtube'
819
- } )
820
-
821
895
const state = ledgerApi . onMediaPublisher ( newState , videoId , response , 1000 , false )
896
+ assert ( setPublisherSpy . calledOnce )
822
897
assert ( saveVisitSpy . calledOnce )
823
898
assert . deepEqual ( state . toJS ( ) , expectedState . toJS ( ) )
824
899
} )
0 commit comments