@@ -54,7 +54,12 @@ class ExperimentClientTest {
5454 private var mockStorage = MockStorage ()
5555 private val testUser = ExperimentUser (userId = " test_user" )
5656
57- private val serverVariant = Variant (key = " on" , value = " on" , payload = " payload" , metadata = mapOf (" evaluationId" to " " ))
57+ private val serverVariant = Variant (
58+ key = " on" ,
59+ value = " on" ,
60+ payload = " payload" ,
61+ metadata = mapOf (" evaluationId" to " " )
62+ )
5863 private val fallbackVariant = Variant (key = " fallback" , value = " fallback" )
5964 private val initialVariant = Variant (key = " initial" , value = " initial" )
6065 private val inlineVariant = Variant (key = " inline" , value = " inline" )
@@ -452,7 +457,12 @@ class ExperimentClientTest {
452457 debug = true ,
453458 exposureTrackingProvider = exposureTrackingProvider,
454459 source = Source .INITIAL_VARIANTS ,
455- initialVariants = mapOf (" flagKey" to Variant (key = " variant" , expKey = " experimentKey" )),
460+ initialVariants = mapOf (
461+ " flagKey" to Variant (
462+ key = " variant" ,
463+ expKey = " experimentKey"
464+ )
465+ ),
456466 ),
457467 OkHttpClient (),
458468 mockStorage,
@@ -1357,13 +1367,15 @@ class ExperimentClientTest {
13571367 }
13581368
13591369 @Test
1360- fun `test config custom request headers added, http call includes headers` () {
1370+ fun `test config custom request headers added, http call on fetch includes headers` () {
13611371 val mockHttpClient = mockk<OkHttpClient >()
1372+ val testServerUrlHost = " api.test-server-url.com"
13621373 val testCountry = " South Africa"
13631374 val client =
13641375 DefaultExperimentClient (
13651376 API_KEY ,
13661377 ExperimentConfig (
1378+ serverUrl = " https://$testServerUrlHost " ,
13671379 customRequestHeaders = { user ->
13681380 mapOf (" country" to user.country!! )
13691381 }
@@ -1375,9 +1387,39 @@ class ExperimentClientTest {
13751387
13761388 client.fetch(ExperimentUser (country = testCountry))
13771389
1378- verify {
1390+ verify(exactly = 1 ) {
1391+ mockHttpClient.newCall(match {
1392+ it.url.host == testServerUrlHost &&
1393+ it.headers[" country" ] == testCountry
1394+ })
1395+ }
1396+ }
1397+
1398+ @Test
1399+ fun `test config custom request headers added, http call on start for flags for flags includes headers` () {
1400+ val mockHttpClient = mockk<OkHttpClient >()
1401+ val testFlagsHost = " api.test-flags-server-url.com"
1402+ val testCountry = " South Africa"
1403+ val client =
1404+ DefaultExperimentClient (
1405+ API_KEY ,
1406+ ExperimentConfig (
1407+ flagsServerUrl = " https://$testFlagsHost " ,
1408+ customRequestHeaders = { user ->
1409+ mapOf (" country" to user.country!! )
1410+ }
1411+ ),
1412+ mockHttpClient,
1413+ mockStorage,
1414+ Experiment .executorService,
1415+ )
1416+
1417+ client.start(ExperimentUser (country = testCountry))
1418+
1419+ verify(exactly = 1 ) {
13791420 mockHttpClient.newCall(match {
1380- it.headers[" country" ] == testCountry
1421+ it.url.host == testFlagsHost &&
1422+ it.headers[" country" ] == testCountry
13811423 })
13821424 }
13831425 }
0 commit comments