Refactor test
Move complex query into a method