Refactor most logic to makeRequest and test it directly.