Skip to content

Add integration tests for RC manage version operations #914

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

Merged
merged 3 commits into from
Jun 26, 2020
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
4 changes: 4 additions & 0 deletions src/remote-config/remote-config-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,10 @@ export class RemoteConfigApiClient {
optionsCopy.endTime = new Date(optionsCopy.endTime).toISOString();
}
}
// Remove undefined fields from optionsCopy
Object.keys(optionsCopy).forEach(key =>
(typeof (optionsCopy as any)[key] === 'undefined') && delete (optionsCopy as any)[key]
);
return optionsCopy;
}
}
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 @@ -145,7 +145,7 @@ export class RemoteConfig implements FirebaseServiceInterface {
return this.client.listVersions(options)
.then((listVersionsResponse) => {
return {
versions: listVersionsResponse.versions.map(version => new VersionImpl(version)),
versions: listVersionsResponse.versions?.map(version => new VersionImpl(version)) ?? [],
nextPageToken: listVersionsResponse.nextPageToken,
}
});
Expand Down
109 changes: 97 additions & 12 deletions test/integration/remote-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const VALID_PARAMETERS = {
},
// eslint-disable-next-line @typescript-eslint/camelcase
welcome_message: {
defaultValue: { value: 'welcome text' + Date.now() },
defaultValue: { value: `welcome text ${Date.now()}` },
conditionalValues: {
ios: { value: 'welcome ios text' },
android: { value: 'welcome android text' },
Expand All @@ -57,16 +57,22 @@ const VALID_PARAMETER_GROUPS = {
},
};

const VALID_CONDITIONS: admin.remoteConfig.RemoteConfigCondition[] = [{
name: 'ios',
expression: 'device.os == \'ios\'',
tagColor: 'INDIGO',
},
{
name: 'android',
expression: 'device.os == \'android\'',
tagColor: 'GREEN',
}];
const VALID_CONDITIONS: admin.remoteConfig.RemoteConfigCondition[] = [
{
name: 'ios',
expression: 'device.os == \'ios\'',
tagColor: 'INDIGO',
},
{
name: 'android',
expression: 'device.os == \'android\'',
tagColor: 'GREEN',
},
];

const VALID_VERSION = {
description: `template description ${Date.now()}`,
}

let currentTemplate: admin.remoteConfig.RemoteConfigTemplate;

Expand All @@ -88,13 +94,16 @@ describe('admin.remoteConfig', () => {
currentTemplate.conditions = VALID_CONDITIONS;
currentTemplate.parameters = VALID_PARAMETERS;
currentTemplate.parameterGroups = VALID_PARAMETER_GROUPS;
currentTemplate.version = VALID_VERSION;
return admin.remoteConfig().validateTemplate(currentTemplate)
.then((template) => {
expect(template.etag).matches(/^etag-[0-9]*-[0-9]*$/);
expect(template.conditions.length).to.equal(2);
expect(template.conditions).to.deep.equal(VALID_CONDITIONS);
expect(template.parameters).to.deep.equal(VALID_PARAMETERS);
expect(template.parameterGroups).to.deep.equal(VALID_PARAMETER_GROUPS);
expect(template.version).to.be.not.undefined;
expect(template.version!.description).equals(VALID_VERSION.description);
});
});

Expand All @@ -103,6 +112,7 @@ describe('admin.remoteConfig', () => {
currentTemplate.conditions = [];
currentTemplate.parameters = VALID_PARAMETERS;
currentTemplate.parameterGroups = VALID_PARAMETER_GROUPS;
currentTemplate.version = VALID_VERSION;
return admin.remoteConfig().validateTemplate(currentTemplate)
.should.eventually.be.rejected.and.have.property('code', 'remote-config/invalid-argument');
});
Expand All @@ -114,13 +124,16 @@ describe('admin.remoteConfig', () => {
currentTemplate.conditions = VALID_CONDITIONS;
currentTemplate.parameters = VALID_PARAMETERS;
currentTemplate.parameterGroups = VALID_PARAMETER_GROUPS;
currentTemplate.version = VALID_VERSION;
return admin.remoteConfig().publishTemplate(currentTemplate)
.then((template) => {
expect(template.etag).matches(/^etag-[0-9]*-[0-9]*$/);
expect(template.conditions.length).to.equal(2);
expect(template.conditions).to.deep.equal(VALID_CONDITIONS);
expect(template.parameters).to.deep.equal(VALID_PARAMETERS);
expect(template.parameterGroups).to.deep.equal(VALID_PARAMETER_GROUPS);
expect(template.version).to.be.not.undefined;
expect(template.version!.description).equals(VALID_VERSION.description);
});
});

Expand All @@ -129,20 +142,92 @@ describe('admin.remoteConfig', () => {
currentTemplate.conditions = [];
currentTemplate.parameters = VALID_PARAMETERS;
currentTemplate.parameterGroups = VALID_PARAMETER_GROUPS;
currentTemplate.version = VALID_VERSION;
return admin.remoteConfig().publishTemplate(currentTemplate)
.should.eventually.be.rejected.and.have.property('code', 'remote-config/invalid-argument');
});
});

describe('getTemplate', () => {
it('verfy that getTemplate() returns the most recently published template', () => {
it('should return the most recently published template', () => {
return admin.remoteConfig().getTemplate()
.then((template) => {
expect(template.etag).matches(/^etag-[0-9]*-[0-9]*$/);
expect(template.conditions.length).to.equal(2);
expect(template.conditions).to.deep.equal(VALID_CONDITIONS);
expect(template.parameters).to.deep.equal(VALID_PARAMETERS);
expect(template.parameterGroups).to.deep.equal(VALID_PARAMETER_GROUPS);
expect(template.version).to.be.not.undefined;
expect(template.version!.description).equals(VALID_VERSION.description);
});
});
});

let versionOneNumber: string;
let versionTwoNumber: string;
const versionOneDescription = `getTemplateAtVersion test v1 ${Date.now()}`;
const versionTwoDescription = `getTemplateAtVersion test v2 ${Date.now()}`;

describe('getTemplateAtVersion', () => {
before(async () => {
// obtain the current active template
let activeTemplate = await admin.remoteConfig().getTemplate();

// publish a new template to create a new version number
activeTemplate.version = { description: versionOneDescription };
activeTemplate = await admin.remoteConfig().publishTemplate(activeTemplate)
expect(activeTemplate.version).to.be.not.undefined;
versionOneNumber = activeTemplate.version!.versionNumber!;

// publish another template to create a second version number
activeTemplate.version = { description: versionTwoDescription };
activeTemplate = await admin.remoteConfig().publishTemplate(activeTemplate)
expect(activeTemplate.version).to.be.not.undefined;
versionTwoNumber = activeTemplate.version!.versionNumber!;
});

it('should return the requested template version v1', () => {
return admin.remoteConfig().getTemplateAtVersion(versionOneNumber)
.then((template) => {
expect(template.etag).matches(/^etag-[0-9]*-[0-9]*$/);
expect(template.version).to.be.not.undefined;
expect(template.version!.versionNumber).equals(versionOneNumber);
expect(template.version!.description).equals(versionOneDescription);
});
});
});

describe('listVersions', () => {
it('should return the most recently published 2 versions', () => {
return admin.remoteConfig().listVersions({
pageSize: 2,
})
.then((response) => {
expect(response.versions.length).to.equal(2);
// versions should be in reverse chronological order
expect(response.versions[0].description).equals(versionTwoDescription);
expect(response.versions[0].versionNumber).equals(versionTwoNumber);
expect(response.versions[1].description).equals(versionOneDescription);
expect(response.versions[1].versionNumber).equals(versionOneNumber);
});
});
});

describe('rollback', () => {
it('verify the most recent template version before rollback to the one prior', () => {
return admin.remoteConfig().getTemplate()
.then((template) => {
expect(template.version).to.be.not.undefined;
expect(template.version!.versionNumber).equals(versionTwoNumber);
});
});

it('should rollback to the requested version', () => {
return admin.remoteConfig().rollback(versionOneNumber)
.then((template) => {
expect(template.version).to.be.not.undefined;
expect(template.version!.updateType).equals('ROLLBACK');
expect(template.version!.description).equals(`Rollback to version ${versionOneNumber}`);
});
});
});
Expand Down
22 changes: 22 additions & 0 deletions test/unit/remote-config/remote-config-api-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,28 @@ describe('RemoteConfigApiClient', () => {
});
});

it('should remove undefined fields from options', () => {
const stub = sinon
.stub(HttpClient.prototype, 'send')
.resolves(utils.responseFrom(TEST_VERSIONS_RESULT, 200));
stubs.push(stub);
return apiClient.listVersions({
pageSize: undefined,
pageToken: undefined,
endVersionNumber: 70,
})
.then(() => {
expect(stub).to.have.been.calledOnce.and.calledWith({
method: 'GET',
url: 'https://firebaseremoteconfig.googleapis.com/v1/projects/test-project/remoteConfig:listVersions',
headers: EXPECTED_HEADERS,
data: {
endVersionNumber: '70'
}
});
});
});

it('should resolve with a list of template versions on success', () => {
const startTime = new Date(2020, 4, 2);
const endTime = 'Thu, 07 May 2020 18:44:41 GMT';
Expand Down
16 changes: 16 additions & 0 deletions test/unit/remote-config/remote-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,21 @@ describe('RemoteConfig', () => {
});
});

it('should resolve with an empty versions list if the no results are availble for requested list options', () => {
const stub = sinon
.stub(RemoteConfigApiClient.prototype, 'listVersions')
.resolves({});
stubs.push(stub);
return remoteConfig.listVersions({
pageSize: 2,
endVersionNumber: 10,
})
.then((response) => {
expect(response.versions.length).to.equal(0);
expect(response.nextPageToken).to.be.undefined;
});
});

it('should resolve with template versions list on success', () => {
const stub = sinon
.stub(RemoteConfigApiClient.prototype, 'listVersions')
Expand All @@ -378,6 +393,7 @@ describe('RemoteConfig', () => {
expect(response.versions.length).to.equal(2);
expect(response.versions[0].updateTime).equals('Thu, 07 May 2020 18:46:09 GMT');
expect(response.versions[1].updateTime).equals('Thu, 07 May 2020 18:44:41 GMT');
expect(response.nextPageToken).to.equal('76');
});
});
});
Expand Down