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

Broker Microservice: Unit test the /validation-errors endpoint #678

Open
lukehesluke opened this issue Mar 27, 2024 · 0 comments
Open

Broker Microservice: Unit test the /validation-errors endpoint #678

lukehesluke opened this issue Mar 27, 2024 · 0 comments

Comments

@lukehesluke
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 💡Ideas
Development

No branches or pull requests

1 participant