2020-10-12 11:00:50 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-12 23:49:20 -07:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-10-12 11:00:50 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-12-04 04:48:34 -07:00
|
|
|
defmodule Pleroma.Web.ChatChannelTest do
|
|
|
|
use Pleroma.Web.ChannelCase
|
|
|
|
alias Pleroma.Web.ChatChannel
|
|
|
|
alias Pleroma.Web.UserSocket
|
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
setup do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, _, socket} =
|
|
|
|
socket(UserSocket, "", %{user_name: user.nickname})
|
|
|
|
|> subscribe_and_join(ChatChannel, "chat:public")
|
|
|
|
|
|
|
|
{: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
|
2020-03-20 09:33:00 -06:00
|
|
|
setup do: clear_config([:instance, :chat_limit])
|
2019-12-04 04:48:34 -07:00
|
|
|
|
|
|
|
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
|
|
|
|
Pleroma.Config.put([:instance, :chat_limit], 2)
|
|
|
|
push(socket, "new_msg", %{"text" => "123"})
|
|
|
|
refute_broadcast("new_msg", %{text: "123"})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|