@@ -38,7 +38,7 @@ jest.mock('../src/platform', () => ({
3838 __esModule : true ,
3939 default : jest . fn ( ( logger : LDLogger ) => ( {
4040 crypto : new PlatformCrypto ( ) ,
41- info : new PlatformInfo ( logger ) ,
41+ info : new PlatformInfo ( logger , { } ) ,
4242 requests : {
4343 createEventSource : jest . fn ( ) ,
4444 fetch : jest . fn ( ) ,
@@ -67,7 +67,7 @@ it('uses correct default diagnostic url', () => {
6767 } ;
6868 ( createPlatform as jest . Mock ) . mockReturnValue ( {
6969 crypto : new PlatformCrypto ( ) ,
70- info : new PlatformInfo ( logger ) ,
70+ info : new PlatformInfo ( logger , { } ) ,
7171 requests : {
7272 createEventSource : jest . fn ( ) ,
7373 fetch : mockedFetch ,
@@ -95,7 +95,7 @@ it('uses correct default analytics event url', async () => {
9595 } ;
9696 ( createPlatform as jest . Mock ) . mockReturnValue ( {
9797 crypto : new PlatformCrypto ( ) ,
98- info : new PlatformInfo ( logger ) ,
98+ info : new PlatformInfo ( logger , { } ) ,
9999 requests : {
100100 createEventSource : createMockEventSource ,
101101 fetch : mockedFetch ,
@@ -127,7 +127,7 @@ it('uses correct default polling url', async () => {
127127 } ;
128128 ( createPlatform as jest . Mock ) . mockReturnValue ( {
129129 crypto : new PlatformCrypto ( ) ,
130- info : new PlatformInfo ( logger ) ,
130+ info : new PlatformInfo ( logger , { } ) ,
131131 requests : {
132132 createEventSource : jest . fn ( ) ,
133133 fetch : mockedFetch ,
@@ -158,7 +158,7 @@ it('uses correct default streaming url', (done) => {
158158 } ;
159159 ( createPlatform as jest . Mock ) . mockReturnValue ( {
160160 crypto : new PlatformCrypto ( ) ,
161- info : new PlatformInfo ( logger ) ,
161+ info : new PlatformInfo ( logger , { } ) ,
162162 requests : {
163163 createEventSource : mockedCreateEventSource ,
164164 fetch : jest . fn ( ) ,
@@ -198,7 +198,7 @@ it('includes authorization header for polling', async () => {
198198 } ;
199199 ( createPlatform as jest . Mock ) . mockReturnValue ( {
200200 crypto : new PlatformCrypto ( ) ,
201- info : new PlatformInfo ( logger ) ,
201+ info : new PlatformInfo ( logger , { } ) ,
202202 requests : {
203203 createEventSource : jest . fn ( ) ,
204204 fetch : mockedFetch ,
@@ -223,6 +223,41 @@ it('includes authorization header for polling', async () => {
223223 ) ;
224224} ) ;
225225
226+ it ( 'includes x-launchdarkly-wrapper header for polling' , async ( ) => {
227+ const mockedFetch = mockFetch ( '{"flagA": true}' , 200 ) ;
228+ const logger : LDLogger = {
229+ error : jest . fn ( ) ,
230+ warn : jest . fn ( ) ,
231+ info : jest . fn ( ) ,
232+ debug : jest . fn ( ) ,
233+ } ;
234+ ( createPlatform as jest . Mock ) . mockReturnValue ( {
235+ crypto : new PlatformCrypto ( ) ,
236+ info : new PlatformInfo ( logger , { wrapperName : 'Rapper' , wrapperVersion : '1.0.0' } ) ,
237+ requests : {
238+ createEventSource : jest . fn ( ) ,
239+ fetch : mockedFetch ,
240+ getEventSourceCapabilities : jest . fn ( ) ,
241+ } ,
242+ encoding : new PlatformEncoding ( ) ,
243+ storage : new PlatformStorage ( logger ) ,
244+ } ) ;
245+ const client = new ReactNativeLDClient ( 'mobile-key' , AutoEnvAttributes . Enabled , {
246+ diagnosticOptOut : true ,
247+ sendEvents : false ,
248+ initialConnectionMode : 'polling' ,
249+ automaticBackgroundHandling : false ,
250+ } ) ;
251+ await client . identify ( { kind : 'user' , key : 'bob' } ) ;
252+
253+ expect ( mockedFetch ) . toHaveBeenCalledWith (
254+ expect . anything ( ) ,
255+ expect . objectContaining ( {
256+ headers : expect . objectContaining ( { 'x-launchdarkly-wrapper' : 'Rapper/1.0.0' } ) ,
257+ } ) ,
258+ ) ;
259+ } ) ;
260+
226261it ( 'includes authorization header for streaming' , ( done ) => {
227262 const mockedCreateEventSource = jest . fn ( ) ;
228263 const logger : LDLogger = {
@@ -233,7 +268,7 @@ it('includes authorization header for streaming', (done) => {
233268 } ;
234269 ( createPlatform as jest . Mock ) . mockReturnValue ( {
235270 crypto : new PlatformCrypto ( ) ,
236- info : new PlatformInfo ( logger ) ,
271+ info : new PlatformInfo ( logger , { } ) ,
237272 requests : {
238273 createEventSource : mockedCreateEventSource ,
239274 fetch : jest . fn ( ) ,
@@ -264,6 +299,47 @@ it('includes authorization header for streaming', (done) => {
264299 } ) ;
265300} ) ;
266301
302+ it ( 'includes wrapper header for streaming' , ( done ) => {
303+ const mockedCreateEventSource = jest . fn ( ) ;
304+ const logger : LDLogger = {
305+ error : jest . fn ( ) ,
306+ warn : jest . fn ( ) ,
307+ info : jest . fn ( ) ,
308+ debug : jest . fn ( ) ,
309+ } ;
310+ ( createPlatform as jest . Mock ) . mockReturnValue ( {
311+ crypto : new PlatformCrypto ( ) ,
312+ info : new PlatformInfo ( logger , { wrapperName : 'Rapper' , wrapperVersion : '1.0.0' } ) ,
313+ requests : {
314+ createEventSource : mockedCreateEventSource ,
315+ fetch : jest . fn ( ) ,
316+ getEventSourceCapabilities : jest . fn ( ) ,
317+ } ,
318+ encoding : new PlatformEncoding ( ) ,
319+ storage : new PlatformStorage ( logger ) ,
320+ } ) ;
321+ const client = new ReactNativeLDClient ( 'mobile-key' , AutoEnvAttributes . Enabled , {
322+ diagnosticOptOut : true ,
323+ sendEvents : false ,
324+ initialConnectionMode : 'streaming' ,
325+ automaticBackgroundHandling : false ,
326+ } ) ;
327+
328+ client
329+ . identify ( { kind : 'user' , key : 'bob' } , { timeout : 0 } )
330+ . then ( ( ) => { } )
331+ . catch ( ( ) => { } )
332+ . then ( ( ) => {
333+ expect ( mockedCreateEventSource ) . toHaveBeenCalledWith (
334+ expect . anything ( ) ,
335+ expect . objectContaining ( {
336+ headers : expect . objectContaining ( { 'x-launchdarkly-wrapper' : 'Rapper/1.0.0' } ) ,
337+ } ) ,
338+ ) ;
339+ done ( ) ;
340+ } ) ;
341+ } ) ;
342+
267343it ( 'includes authorization header for events' , async ( ) => {
268344 const mockedFetch = mockFetch ( '{"flagA": true}' , 200 ) ;
269345 const logger : LDLogger = {
@@ -274,7 +350,7 @@ it('includes authorization header for events', async () => {
274350 } ;
275351 ( createPlatform as jest . Mock ) . mockReturnValue ( {
276352 crypto : new PlatformCrypto ( ) ,
277- info : new PlatformInfo ( logger ) ,
353+ info : new PlatformInfo ( logger , { } ) ,
278354 requests : {
279355 createEventSource : jest . fn ( ) ,
280356 fetch : mockedFetch ,
0 commit comments