Refactor middleware tests.