October 2019
Intermediate to advanced
358 pages
8h 22m
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 rumbl_umbrella/apps/rumbl_web/test/channels/user_socket_test.exs file containing:
| 1: | defmodule RumblWeb.Channels.UserSocketTest do |
| - | use RumblWeb.ChannelCase, async: true |
| - | alias RumblWeb.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 ... |
Read now
Unlock full access