Writing and running tests
We are going to give a couple of examples of writing tests. First, we will use a public endpoint and see how we can write a test against our public
routes, then we will see how to test a secure endpoint.
Testing a public endpoint
We will start by testing a public endpoint first; let's consider the GET /api/classrooms
endpoint. We want to test the endpoint is working as expected—that is, it is accessible and returning the expected result.
Before we start writing the tests, let's make sure that we are allowing public access to this endpoint by updating the permissions. Update the bootstrap
function in the src/index.js
file, allowing public
access to the classroom's find
endpoint, as illustrated in the following code snippet:
await enablePermission("public", "classroom","classroom", "find");
We should be able to access the GET /api/classrooms
endpoint without the need to authenticate...