@@ -27,6 +27,18 @@ describe('Stream', () => {
2727 baseHeaders = getLDHeaders ( platform , defaultConfig ) ;
2828 } ) ;
2929
30+ function makeExpectedStreamUrl ( base64User , userHash , withReasons ) {
31+ const url = baseUrl + '/eval/' + envName + '/' + base64User ;
32+ const queryParams = [ ] ;
33+ if ( userHash ) {
34+ queryParams . push ( 'h=' + userHash ) ;
35+ }
36+ if ( withReasons ) {
37+ queryParams . push ( '?withReasons=true' ) ;
38+ }
39+ return url + ( queryParams . length ? '?' + queryParams . join ( '&' ) : '' ) ;
40+ }
41+
3042 it ( 'should not throw on EventSource when it does not exist' , ( ) => {
3143 const platform1 = { ...platform } ;
3244 delete platform1 [ 'eventSourceFactory' ] ;
@@ -51,22 +63,22 @@ describe('Stream', () => {
5163
5264 it ( 'connects to EventSource with eval stream URL by default' , async ( ) => {
5365 const stream = new Stream ( platform , defaultConfig , envName ) ;
54- stream . connect ( user , { } ) ;
66+ stream . connect ( user , null , { } ) ;
5567
56- await platform . testing . expectStream ( baseUrl + '/eval/' + envName + '/' + encodedUser ) ;
68+ await platform . testing . expectStream ( makeExpectedStreamUrl ( encodedUser ) ) ;
5769 } ) ;
5870
5971 it ( 'adds secure mode hash to URL if provided' , async ( ) => {
60- const stream = new Stream ( platform , defaultConfig , envName , null , hash ) ;
61- stream . connect ( user , { } ) ;
72+ const stream = new Stream ( platform , defaultConfig , envName ) ;
73+ stream . connect ( user , hash , { } ) ;
6274
63- await platform . testing . expectStream ( baseUrl + '/eval/' + envName + '/' + encodedUser + '?h=' + hash ) ;
75+ await platform . testing . expectStream ( makeExpectedStreamUrl ( encodedUser , hash ) ) ;
6476 } ) ;
6577
6678 it ( 'falls back to ping stream URL if useReport is true and REPORT is not supported' , async ( ) => {
6779 const config = { ...defaultConfig , useReport : true } ;
6880 const stream = new Stream ( platform , config , envName ) ;
69- stream . connect ( user , { } ) ;
81+ stream . connect ( user , null , { } ) ;
7082
7183 await platform . testing . expectStream ( baseUrl + '/ping/' + envName ) ;
7284 } ) ;
@@ -75,7 +87,7 @@ describe('Stream', () => {
7587 const platform1 = { ...platform , eventSourceAllowsReport : true } ;
7688 const config = { ...defaultConfig , useReport : true } ;
7789 const stream = new Stream ( platform1 , config , envName ) ;
78- stream . connect ( user , { } ) ;
90+ stream . connect ( user , null , { } ) ;
7991
8092 const created = await platform . testing . expectStream ( baseUrl + '/eval/' + envName ) ;
8193 expect ( created . options . method ) . toEqual ( 'REPORT' ) ;
@@ -84,27 +96,27 @@ describe('Stream', () => {
8496
8597 it ( 'sends default SDK headers' , async ( ) => {
8698 const stream = new Stream ( platform , defaultConfig , envName ) ;
87- stream . connect ( user , { } ) ;
99+ stream . connect ( user , null , { } ) ;
88100
89- const created = await platform . testing . expectStream ( baseUrl + '/eval/' + envName + '/' + encodedUser ) ;
101+ const created = await platform . testing . expectStream ( makeExpectedStreamUrl ( encodedUser ) ) ;
90102 expect ( created . options . headers ) . toEqual ( baseHeaders ) ;
91103 } ) ;
92104
93105 it ( 'sends SDK headers with wrapper info' , async ( ) => {
94106 const config = { ...defaultConfig , wrapperName : 'FakeSDK' } ;
95107 const stream = new Stream ( platform , config , envName ) ;
96- stream . connect ( user , { } ) ;
108+ stream . connect ( user , null , { } ) ;
97109
98- const created = await platform . testing . expectStream ( baseUrl + '/eval/' + envName + '/' + encodedUser ) ;
110+ const created = await platform . testing . expectStream ( makeExpectedStreamUrl ( encodedUser ) ) ;
99111 expect ( created . options . headers ) . toEqual ( { ...baseHeaders , 'X-LaunchDarkly-Wrapper' : 'FakeSDK' } ) ;
100112 } ) ;
101113
102114 it ( 'does not send SDK headers when sendLDHeaders is false' , async ( ) => {
103115 const config = { ...defaultConfig , sendLDHeaders : false } ;
104116 const stream = new Stream ( platform , config , envName ) ;
105- stream . connect ( user , { } ) ;
117+ stream . connect ( user , null , { } ) ;
106118
107- const created = await platform . testing . expectStream ( baseUrl + '/eval/' + envName + '/' + encodedUser ) ;
119+ const created = await platform . testing . expectStream ( makeExpectedStreamUrl ( encodedUser ) ) ;
108120 expect ( created . options . headers ) . toEqual ( { } ) ;
109121 } ) ;
110122
@@ -113,7 +125,7 @@ describe('Stream', () => {
113125 const fn1 = jest . fn ( ) ;
114126 const fn2 = jest . fn ( ) ;
115127
116- stream . connect ( user , {
128+ stream . connect ( user , null , {
117129 birthday : fn1 ,
118130 anniversary : fn2 ,
119131 } ) ;
@@ -184,7 +196,7 @@ describe('Stream', () => {
184196 const config = { ...defaultConfig , streamReconnectDelay : 1 } ;
185197 const stream = new Stream ( platform , config , envName ) ;
186198 const fakePut = jest . fn ( ) ;
187- stream . connect ( user , {
199+ stream . connect ( user , null , {
188200 put : fakePut ,
189201 } ) ;
190202
@@ -227,7 +239,7 @@ describe('Stream', () => {
227239
228240 expect ( acc . getProps ( ) . streamInits . length ) . toEqual ( 0 ) ;
229241
230- stream . connect ( user , {
242+ stream . connect ( user , null , {
231243 put : jest . fn ( ) ,
232244 } ) ;
233245
@@ -255,7 +267,7 @@ describe('Stream', () => {
255267
256268 expect ( acc . getProps ( ) . streamInits . length ) . toEqual ( 0 ) ;
257269
258- stream . connect ( user , {
270+ stream . connect ( user , null , {
259271 put : jest . fn ( ) ,
260272 } ) ;
261273
0 commit comments