@@ -17,7 +17,6 @@ describe("JsonService", () => {
17
17
"Custom-Header-1" : "this-is-header-1" ,
18
18
"Custom-Header-2" : "this-is-header-2" ,
19
19
"acCept" : "application/fake" ,
20
- "AuthoriZation" : "not good" ,
21
20
"Content-Type" : "application/fail" ,
22
21
} ;
23
22
const dynamicExtraHeaders = {
@@ -26,7 +25,6 @@ describe("JsonService", () => {
26
25
return "my-name-is-header-2" ;
27
26
} ,
28
27
"acCept" : ( ) => "nothing" ,
29
- "AuthoriZation" : ( ) => "not good" ,
30
28
"Content-Type" : "application/fail" ,
31
29
} ;
32
30
@@ -587,4 +585,86 @@ describe("JsonService", () => {
587
585
expect ( result ) . toEqual ( json ) ;
588
586
} ) ;
589
587
} ) ;
588
+
589
+ describe ( "_appendExtraHeaders" , ( ) => {
590
+ it ( "should add extra static headers" , ( ) => {
591
+ // arrange
592
+ const headers = {
593
+ "Accept" : "application/json" ,
594
+ } ;
595
+ subject [ "_extraHeaders" ] = {
596
+ "foo" : "bar" ,
597
+ } ;
598
+
599
+ // act
600
+ subject [ "_appendExtraHeaders" ] ( headers ) ;
601
+
602
+ // assert
603
+ expect ( headers ) . toMatchObject ( {
604
+ "Accept" : "application/json" ,
605
+ "foo" : "bar" ,
606
+ } ) ;
607
+ } ) ;
608
+
609
+ it ( "should add extra dynamic headers" , ( ) => {
610
+ // arrange
611
+ const headers = {
612
+ "Accept" : "application/json" ,
613
+ } ;
614
+ subject [ "_extraHeaders" ] = {
615
+ "foo" : ( ) => {
616
+ return "bar" ;
617
+ } ,
618
+ } ;
619
+
620
+ // act
621
+ subject [ "_appendExtraHeaders" ] ( headers ) ;
622
+
623
+ // assert
624
+ expect ( headers ) . toMatchObject ( {
625
+ "Accept" : "application/json" ,
626
+ "foo" : "bar" ,
627
+ } ) ;
628
+ } ) ;
629
+
630
+ it ( "should skip protected special headers" , ( ) => {
631
+ // arrange
632
+ const headers = {
633
+ "Accept" : "application/json" ,
634
+ } ;
635
+ subject [ "_extraHeaders" ] = {
636
+ "foo" : "bar" ,
637
+ "accept" : "application/xml" ,
638
+ } ;
639
+
640
+ // act
641
+ subject [ "_appendExtraHeaders" ] ( headers ) ;
642
+
643
+ // assert
644
+ expect ( headers ) . toMatchObject ( {
645
+ "Accept" : "application/json" ,
646
+ "foo" : "bar" ,
647
+ } ) ;
648
+ } ) ;
649
+
650
+ it ( "should skip override special headers" , ( ) => {
651
+ // arrange
652
+ const headers = {
653
+ "Authorization" : "Bearer 1" ,
654
+ } ;
655
+ subject [ "_extraHeaders" ] = {
656
+ "foo" : "bar" ,
657
+ "Authorization" : "Bearer 2" ,
658
+ } ;
659
+
660
+ // act
661
+ subject [ "_appendExtraHeaders" ] ( headers ) ;
662
+
663
+ // assert
664
+ expect ( headers ) . toMatchObject ( {
665
+ "Authorization" : "Bearer 1" ,
666
+ "foo" : "bar" ,
667
+ } ) ;
668
+ } ) ;
669
+ } ) ;
590
670
} ) ;
0 commit comments