Skip to content
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
14 changes: 13 additions & 1 deletion src/remote-config/remote-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class RemoteConfigTemplateImpl implements RemoteConfigTemplate {
!validator.isNonEmptyString(config.etag)) {
throw new FirebaseRemoteConfigError(
'invalid-argument',
`Invalid Remote Config template response: ${JSON.stringify(config)}`);
`Invalid Remote Config template: ${JSON.stringify(config)}`);
}

this.etagInternal = config.etag;
Expand Down Expand Up @@ -188,4 +188,16 @@ class RemoteConfigTemplateImpl implements RemoteConfigTemplate {
get etag(): string {
return this.etagInternal;
}

/**
* @return {RemoteConfigTemplate} A JSON-serializable representation of this object.
*/
public toJSON(): RemoteConfigTemplate {
return {
conditions: this.conditions,
parameters: this.parameters,
parameterGroups: this.parameterGroups,
etag: this.etag,
}
}
}
2 changes: 1 addition & 1 deletion test/integration/remote-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ describe('admin.remoteConfig', () => {
const jsonString = JSON.stringify(invalidEtagTemplate);
it(`should throw if the ETag is ${JSON.stringify(invalidEtag)}`, () => {
expect(() => admin.remoteConfig().createTemplateFromJSON(jsonString))
.to.throw(`Invalid Remote Config template response: ${jsonString}`);
.to.throw(`Invalid Remote Config template: ${jsonString}`);
});
});

Expand Down
17 changes: 10 additions & 7 deletions test/unit/remote-config/remote-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ describe('RemoteConfig', () => {
stubs.push(stub);
return remoteConfig.getTemplate()
.should.eventually.be.rejected.and.have.property(
'message', 'Invalid Remote Config template response: null');
'message', 'Invalid Remote Config template: null');
});

it('should reject when API response does not contain an ETag', () => {
Expand All @@ -198,7 +198,7 @@ describe('RemoteConfig', () => {
stubs.push(stub);
return remoteConfig.getTemplate()
.should.eventually.be.rejected.and.have.property(
'message', `Invalid Remote Config template response: ${JSON.stringify(response)}`);
'message', `Invalid Remote Config template: ${JSON.stringify(response)}`);
});

it('should reject when API response does not contain valid parameters', () => {
Expand Down Expand Up @@ -314,6 +314,9 @@ describe('RemoteConfig', () => {
expect(cond.name).to.equal('ios');
expect(cond.expression).to.equal('device.os == \'ios\'');
expect(cond.tagColor).to.equal(TagColor.BLUE);

const parsed = JSON.parse(JSON.stringify(template));
expect(parsed).deep.equals(REMOTE_CONFIG_RESPONSE);
});
});
});
Expand Down Expand Up @@ -344,7 +347,7 @@ describe('RemoteConfig', () => {
stubs.push(stub);
return remoteConfig.validateTemplate(REMOTE_CONFIG_TEMPLATE)
.should.eventually.be.rejected.and.have.property(
'message', 'Invalid Remote Config template response: null');
'message', 'Invalid Remote Config template: null');
});

it('should reject when API response does not contain an ETag', () => {
Expand All @@ -356,7 +359,7 @@ describe('RemoteConfig', () => {
stubs.push(stub);
return remoteConfig.validateTemplate(REMOTE_CONFIG_TEMPLATE)
.should.eventually.be.rejected.and.have.property(
'message', `Invalid Remote Config template response: ${JSON.stringify(response)}`);
'message', `Invalid Remote Config template: ${JSON.stringify(response)}`);
});

it('should reject when API response does not contain valid parameters', () => {
Expand Down Expand Up @@ -497,7 +500,7 @@ describe('RemoteConfig', () => {
stubs.push(stub);
return remoteConfig.publishTemplate(REMOTE_CONFIG_TEMPLATE)
.should.eventually.be.rejected.and.have.property(
'message', 'Invalid Remote Config template response: null');
'message', 'Invalid Remote Config template: null');
});

it('should reject when API response does not contain an ETag', () => {
Expand All @@ -509,7 +512,7 @@ describe('RemoteConfig', () => {
stubs.push(stub);
return remoteConfig.publishTemplate(REMOTE_CONFIG_TEMPLATE)
.should.eventually.be.rejected.and.have.property(
'message', `Invalid Remote Config template response: ${JSON.stringify(response)}`);
'message', `Invalid Remote Config template: ${JSON.stringify(response)}`);
});

it('should reject when API response does not contain valid parameters', () => {
Expand Down Expand Up @@ -657,7 +660,7 @@ describe('RemoteConfig', () => {
const jsonString = JSON.stringify(sourceTemplate);
it(`should throw if the ETag is ${JSON.stringify(invalidEtag)}`, () => {
expect(() => remoteConfig.createTemplateFromJSON(jsonString))
.to.throw(`Invalid Remote Config template response: ${jsonString}`);
.to.throw(`Invalid Remote Config template: ${jsonString}`);
});
});

Expand Down