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

feat(rc): Add Remote Config Parameter Value Type Support #1424

Merged
merged 4 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions etc/firebase-admin.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,7 @@ export namespace remoteConfig {
nextPageToken?: string;
versions: Version[];
}
export type ParameterValueType = 'STRING' | 'BOOLEAN' | 'NUMBER' | 'JSON';
export interface RemoteConfig {
// (undocumented)
app: app.App;
Expand All @@ -1038,6 +1039,7 @@ export namespace remoteConfig {
};
defaultValue?: RemoteConfigParameterValue;
description?: string;
valueType?: ParameterValueType;
}
export interface RemoteConfigParameterGroup {
description?: string;
Expand Down
12 changes: 12 additions & 0 deletions src/remote-config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ export namespace remoteConfig {
* Unicode characters.
*/
description?: string;

/**
* The data type for all values of this parameter in the current version of the template.
* Defaults to `ParameterValueType.STRING` if unspecified.
*/
valueType?: ParameterValueType;
}

/**
Expand Down Expand Up @@ -259,6 +265,12 @@ export namespace remoteConfig {
export type TagColor = 'BLUE' | 'BROWN' | 'CYAN' | 'DEEP_ORANGE' | 'GREEN' |
'INDIGO' | 'LIME' | 'ORANGE' | 'PINK' | 'PURPLE' | 'TEAL';

/**
* Type representing a Remote Config parameter value data type.
* Defaults to `STRING` if unspecified.
*/
export type ParameterValueType = 'STRING' | 'BOOLEAN' | 'NUMBER' | 'JSON'

/**
* Interface representing a Remote Config template version.
* Output only, except for the version description. Contains metadata about a particular
Expand Down
5 changes: 3 additions & 2 deletions test/unit/remote-config/remote-config-api-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('RemoteConfigApiClient', () => {

const TEST_RESPONSE = {
conditions: [{ name: 'ios', expression: 'exp' }],
parameters: { param: { defaultValue: { value: 'true' } } },
parameters: { param: { defaultValue: { value: 'true' }, valueType: 'BOOLEAN' } },
parameterGroups: { group: { parameters: { paramabc: { defaultValue: { value: 'true' } } }, } },
version: VERSION_INFO,
};
Expand Down Expand Up @@ -132,6 +132,7 @@ describe('RemoteConfigApiClient', () => {
defaultValue: { value: 'true' },
conditionalValues: { ios: { useInAppDefault: true } },
description: 'this is a promo',
valueType: 'BOOLEAN'
},
},
parameterGroups: {
Expand Down Expand Up @@ -429,7 +430,7 @@ describe('RemoteConfigApiClient', () => {
});

VALIDATION_ERROR_MESSAGES.forEach((message) => {
it('should reject with failed-precondition when a validation error occurres', () => {
it('should reject with failed-precondition when a validation error occurs', () => {
const stub = sinon
.stub(HttpClient.prototype, 'send')
.rejects(utils.errorFrom({
Expand Down
7 changes: 6 additions & 1 deletion test/unit/remote-config/remote-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('RemoteConfig', () => {
'android_en': { value: 'A Droid must love a pumpkin spice latte.' },
},
description: 'Description of the parameter.',
valueType: 'STRING' as remoteConfig.ParameterValueType,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this used?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used in REMOTE_CONFIG_RESPONSE in line 98 and also be used in the parameter groups tests (ex: line 506)

},
},
},
Expand Down Expand Up @@ -91,6 +92,7 @@ describe('RemoteConfig', () => {
defaultValue: { value: 'true' },
conditionalValues: { ios: { useInAppDefault: true } },
description: 'this is a promo',
valueType: 'BOOLEAN',
},
},
parameterGroups: PARAMETER_GROUPS,
Expand All @@ -110,6 +112,7 @@ describe('RemoteConfig', () => {
defaultValue: { value: 'true' },
conditionalValues: { ios: { useInAppDefault: true } },
description: 'this is a promo',
valueType: 'BOOLEAN',
},
},
parameterGroups: PARAMETER_GROUPS,
Expand Down Expand Up @@ -383,7 +386,7 @@ describe('RemoteConfig', () => {
});
});

it('should resolve with an empty versions list if the no results are availble for requested list options', () => {
it('should resolve with an empty versions list if no results are available for requested list options', () => {
const stub = sinon
.stub(RemoteConfigApiClient.prototype, 'listVersions')
.resolves({} as any);
Expand Down Expand Up @@ -498,6 +501,7 @@ describe('RemoteConfig', () => {
expect(p1.defaultValue).deep.equals({ value: 'true' });
expect(p1.conditionalValues).deep.equals({ ios: { useInAppDefault: true } });
expect(p1.description).equals('this is a promo');
expect(p1.valueType).equals('BOOLEAN');

expect(newTemplate.parameterGroups).deep.equals(PARAMETER_GROUPS);

Expand Down Expand Up @@ -662,6 +666,7 @@ describe('RemoteConfig', () => {
expect(p1.defaultValue).deep.equals({ value: 'true' });
expect(p1.conditionalValues).deep.equals({ ios: { useInAppDefault: true } });
expect(p1.description).equals('this is a promo');
expect(p1.valueType).equals('BOOLEAN');

expect(template.parameterGroups).deep.equals(PARAMETER_GROUPS);

Expand Down