Challenge: Test API Routes with Cypress

Challenge yourself by manually testing API routes and asserting the correct responses.

We'll cover the following

Although the process of testing API routes is similar to testing other pages, there are a few differences to consider. For instance, when testing the creation of meetups, instead of manually filling up a form and submitting it, we can directly call the API route responsible for creating new meetups. Since we use trpc to handle our API routes, determining the correct path for the API route is not as straightforward.

Based on the file structure, we can see that this file is located at /pages/api/trpc/[trpc].ts. The API route for this file is /api/trpc/[trpc], where [trpc] represents the name of our mutation, which, in this case, is create. To manually call this API route, we need to send a request to the /api/trpc/create path. In addition to figuring out the path of the API route, we also need to determine the payload structure.

Let’s examine the validation schema responsible for defining the structure of the JSON payload accepted by our API route.

Get hands-on with 1200+ tech skills courses.