Test refactor

CC @jnormore 

We (Shopify) currently carry our own set of patches on top of this package. Not all of them are necessarily worthy of being upstreamed (our use case is fairly specific), but at least some parts of them are, so assuming that this is acceptable I will probably submit a few more PRs over the next few weeks.

This change refactors the test function `testWithClient` into many more individual methods so that our test code can reuse them. There should be no functional changes to the tests (or to any of the actual package code, of course).