Refactor User.post_register_action/1 emails
[akkoma] / test / web / chat_channel_test.exs
1 defmodule Pleroma.Web.ChatChannelTest do
2 use Pleroma.Web.ChannelCase
3 alias Pleroma.Web.ChatChannel
4 alias Pleroma.Web.UserSocket
5
6 import Pleroma.Factory
7
8 setup do
9 user = insert(:user)
10
11 {:ok, _, socket} =
12 socket(UserSocket, "", %{user_name: user.nickname})
13 |> subscribe_and_join(ChatChannel, "chat:public")
14
15 {:ok, socket: socket}
16 end
17
18 test "it broadcasts a message", %{socket: socket} do
19 push(socket, "new_msg", %{"text" => "why is tenshi eating a corndog so cute?"})
20 assert_broadcast("new_msg", %{text: "why is tenshi eating a corndog so cute?"})
21 end
22
23 describe "message lengths" do
24 setup do: clear_config([:instance, :chat_limit])
25
26 test "it ignores messages of length zero", %{socket: socket} do
27 push(socket, "new_msg", %{"text" => ""})
28 refute_broadcast("new_msg", %{text: ""})
29 end
30
31 test "it ignores messages above a certain length", %{socket: socket} do
32 Pleroma.Config.put([:instance, :chat_limit], 2)
33 push(socket, "new_msg", %{"text" => "123"})
34 refute_broadcast("new_msg", %{text: "123"})
35 end
36 end
37 end