You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR introduced unit tests for Broker Microservice's user-facing endpoints: #677.
The idea was that these endpoints need custom unit tests because the endpoints which are used by Integration Tests are already implicitly tested every time Test Suite runs.
The only remaining one is the /validation-errors endpoint.
Solution Notes
Broker's global state and initialization issues
Broker uses global state (see state.js) and config that is loaded from a file as soon as the broker-config.js module is imported. These can get in the way of simple unit tests. So the strategy so far has been to isolate functions that need to be tested into modules that do NOT have state.js or broker-config.js in their dependency chain (see util/sample-opportunities.js for an example of such a module. It contains and links to a fair bit of functionality but never loads either of those modules).
So, you'll need to move renderValidationErrorsHtml(..) out of core.js. You can then test the /validation-errors route by testing this functionality.
This function just uses a ValidatorWorkerPool class to get some data from it, so you can just manually set up one of these with the data that is needed to set up the test.
Testing an HTML page
Since it's an HTML page, I recommend using a library like https://github.com/cheeriojs/cheerio to create a DOM, which can then be queried to see that things are working as expected
The text was updated successfully, but these errors were encountered:
This PR introduced unit tests for Broker Microservice's user-facing endpoints: #677.
The idea was that these endpoints need custom unit tests because the endpoints which are used by Integration Tests are already implicitly tested every time Test Suite runs.
The only remaining one is the
/validation-errors
endpoint.Solution Notes
Broker's global state and initialization issues
Broker uses global state (see
state.js
) and config that is loaded from a file as soon as thebroker-config.js
module is imported. These can get in the way of simple unit tests. So the strategy so far has been to isolate functions that need to be tested into modules that do NOT havestate.js
orbroker-config.js
in their dependency chain (seeutil/sample-opportunities.js
for an example of such a module. It contains and links to a fair bit of functionality but never loads either of those modules).So, you'll need to move
renderValidationErrorsHtml(..)
out ofcore.js
. You can then test the/validation-errors
route by testing this functionality.This function just uses a
ValidatorWorkerPool
class to get some data from it, so you can just manually set up one of these with the data that is needed to set up the test.Testing an HTML page
Since it's an HTML page, I recommend using a library like https://github.com/cheeriojs/cheerio to create a DOM, which can then be queried to see that things are working as expected
The text was updated successfully, but these errors were encountered: