I’m trying to understand how to create tests for REST Endpoint that a custom module creates.
I managed to create a Unit Test for the Get method of the Rest-resource and now I want to create a Functional test for the REST-endpoint.
The idea of the test is the following. The test should create a user account with required roles and permissions, authenticate it on the site and send a GET request on behalf of it. And after that, the test should check up the content of the response in JSON format and compare it with the expected.
Also, it’s possible to create a test for trying a use without permission to send a request and get a response.
Unfortunately, I haven’t found any relevant examples of this test.
Could you clarify me or share your experience, on how to create these tests?
Does the Drupal testing framework have tools to create tests for REST requests? Or maybe would it be simpler or more correctly to use some external tools for this testing?
Which kind of test should I use – Kernel test or Browser test?
Could anyone share an example of this test or a link?
Thanks in advance.