diff --git a/lib/poxa/users_handler.ex b/lib/poxa/users_handler.ex index 274589e..cfe444a 100644 --- a/lib/poxa/users_handler.ex +++ b/lib/poxa/users_handler.ex @@ -49,8 +49,8 @@ defmodule Poxa.UsersHandler do """ def get_json(req, channel) do - response = PresenceChannel.users(channel) |> Enum.map(fn(id) -> [id: id] end) - {Poison.encode!(users: response), req, nil} + response = PresenceChannel.users(channel) |> Enum.map(fn(id) -> %{ id: id } end) + {Poison.encode!(%{ users: response }), req, nil} end end diff --git a/test/integration/presence_channel_test.exs b/test/integration/presence_channel_test.exs index ca204e1..e9ca347 100644 --- a/test/integration/presence_channel_test.exs +++ b/test/integration/presence_channel_test.exs @@ -49,6 +49,8 @@ defmodule Poxa.Integration.PresenceChannelTest do assert_receive %{channel: ^channel, event: "test_event", data: %{"data" => 42}}, 1_000 + + assert Pusher.users(channel) == {:ok, [%{"id" => "123"}]} end test "member_added event on populated presence channel", context do @@ -74,6 +76,8 @@ defmodule Poxa.Integration.PresenceChannelTest do data: %{"user_id" => "123", "user_info" => %{"k2" => "v2"}}, event: "pusher_internal:member_added"}, 1_000 + assert Pusher.users(channel) == {:ok, [%{"id" => "123"}, %{"id" => "456"}]} + PusherClient.disconnect!(other_pid) end @@ -124,6 +128,8 @@ defmodule Poxa.Integration.PresenceChannelTest do data: %{"user_id" => "456"}, event: "pusher_internal:member_removed"}, 1_000 + assert Pusher.users(channel) == {:ok, [%{"id" => "123"}]} + PusherClient.disconnect!(other_pid) end @@ -150,6 +156,8 @@ defmodule Poxa.Integration.PresenceChannelTest do data: %{"user_id" => "123"}, event: "pusher_internal:member_removed"}, 1_000 + assert Pusher.users(channel) == {:ok, [%{"id" => "123"}]} + PusherClient.disconnect!(other_pid) end end diff --git a/test/users_handler_test.exs b/test/users_handler_test.exs index f491118..0a0f30b 100644 --- a/test/users_handler_test.exs +++ b/test/users_handler_test.exs @@ -31,7 +31,7 @@ defmodule Poxa.UsersHandlerTest do test "get_json returns users of a presence channel" do expect(PresenceChannel, :users, 1, ["user1", "user2"]) - expected = [users: [[id: "user1"], [id: "user2"]]] + expected = %{ users: [%{ id: "user1" }, %{ id: "user2" }] } expect(Poison, :encode!, [{[expected], :encoded_json}]) assert get_json(:req, "channel123") == {:encoded_json, :req, nil}