logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

chat_channel_test.exs (1104B)


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