2020-10-12 17:00:50 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-10-12 17:00:50 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-08-03 22:08:35 +00:00
|
|
|
defmodule Pleroma.Web.ShoutChannelTest do
|
2019-12-04 11:48:34 +00:00
|
|
|
use Pleroma.Web.ChannelCase
|
2020-08-03 22:08:35 +00:00
|
|
|
alias Pleroma.Web.ShoutChannel
|
2019-12-04 11:48:34 +00:00
|
|
|
alias Pleroma.Web.UserSocket
|
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
setup do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, _, socket} =
|
|
|
|
socket(UserSocket, "", %{user_name: user.nickname})
|
2021-06-07 21:10:24 +00:00
|
|
|
|> subscribe_and_join(ShoutChannel, "chat:public")
|
2019-12-04 11:48:34 +00:00
|
|
|
|
|
|
|
{: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-08-04 15:42:52 +00:00
|
|
|
setup do: clear_config([:shout, :limit])
|
2019-12-04 11:48:34 +00: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
|
2021-05-20 19:30:29 +00:00
|
|
|
clear_config([:shout, :limit], 2)
|
2019-12-04 11:48:34 +00:00
|
|
|
push(socket, "new_msg", %{"text" => "123"})
|
|
|
|
refute_broadcast("new_msg", %{text: "123"})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|