October 2019
Intermediate to advanced
358 pages
8h 22m
English
If your code is worth writing, it’s worth testing. Earlier, we bypassed our authentication plug, so we should test it now. The good news is that since our plug is essentially a function, it’s relatively easy to build a set of tests that will confirm that it does what we need.
Create a test/rumbl_web/controllers/auth_test.exs and key in the following contents. We’re going to break the test file into parts to keep things simple.
First, test the authenticate_user function that does the lion’s share of the work:
| | defmodule RumblWeb.AuthTest do |
| | use RumblWeb.ConnCase, async: true |
| | alias RumblWeb.Auth |
| | |
| | test "authenticate_user halts when no current_user ... |
Read now
Unlock full access