Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove defaultConfig from public SSRC API #2505

Merged
merged 2 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion etc/firebase-admin.remote-config.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ export type ServerConfig = {
// @public
export interface ServerTemplate {
cache: ServerTemplateData;
defaultConfig: ServerConfig;
evaluate(context?: EvaluationContext): ServerConfig;
load(): Promise<void>;
}
Expand Down
5 changes: 0 additions & 5 deletions src/remote-config/remote-config-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,6 @@ export interface ServerTemplate {
*/
cache: ServerTemplateData;

/**
* A {@link ServerConfig} that contains default Config values.
*/
defaultConfig: ServerConfig;

/**
* Evaluates the current template to produce a {@link ServerConfig}.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/remote-config/remote-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class ServerTemplateImpl implements ServerTemplate {
constructor(
private readonly apiClient: RemoteConfigApiClient,
private readonly conditionEvaluator: ConditionEvaluator,
public readonly defaultConfig: ServerConfig = {}
private readonly defaultConfig: ServerConfig = {}
) { }

/**
Expand Down
82 changes: 53 additions & 29 deletions test/unit/remote-config/remote-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,20 +610,28 @@ describe('RemoteConfig', () => {
});

it('should set defaultConfig when passed', () => {
const defaultConfig = {
holiday_promo_enabled: false,
holiday_promo_discount: 20,
};
// Defines template with no parameters to demonstrate
// default config will be used instead,
const template = deepCopy(SERVER_REMOTE_CONFIG_RESPONSE) as ServerTemplateData;
template.parameters = {};

const stub = sinon
.stub(RemoteConfigApiClient.prototype, operationName)
.resolves(SERVER_REMOTE_CONFIG_RESPONSE as ServerTemplateData);
.resolves(template);
stubs.push(stub);

const defaultConfig = {
holiday_promo_enabled: false,
holiday_promo_discount: 20,
};

return remoteConfig.getServerTemplate({ defaultConfig })
.then((template) => {
expect(template.defaultConfig.holiday_promo_enabled).to.equal(false);
expect(template.defaultConfig.holiday_promo_discount).to.equal(20);
const config = template.evaluate();
expect(config.holiday_promo_enabled).to.equal(
defaultConfig.holiday_promo_enabled);
expect(config.holiday_promo_discount).to.equal(
defaultConfig.holiday_promo_discount);
});
});
});
Expand Down Expand Up @@ -1029,50 +1037,66 @@ describe('RemoteConfig', () => {
});

it('uses local default if parameter not in template', () => {
const template = deepCopy(SERVER_REMOTE_CONFIG_RESPONSE) as ServerTemplateData;
template.parameters = {};

const stub = sinon
.stub(RemoteConfigApiClient.prototype, 'getServerTemplate')
.resolves(SERVER_REMOTE_CONFIG_RESPONSE_2 as ServerTemplateData);
.resolves(template);
stubs.push(stub);
return remoteConfig.getServerTemplate({
defaultConfig: {
dog_coat: 'blue merle',
}
})

const defaultConfig = {
dog_coat: 'blue merle',
};

return remoteConfig.getServerTemplate({ defaultConfig })
.then((template: ServerTemplate) => {
const config = template.evaluate!();
expect(config.dog_coat).to.equal(template.defaultConfig.dog_coat);
const config = template.evaluate();
expect(config.dog_coat).to.equal(defaultConfig.dog_coat);
});
});

it('uses local default when parameter is in template but default value is undefined', () => {
const template = deepCopy(SERVER_REMOTE_CONFIG_RESPONSE) as ServerTemplateData;
template.parameters = {
dog_no_remote_default_value: {}
};

const stub = sinon
.stub(RemoteConfigApiClient.prototype, 'getServerTemplate')
.resolves(SERVER_REMOTE_CONFIG_RESPONSE_2 as ServerTemplateData);
.resolves(template);
stubs.push(stub);
return remoteConfig.getServerTemplate({
defaultConfig: {
dog_no_remote_default_value: 'local default'
}
})

const defaultConfig = {
dog_no_remote_default_value: 'local default'
};

return remoteConfig.getServerTemplate({ defaultConfig })
.then((template: ServerTemplate) => {
const config = template.evaluate!();
expect(config.dog_no_remote_default_value).to.equal(template.defaultConfig.dog_no_remote_default_value);
expect(config.dog_no_remote_default_value).to.equal(defaultConfig.dog_no_remote_default_value);
});
});

it('uses local default when in-app default value specified', () => {
const template = deepCopy(SERVER_REMOTE_CONFIG_RESPONSE) as ServerTemplateData;
template.parameters = {
dog_no_remote_default_value: {}
};

const stub = sinon
.stub(RemoteConfigApiClient.prototype, 'getServerTemplate')
.resolves(SERVER_REMOTE_CONFIG_RESPONSE_2 as ServerTemplateData);
.resolves(template);
stubs.push(stub);
return remoteConfig.getServerTemplate({
defaultConfig: {
dog_use_inapp_default: '🐕'
}
})

const defaultConfig = {
dog_use_inapp_default: '🐕'
};

return remoteConfig.getServerTemplate({ defaultConfig })
.then((template: ServerTemplate) => {
const config = template.evaluate!();
expect(config.dog_use_inapp_default).to.equal(template.defaultConfig.dog_use_inapp_default);
expect(config.dog_use_inapp_default).to.equal(defaultConfig.dog_use_inapp_default);
});
});

Expand Down