1

First of all, if I should ask this question elsewhere please let me know, as I'm not sure where it belongs.

I have a working application with NextJS and MSW, where I can capture the server-side API requests with MSW and return mocked JSON results.

The issue I have is that there are probably about 15 API calls that I need to mock in order to test my application properly

While I could just call each one of these manually, copy and paste the results into a file and then just return that data from the file when I capture the API call, this not a very scalable solution, especially if the back-end API changes.

Question: What are your best methods for automating the generation of these results?

In the past I have created JSON files that have all of the URL paths and query parameters explicitely listed, and I would parse through this file and query every endpoint, and then I had template files which would be used to re-populate my fixtures directory with all of the mocked responses, however this was also very cumbersome.

(For reference, the API has a somewhat similar structure to this one: https://api.gouv.fr/documentation/api-geo, where there are multiple endpoints for fetching data, and each endpoint supports a number of different query parameters to tweak the call.)

Tyler
  • 1,163
  • 16
  • 37

0 Answers0