shout_channel_test.ex 1.22 KB
Newer Older
feld's avatar
feld committed
1
# Pleroma: A lightweight social networking server
Haelwenn's avatar
Haelwenn committed
2
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
feld's avatar
feld committed
3
4
# SPDX-License-Identifier: AGPL-3.0-only

5
defmodule Pleroma.Web.ShoutChannelTest do
6
  use Pleroma.Web.ChannelCase
7
  alias Pleroma.Web.ShoutChannel
8
9
10
11
12
13
14
15
16
  alias Pleroma.Web.UserSocket

  import Pleroma.Factory

  setup do
    user = insert(:user)

    {:ok, _, socket} =
      socket(UserSocket, "", %{user_name: user.nickname})
17
      |> subscribe_and_join(ShoutChannel, "shout:public")
18
19
20
21
22
23
24
25
26
27

    {:ok, socket: socket}
  end

  test "it broadcasts a message", %{socket: socket} do
    push(socket, "new_msg", %{"text" => "why is tenshi eating a corndog so cute?"})
    assert_broadcast("new_msg", %{text: "why is tenshi eating a corndog so cute?"})
  end

  describe "message lengths" do
28
    setup do: clear_config([:shout, :limit])
29
30
31
32
33
34
35

    test "it ignores messages of length zero", %{socket: socket} do
      push(socket, "new_msg", %{"text" => ""})
      refute_broadcast("new_msg", %{text: ""})
    end

    test "it ignores messages above a certain length", %{socket: socket} do
36
      Pleroma.Config.put([:shout, :limit], 2)
37
38
39
40
41
      push(socket, "new_msg", %{"text" => "123"})
      refute_broadcast("new_msg", %{text: "123"})
    end
  end
end