Skip to content

Commit 20c40b4

Browse files
[FSSDK-11938] test addition
1 parent 6f73492 commit 20c40b4

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

lib/modules/datafile-manager/httpPollingDatafileManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import { getLogger } from '../logging';
18-
import { sprintf } from '../../utils/fns';
18+
import { sprintf, assign } from '../../utils/fns';
1919
import { DatafileManager, DatafileManagerConfig, DatafileUpdate } from './datafileManager';
2020
import EventEmitter, { Disposer } from './eventEmitter';
2121
import { AbortableRequest, Response, Headers } from './http';
@@ -272,7 +272,7 @@ export default abstract class HttpPollingDatafileManager implements DatafileMana
272272
const headers: Headers = {};
273273

274274
if (this.customHeaders) {
275-
Object.assign(headers, this.customHeaders);
275+
assign(headers, this.customHeaders);
276276
}
277277

278278
if (this.lastResponseLastModified) {

tests/nodeDatafileManager.spec.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)