April 2016
Beginner to intermediate
300 pages
6h 58m
English
Most of our channels code relies on an authenticated user. We’ll start our tests with the socket authentication. Let’s do that now.
Create a rumbrella/apps/rumbl/test/channels/user_socket_test.exs file containing:
| 1: | defmodule Rumbl.Channels.UserSocketTest do |
| - | use Rumbl.ChannelCase, async: true |
| - | alias Rumbl.UserSocket |
| - | |
| 5: | test "socket authentication with valid token" do |
| - | token = Phoenix.Token.sign(@endpoint, "user socket", "123") |
| - | |
| - | assert {:ok, socket} = connect(UserSocket, %{"token" => token}) |
| - | assert socket.assigns.user_id == "123" |
| 10: | end |
| - | |
| - | test "socket authentication with invalid ... |
Read now
Unlock full access