@@ -610,20 +610,28 @@ describe('RemoteConfig', () => {
610
610
} ) ;
611
611
612
612
it ( 'should set defaultConfig when passed' , ( ) => {
613
- const defaultConfig = {
614
- holiday_promo_enabled : false ,
615
- holiday_promo_discount : 20 ,
616
- } ;
613
+ // Defines template with no parameters to demonstrate
614
+ // default config will be used instead ,
615
+ const template = deepCopy ( SERVER_REMOTE_CONFIG_RESPONSE ) as ServerTemplateData ;
616
+ template . parameters = { } ;
617
617
618
618
const stub = sinon
619
619
. stub ( RemoteConfigApiClient . prototype , operationName )
620
- . resolves ( SERVER_REMOTE_CONFIG_RESPONSE as ServerTemplateData ) ;
620
+ . resolves ( template ) ;
621
621
stubs . push ( stub ) ;
622
622
623
+ const defaultConfig = {
624
+ holiday_promo_enabled : false ,
625
+ holiday_promo_discount : 20 ,
626
+ } ;
627
+
623
628
return remoteConfig . getServerTemplate ( { defaultConfig } )
624
629
. then ( ( template ) => {
625
- expect ( template . defaultConfig . holiday_promo_enabled ) . to . equal ( false ) ;
626
- expect ( template . defaultConfig . holiday_promo_discount ) . to . equal ( 20 ) ;
630
+ const config = template . evaluate ( ) ;
631
+ expect ( config . holiday_promo_enabled ) . to . equal (
632
+ defaultConfig . holiday_promo_enabled ) ;
633
+ expect ( config . holiday_promo_discount ) . to . equal (
634
+ defaultConfig . holiday_promo_discount ) ;
627
635
} ) ;
628
636
} ) ;
629
637
} ) ;
@@ -1029,50 +1037,66 @@ describe('RemoteConfig', () => {
1029
1037
} ) ;
1030
1038
1031
1039
it ( 'uses local default if parameter not in template' , ( ) => {
1040
+ const template = deepCopy ( SERVER_REMOTE_CONFIG_RESPONSE ) as ServerTemplateData ;
1041
+ template . parameters = { } ;
1042
+
1032
1043
const stub = sinon
1033
1044
. stub ( RemoteConfigApiClient . prototype , 'getServerTemplate' )
1034
- . resolves ( SERVER_REMOTE_CONFIG_RESPONSE_2 as ServerTemplateData ) ;
1045
+ . resolves ( template ) ;
1035
1046
stubs . push ( stub ) ;
1036
- return remoteConfig . getServerTemplate ( {
1037
- defaultConfig : {
1038
- dog_coat : 'blue merle' ,
1039
- }
1040
- } )
1047
+
1048
+ const defaultConfig = {
1049
+ dog_coat : 'blue merle' ,
1050
+ } ;
1051
+
1052
+ return remoteConfig . getServerTemplate ( { defaultConfig } )
1041
1053
. then ( ( template : ServerTemplate ) => {
1042
- const config = template . evaluate ! ( ) ;
1043
- expect ( config . dog_coat ) . to . equal ( template . defaultConfig . dog_coat ) ;
1054
+ const config = template . evaluate ( ) ;
1055
+ expect ( config . dog_coat ) . to . equal ( defaultConfig . dog_coat ) ;
1044
1056
} ) ;
1045
1057
} ) ;
1046
1058
1047
1059
it ( 'uses local default when parameter is in template but default value is undefined' , ( ) => {
1060
+ const template = deepCopy ( SERVER_REMOTE_CONFIG_RESPONSE ) as ServerTemplateData ;
1061
+ template . parameters = {
1062
+ dog_no_remote_default_value : { }
1063
+ } ;
1064
+
1048
1065
const stub = sinon
1049
1066
. stub ( RemoteConfigApiClient . prototype , 'getServerTemplate' )
1050
- . resolves ( SERVER_REMOTE_CONFIG_RESPONSE_2 as ServerTemplateData ) ;
1067
+ . resolves ( template ) ;
1051
1068
stubs . push ( stub ) ;
1052
- return remoteConfig . getServerTemplate ( {
1053
- defaultConfig : {
1054
- dog_no_remote_default_value : 'local default'
1055
- }
1056
- } )
1069
+
1070
+ const defaultConfig = {
1071
+ dog_no_remote_default_value : 'local default'
1072
+ } ;
1073
+
1074
+ return remoteConfig . getServerTemplate ( { defaultConfig } )
1057
1075
. then ( ( template : ServerTemplate ) => {
1058
1076
const config = template . evaluate ! ( ) ;
1059
- expect ( config . dog_no_remote_default_value ) . to . equal ( template . defaultConfig . dog_no_remote_default_value ) ;
1077
+ expect ( config . dog_no_remote_default_value ) . to . equal ( defaultConfig . dog_no_remote_default_value ) ;
1060
1078
} ) ;
1061
1079
} ) ;
1062
1080
1063
1081
it ( 'uses local default when in-app default value specified' , ( ) => {
1082
+ const template = deepCopy ( SERVER_REMOTE_CONFIG_RESPONSE ) as ServerTemplateData ;
1083
+ template . parameters = {
1084
+ dog_no_remote_default_value : { }
1085
+ } ;
1086
+
1064
1087
const stub = sinon
1065
1088
. stub ( RemoteConfigApiClient . prototype , 'getServerTemplate' )
1066
- . resolves ( SERVER_REMOTE_CONFIG_RESPONSE_2 as ServerTemplateData ) ;
1089
+ . resolves ( template ) ;
1067
1090
stubs . push ( stub ) ;
1068
- return remoteConfig . getServerTemplate ( {
1069
- defaultConfig : {
1070
- dog_use_inapp_default : '🐕'
1071
- }
1072
- } )
1091
+
1092
+ const defaultConfig = {
1093
+ dog_use_inapp_default : '🐕'
1094
+ } ;
1095
+
1096
+ return remoteConfig . getServerTemplate ( { defaultConfig } )
1073
1097
. then ( ( template : ServerTemplate ) => {
1074
1098
const config = template . evaluate ! ( ) ;
1075
- expect ( config . dog_use_inapp_default ) . to . equal ( template . defaultConfig . dog_use_inapp_default ) ;
1099
+ expect ( config . dog_use_inapp_default ) . to . equal ( defaultConfig . dog_use_inapp_default ) ;
1076
1100
} ) ;
1077
1101
} ) ;
1078
1102
0 commit comments