@@ -65,7 +65,74 @@ describe('Segment.io', () => {
6565 } )
6666 } )
6767
68- describe ( 'configuring a keep alive' , ( ) => {
68+ describe ( 'configuring additionalHeaders' , ( ) => {
69+ it ( 'should accept additional headers' , async ( ) => {
70+ const analytics = new Analytics ( { writeKey : 'foo' } )
71+
72+ await analytics . register (
73+ await segmentio ( analytics , {
74+ apiKey : '' ,
75+ deliveryStrategy : {
76+ config : {
77+ additionalHeaders : {
78+ 'X-My-Header' : 'foo' ,
79+ } ,
80+ } ,
81+ } ,
82+ } )
83+ )
84+
85+ await analytics . track ( 'foo' )
86+ const [ _ , params ] = spyMock . mock . lastCall
87+ expect ( params . headers [ 'X-My-Header' ] ) . toBe ( 'foo' )
88+ expect ( params . headers [ 'Content-Type' ] ) . toBe ( 'text/plain' )
89+ } )
90+
91+ it ( 'should allow additional headers to be a function' , async ( ) => {
92+ const analytics = new Analytics ( { writeKey : 'foo' } )
93+
94+ await analytics . register (
95+ await segmentio ( analytics , {
96+ apiKey : '' ,
97+ deliveryStrategy : {
98+ config : {
99+ additionalHeaders : ( ) => ( {
100+ 'X-My-Header' : 'foo' ,
101+ } ) ,
102+ } ,
103+ } ,
104+ } )
105+ )
106+
107+ await analytics . track ( 'foo' )
108+ const [ _ , params ] = spyMock . mock . lastCall
109+ expect ( params . headers [ 'X-My-Header' ] ) . toBe ( 'foo' )
110+ expect ( params . headers [ 'Content-Type' ] ) . toBe ( 'text/plain' )
111+ } )
112+ } )
113+
114+ describe ( 'configuring fetch priority' , ( ) => {
115+ it ( 'should accept fetch priority configuration' , async ( ) => {
116+ const analytics = new Analytics ( { writeKey : 'foo' } )
117+
118+ await analytics . register (
119+ await segmentio ( analytics , {
120+ apiKey : '' ,
121+ deliveryStrategy : {
122+ config : {
123+ fetchPriority : 'high' ,
124+ } ,
125+ } ,
126+ } )
127+ )
128+
129+ await analytics . track ( 'foo' )
130+ const [ _ , params ] = spyMock . mock . lastCall
131+ expect ( params . priority ) . toBe ( 'high' )
132+ } )
133+ } )
134+
135+ describe ( 'configuring keepalive' , ( ) => {
69136 it ( 'should accept keepalive configuration' , async ( ) => {
70137 const analytics = new Analytics ( { writeKey : 'foo' } )
71138
0 commit comments