defmodule WaxxWeb.BoardChannelTest do
use WaxxWeb.ChannelCase, async: true
import Waxx.AccountsFixtures
import Waxx.KanbanFixtures
alias WaxxWeb.{BoardChannel, UserSocket}
defp connected_socket(user) do
token = api_token_fixture(user)
{:ok, socket} = connect(UserSocket, %{"token" => token})
socket
end
test "members can join their board channel" do
user = confirmed_user_fixture()
board = board_fixture(user)
socket = connected_socket(user)
{:ok, reply, _socket} = subscribe_and_join(socket, BoardChannel, "board:" <> board.id)
assert reply == %{board_id: board.id}
end
test "non-members are refused" do
member = confirmed_user_fixture()
stranger = confirmed_user_fixture()
board = board_fixture(member)
socket = connected_socket(stranger)
assert {:error, %{reason: "forbidden"}} =
subscribe_and_join(socket, BoardChannel, "board:" <> board.id)
end
test "broadcasts cards_changed when a card mutation lands" do
user = confirmed_user_fixture()
board = board_fixture(user)
socket = connected_socket(user)
{:ok, _, _} = subscribe_and_join(socket, BoardChannel, "board:" <> board.id)
# Trigger an actual mutation; the existing PubSub broadcast in
# Kanban routes through to the channel.
_ = card_fixture(board, user)
assert_push("cards_changed", %{board_id: board_id})
assert board_id == board.id
end
test "revoking an api token broadcasts a 'disconnect' on the user_socket" do
user = confirmed_user_fixture()
token = api_token_fixture(user)
{:ok, socket} = connect(UserSocket, %{"token" => token})
# Subscribe the test process to the user's socket topic so we can
# observe the disconnect broadcast.
WaxxWeb.Endpoint.subscribe("user_socket:" <> socket.assigns.user_id)
[%{id: token_id}] = Waxx.Accounts.list_api_tokens(user)
:ok = Waxx.Accounts.delete_api_token(user, token_id)
assert_receive %Phoenix.Socket.Broadcast{event: "disconnect"}
end
end
neiam
/waxx
waxx
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
Log in to mark this repository.
2.0 KiB · text
History
a2252b9