Improve integration tests
Currently, the codebase contains a lot of complexity by introducing traits that are used for mocking dependencies in tests. While this allows us to test the bors in an easy way by replacing the Team API and GitHub API communication, it also means that we are not testing a bunch of code (the "frontend" - setting up the webhook server and the "backend" - communication with external APIs). We also mock the database completely.
I think that it would be better to make our tests (even more) integration-like, and just test the whole app together. This means a few things:
- We would need to use a real PostgreSQL database in tests. That should be quite easy to do in
sqlx(sqlx::testcan inject a Postgres database into tests). - We would need to mock Team API and GitHub API HTTP calls (this can be done using e.g.
wiremockorhttpmock). Mocking REST API calls is not that complicated, GraphQL is a bit harder, but should still be doable. - We would need to generate the inputs to the app using GH webhooks (should be relatively easy by writing a few generator functions for them).
- We would need to mock time (to test timeouts etc.), but we already do that, and if we will run the integration tests in-process (rather than just running the binary), we can reuse the same implementation.
- We would need to handle the fact that the tests would no longer be "synchronous", in the sense that we would need to wait some time e.g. until a comment "appears" on a PR (now we can just
awaita handler that will post the comment until it finishes).
If we do all do that, we can get rid of all the annoying traits, and simplify the codebase a lot.
Before we do this, we should evaluate if it is indeed possible to reasonably write a full end-to-end integration test though, and if there aren't any big problems with it.