Web.MastodonApi.MastodonSocketTest: Add test for unauthenticated websocket
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Sat, 24 Nov 2018 07:47:35 +0000 (08:47 +0100)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Sat, 24 Nov 2018 07:51:35 +0000 (08:51 +0100)
test/web/mastodon_api/mastodon_socket_test.exs [new file with mode: 0644]

diff --git a/test/web/mastodon_api/mastodon_socket_test.exs b/test/web/mastodon_api/mastodon_socket_test.exs
new file mode 100644 (file)
index 0000000..c7d71de
--- /dev/null
@@ -0,0 +1,33 @@
+defmodule Pleroma.Web.MastodonApi.MastodonSocketTest do
+  use Pleroma.DataCase
+
+  alias Pleroma.Web.MastodonApi.MastodonSocket
+  alias Pleroma.Web.{Streamer, CommonAPI}
+  alias Pleroma.User
+
+  import Pleroma.Factory
+
+  test "public is working when non-authenticated" do
+    user = insert(:user)
+
+    task =
+      Task.async(fn ->
+        assert_receive {:text, _}, 4_000
+      end)
+
+    fake_socket = %{
+      transport_pid: task.pid,
+      assigns: %{}
+    }
+
+    topics = %{
+      "public" => [fake_socket]
+    }
+
+    {:ok, activity} = CommonAPI.post(user, %{"status" => "Test"})
+
+    Streamer.push_to_socket(topics, "public", activity)
+
+    Task.await(task)
+  end
+end