Refactor api_client_test

* Trim and convert to string test made more exact
* Use a helper method to generate error