Testing the GraphQL API with Mocha
We must verify that all the API functions we're offering work correctly. I'm going to show you how to do this with two examples, as follows:
- The user needs to sign up or log in. This is a critical feature where we should verify that the API works correctly.
- The user queries or mutates data via the GraphQL API. For our test case, we will request all chats the logged-in user is related to.
Those two examples should explain all the essential techniques to test every part of your API. You can add more functions that you want to test at any point.
Testing the authentication
We extend the authentication tests of our test with the signup functionality. We're going to send a simple GraphQL request to our backend, including all the required data to sign up a new user. We've already sent requests, so there's nothing new here. In comparison to all the requests before, however, we have to send a POST
request...