@@ -183,4 +183,49 @@ describe('nodeDatafileManager', () => {
183183 expect ( makeGetRequestSpy ) . toBeCalledWith ( 'https://myawesomeurl/' , expect . anything ( ) ) ;
184184 await manager . stop ( ) ;
185185 } ) ;
186+
187+ it ( 'passes custom headers to makeGetRequest and merges with system headers' , async ( ) => {
188+ makeGetRequestSpy . mockReturnValue ( {
189+ abort : jest . fn ( ) ,
190+ responsePromise : Promise . resolve ( {
191+ statusCode : 200 ,
192+ body : '{"foo":"bar"}' ,
193+ headers : {
194+ 'last-modified' : 'Fri, 08 Mar 2019 18:57:17 GMT' ,
195+ } ,
196+ } ) ,
197+ } ) ;
198+ const manager = new NodeDatafileManager ( {
199+ sdkKey : '1234' ,
200+ autoUpdate : true ,
201+ customHeaders : {
202+ 'X-Custom-Header' : 'custom-value' ,
203+ 'X-Environment' : 'production' ,
204+ } ,
205+ } ) ;
206+ manager . start ( ) ;
207+ await manager . onReady ( ) ;
208+
209+ // First request should have custom headers
210+ expect ( makeGetRequestSpy ) . toBeCalledTimes ( 1 ) ;
211+ expect ( makeGetRequestSpy . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'https://cdn.optimizely.com/datafiles/1234.json' ) ;
212+ expect ( makeGetRequestSpy . mock . calls [ 0 ] [ 1 ] ) . toEqual ( {
213+ 'X-Custom-Header' : 'custom-value' ,
214+ 'X-Environment' : 'production' ,
215+ } ) ;
216+
217+ // Advance time to trigger second request
218+ await advanceTimersByTime ( 300000 ) ;
219+
220+ // Second request should have both custom headers AND if-modified-since
221+ expect ( makeGetRequestSpy ) . toBeCalledTimes ( 2 ) ;
222+ expect ( makeGetRequestSpy . mock . calls [ 1 ] [ 0 ] ) . toBe ( 'https://cdn.optimizely.com/datafiles/1234.json' ) ;
223+ expect ( makeGetRequestSpy . mock . calls [ 1 ] [ 1 ] ) . toEqual ( {
224+ 'X-Custom-Header' : 'custom-value' ,
225+ 'X-Environment' : 'production' ,
226+ 'if-modified-since' : 'Fri, 08 Mar 2019 18:57:17 GMT' ,
227+ } ) ;
228+
229+ await manager . stop ( ) ;
230+ } ) ;
186231} ) ;
0 commit comments