As you can see in the example code above, the method returns the parsed response if the page count equals the current page, otherwise, it calls itself recursively. So, in case of recursion, we need to make sure that the method and the mocked dependencies are called with the correct parameters on each call in the tests.
We need some dependencies for the example project.
Creating Stubs and Dummy Objects
As the recursion case occurs when the
x-total-pages key from the response headers is received with a value bigger than one, we can start to write out test code by creating dummy response objects like the following ones.
As the resultset consists of two pages, the request builder object should return some results like the following ones according to the page number it is called with.
And.. we have some parsed responses and final result expectations like the following