Refactor the Code

Learn how to refactor repository code and test routes.

What is left to test?

We have no tests for our Repository class, which handles all the database work. We also don’t have tests for our routes.

We have several options for testing here, but we have to do some refactoring before we can test either of them. For starters, we should move our routes out of our main application into separate classes to test them more easily. But should we refactor code only to gain better testability?

The answer is yes, we should. There are, of course, pros and cons to that, but in general, this approach makes sense. Regardless of pure or impure, we want our code to have a clean structure.

Get hands-on with 1200+ tech skills courses.