logo

pleroma

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

state_test.exs (1560B)


      1 # Pleroma: A lightweight social networking server
      2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
      3 # SPDX-License-Identifier: AGPL-3.0-only
      4 
      5 defmodule Pleroma.Web.StateTest do
      6   use Pleroma.DataCase
      7 
      8   import Pleroma.Factory
      9   alias Pleroma.Web.Streamer
     10   alias Pleroma.Web.Streamer.StreamerSocket
     11 
     12   @moduletag needs_streamer: true
     13 
     14   describe "sockets" do
     15     setup do
     16       user = insert(:user)
     17       user2 = insert(:user)
     18       {:ok, %{user: user, user2: user2}}
     19     end
     20 
     21     test "it can add a socket", %{user: user} do
     22       Streamer.add_socket("public", %{transport_pid: 1, assigns: %{user: user}})
     23 
     24       assert(%{"public" => [%StreamerSocket{transport_pid: 1}]} = Streamer.get_sockets())
     25     end
     26 
     27     test "it can add multiple sockets per user", %{user: user} do
     28       Streamer.add_socket("public", %{transport_pid: 1, assigns: %{user: user}})
     29       Streamer.add_socket("public", %{transport_pid: 2, assigns: %{user: user}})
     30 
     31       assert(
     32         %{
     33           "public" => [
     34             %StreamerSocket{transport_pid: 2},
     35             %StreamerSocket{transport_pid: 1}
     36           ]
     37         } = Streamer.get_sockets()
     38       )
     39     end
     40 
     41     test "it will not add a duplicate socket", %{user: user} do
     42       Streamer.add_socket("activity", %{transport_pid: 1, assigns: %{user: user}})
     43       Streamer.add_socket("activity", %{transport_pid: 1, assigns: %{user: user}})
     44 
     45       assert(
     46         %{
     47           "activity" => [
     48             %StreamerSocket{transport_pid: 1}
     49           ]
     50         } = Streamer.get_sockets()
     51       )
     52     end
     53   end
     54 end