Communicating with a Test Channel

Let’s see how easy it is to test our VideoChannel features. Our plan is simple. We’re going to set up some data to share across our tests and then sign the user in within our setup block. Then, we can write some independent tests against that live connection.

First we’ll need a few helper functions to make it easier to create users and videos. Make the file test/support/test_helpers.ex look like this:

 defmodule​ RumblWeb.TestHelpers ​do
 
 defp​ default_user() ​do
  %{
 name:​ ​"​​Some User"​,
 username:​ ​"​​user​​#{​System.unique_integer([​:positive​])​}​​"​,
 password:​ ​"​​supersecret"
  }
 end
 
 def​ insert_user(attrs ...

Get Programming Phoenix 1.4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.