Testing the Happy Path
Let’s create a test for the happy path of our application.
We'll cover the following
Defining the happy path test
The test is structured very similarly to the error test from the previous lesson. The common elements are these:
-
It accepts a context with a
Plug.Conn
that contains a valid JWT. -
It calls the endpoint using
put/3
, a helper from the Phoenix library. -
It uses
json_response/2
to assert on the HTTP response code and to deserialize the JSON response. -
It makes assertions on the return value.
-
It makes assertions on the side effects.
Let’s add the following test inside the describe block PUT /api/users/:id
.
Get hands-on with 1400+ tech skills courses.