Skip to content

Commit

Permalink
Merge pull request #130 from edgurgel/fix-user-handler-json
Browse files Browse the repository at this point in the history
Fix UsersHandler JSON generation
  • Loading branch information
edgurgel authored Jun 30, 2018
2 parents 35aa381 + 51b821b commit d4c698b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/poxa/users_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

8 changes: 8 additions & 0 deletions test/integration/presence_channel_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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
2 changes: 1 addition & 1 deletion test/users_handler_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit d4c698b

Please sign in to comment.