refactor middleware test