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

Refactor unit tests for Remote Config #884

Merged
merged 2 commits into from
May 11, 2020
Merged

Conversation

lahirumaramba
Copy link
Member

Our unit tests for RC are quite repetitive. As we are adding more features to the RC API, it is time to clean up the code a bit.

  • Add reusable functions for repetitive tests.
  • Move input validation tests from remote-config.spec.ts to remote-config-api-client.spec.ts as that is where the validation really takes place.

Copy link
Contributor

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

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

Thanks for putting this together. Looks pretty good. Just a few nits to think about.

@@ -240,6 +191,14 @@ describe('RemoteConfigApiClient', () => {
.should.eventually.be.rejectedWith(noProjectId);
});

// tests for input template validations
testInvalidInputTemplates((t: RemoteConfigTemplate) => { apiClient.validateTemplate(t); });
Copy link
Contributor

Choose a reason for hiding this comment

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

Type annotation not needed here. Let the compiler infer the type whenever possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

The compiler complains if I don't annotate the type here. I could remove the return types though.

remote-config-api-client.spec.ts (193,32): Parameter 't' implicitly has an 'any' type. (7006)

testInvalidInputTemplates((t: RemoteConfigTemplate) => { apiClient.validateTemplate(t); });

// tests for api response validations
runApiResponseValidationTests((): Promise<RemoteConfigTemplate> => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Here too. Just () => apiClient.validateTemplate(...)

});
});

function runApiResponseValidationTests(rcOperation: () => Promise<RemoteConfigTemplate>): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

Most of this is checking for various error responses. So may be runErrorResponseTests() is more appropriate? Your call.

});
}

function runTemplateVersionNumberTests(rcOperation: Function): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't see why this needs to be a function. If you're planning for future reuse, I'd rather refactor this into a function at that point.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I am planing to use in the next PR. I will introduce the function at that point then :)

'message', `Remote Config conditions must be an array`);
const invalidEtags = [...INVALID_STRINGS];
let sourceTemplate = deepCopy(REMOTE_CONFIG_RESPONSE);
invalidEtags.forEach((invalidEtag) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

INVALID_STRINGS.forEach(...

.resolves(response);
stubs.push(stub);
return remoteConfig.publishTemplate(REMOTE_CONFIG_TEMPLATE)
return rcOperation()
.should.eventually.be.rejected.and.have.property(
'message', `Remote Config conditions must be an array`);
});

it('should resolve with parameters:{} when no parameters present in the response', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This and the subsequent resolves tests should not be in the runApiResponseValidationTests IMO. May be put them in a separate function?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. Moved to a new function runValidResponseTests. Renamed runApiResponseValidationTests to runInvalidResponseTests.

Copy link
Contributor

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

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

Thanks. LGTM 👍

@lahirumaramba lahirumaramba merged commit 773add8 into remote-config-vc May 11, 2020
@lahirumaramba lahirumaramba deleted the lm-rc-rollback branch May 11, 2020 18:36
lahirumaramba added a commit that referenced this pull request Jun 25, 2020
* Get remote config template by version number (#874)

* Get remote config template by version number

* Refactor unit tests for Remote Config (#884)

* Refactor unit tests

* Add Remote Config Rollback operation (#885)

* Add Remote Config Rollback operation

* Update docs and move etag validation to a helper function

* Update docs

* Introduce a util to create a template from API response

* PR fixes

* Remote Config Add list versions operation (#896)

* Remote Config: Add list versions operation

* Add version Impl and other PR fixes

* PR fixes

* Imrpoved unit tests and some code clean up

* Fix code formatting

* Add a separate function to get a Template with version (#902)

* Add version meta data to RC templates (#906)

* Add version meta data to RC templates

* PR fixes

* Use assertion to unwrap template.version

* Update Remote Config Docstrings in index.d.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants