alvinlal

alvinlal

how to assert that a particular socket received a particular event in phoenix channel test

if i have a channel test like given below, is it possible to assert that socketA client received a particular event and socketB received a particular event ?

defmodule RockPaperScissorsWeb.GameChannelTest do
  use RockPaperScissorsWeb.ChannelCase

  test "players get correct results" do

    player_id_a = UUID.uuid4()
    player_id_b = UUID.uuid4()
    game_channel_id = UUID.uuid4()

    {_, _, socketA} = joinGameChannel(game_channel_id, player_id_a)
    {_, _, socketB} = joinGameChannel(game_channel_id, player_id_b)

    push(socketA, "move", %{"player_id" => player_id_a, "move" => "r"})
    push(socketB, "move", %{"player_id" => player_id_b, "move" => "r"})

   # assert that socketA client received a particular event
   # assert that socketB client received a particular event
  end


  # Helpers
  defp joinGameChannel(game_channel_id, player_id) do
    RockPaperScissorsWeb.Socket
    |> socket(nil, %{})
    |> subscribe_and_join(
      RockPaperScissorsWeb.GameChannel,
      "game:#{game_channel_id}",
      %{"player_id" => player_id}
    )
  end

end

Where Next?

Popular in Questions Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New

Other popular topics Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement