Skip to content

Commit ef4b2df

Browse files
authored
Remove defaultConfig from public SSRC API (#2505)
In practice, we only set default config using the initialization methods, so make the internal field private to simplify the API.
1 parent 02c0559 commit ef4b2df

File tree

4 files changed

+54
-36
lines changed

4 files changed

+54
-36
lines changed

etc/firebase-admin.remote-config.api.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ export type ServerConfig = {
166166
// @public
167167
export interface ServerTemplate {
168168
cache: ServerTemplateData;
169-
defaultConfig: ServerConfig;
170169
evaluate(context?: EvaluationContext): ServerConfig;
171170
load(): Promise<void>;
172171
}

src/remote-config/remote-config-api.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,6 @@ export interface ServerTemplate {
382382
*/
383383
cache: ServerTemplateData;
384384

385-
/**
386-
* A {@link ServerConfig} that contains default Config values.
387-
*/
388-
defaultConfig: ServerConfig;
389-
390385
/**
391386
* Evaluates the current template to produce a {@link ServerConfig}.
392387
*/

src/remote-config/remote-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ class ServerTemplateImpl implements ServerTemplate {
296296
constructor(
297297
private readonly apiClient: RemoteConfigApiClient,
298298
private readonly conditionEvaluator: ConditionEvaluator,
299-
public readonly defaultConfig: ServerConfig = {}
299+
private readonly defaultConfig: ServerConfig = {}
300300
) { }
301301

302302
/**

test/unit/remote-config/remote-config.spec.ts

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -610,20 +610,28 @@ describe('RemoteConfig', () => {
610610
});
611611

612612
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 = {};
617617

618618
const stub = sinon
619619
.stub(RemoteConfigApiClient.prototype, operationName)
620-
.resolves(SERVER_REMOTE_CONFIG_RESPONSE as ServerTemplateData);
620+
.resolves(template);
621621
stubs.push(stub);
622622

623+
const defaultConfig = {
624+
holiday_promo_enabled: false,
625+
holiday_promo_discount: 20,
626+
};
627+
623628
return remoteConfig.getServerTemplate({ defaultConfig })
624629
.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);
627635
});
628636
});
629637
});
@@ -1029,50 +1037,66 @@ describe('RemoteConfig', () => {
10291037
});
10301038

10311039
it('uses local default if parameter not in template', () => {
1040+
const template = deepCopy(SERVER_REMOTE_CONFIG_RESPONSE) as ServerTemplateData;
1041+
template.parameters = {};
1042+
10321043
const stub = sinon
10331044
.stub(RemoteConfigApiClient.prototype, 'getServerTemplate')
1034-
.resolves(SERVER_REMOTE_CONFIG_RESPONSE_2 as ServerTemplateData);
1045+
.resolves(template);
10351046
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 })
10411053
.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);
10441056
});
10451057
});
10461058

10471059
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+
10481065
const stub = sinon
10491066
.stub(RemoteConfigApiClient.prototype, 'getServerTemplate')
1050-
.resolves(SERVER_REMOTE_CONFIG_RESPONSE_2 as ServerTemplateData);
1067+
.resolves(template);
10511068
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 })
10571075
.then((template: ServerTemplate) => {
10581076
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);
10601078
});
10611079
});
10621080

10631081
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+
10641087
const stub = sinon
10651088
.stub(RemoteConfigApiClient.prototype, 'getServerTemplate')
1066-
.resolves(SERVER_REMOTE_CONFIG_RESPONSE_2 as ServerTemplateData);
1089+
.resolves(template);
10671090
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 })
10731097
.then((template: ServerTemplate) => {
10741098
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);
10761100
});
10771101
});
10781102

0 commit comments

Comments
 (0)