All new code requires tests to ensure against regressions.
However, if your PR contains zero code changes, feel free to select the checkmark below to indicate so.
[X] Have you ran tests against this code?
[ ] This PR contains zero code changes.
Description of the Change
One factor holding back the, very much needed, total testing refactor, is that while all backend API calls have been moved into a singular function, chaining any type of complex requests can get complex, and become unwieldy to work with.
Since many of the integration functions that need to be properly tested can end up themselves making multiples of tests, and we need to have proper control over every return that may occur within that API return chain, there is no pretty way of creating all of these Mock API responses.
So to at least make them much more wieldy, and avoid duplicating code, this PR introduces a new testing module httpMock.helper.jest.js which exports a few functions and classes to assist with mocking API returns.
The most important the HTTP class, uses an object builder pattern to craft an object, that once parsed, mimics the API return that would be provided from an API call.
This in conjunction with the reused webRequestMock of the vcs test module, lets us provide an array of the parsed objects returned by HTTP and use them based on path as responses to API calls, to properly Mock any API return within a given chain.
Lastly, a global hashMap is used to retain every generated mock, so that it can be reused within a single files tests, to reduce duplication.
Requirements
Filling out the template is required.
All new code requires tests to ensure against regressions.
[X] Have you ran tests against this code?
[ ] This PR contains zero code changes.
Description of the Change
One factor holding back the, very much needed, total testing refactor, is that while all backend API calls have been moved into a singular function, chaining any type of complex requests can get complex, and become unwieldy to work with.
Since many of the integration functions that need to be properly tested can end up themselves making multiples of tests, and we need to have proper control over every return that may occur within that API return chain, there is no pretty way of creating all of these Mock API responses.
So to at least make them much more wieldy, and avoid duplicating code, this PR introduces a new testing module
httpMock.helper.jest.js
which exports a few functions and classes to assist with mocking API returns.The most important the
HTTP
class, uses an object builder pattern to craft an object, that once parsed, mimics the API return that would be provided from an API call.This in conjunction with the reused
webRequestMock
of thevcs
test module, lets us provide an array of the parsed objects returned byHTTP
and use them based on path as responses to API calls, to properly Mock any API return within a given chain.Lastly, a global hashMap is used to retain every generated mock, so that it can be reused within a single files tests, to reduce duplication.