Test paginated event list

Introduce an event number limit for…limits

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2018-12-21 11:45:55 +01:00
parent 088df9e207
commit db2cec7706
2 changed files with 87 additions and 1 deletions

View File

@ -4,10 +4,18 @@ defmodule MobilizonWeb.Resolvers.Event do
alias Mobilizon.Actors alias Mobilizon.Actors
alias Mobilizon.Events.Event alias Mobilizon.Events.Event
def list_events(_parent, %{page: page, limit: limit}, _resolution) do # We limit the max number of events that can be retrieved
@event_max_limit 100
def list_events(_parent, %{page: page, limit: limit}, _resolution)
when limit < @event_max_limit do
{:ok, Mobilizon.Events.list_events(page, limit)} {:ok, Mobilizon.Events.list_events(page, limit)}
end end
def list_events(_parent, %{page: page, limit: limit}, _resolution) do
{:error, :events_max_limit_reached}
end
def find_event(_parent, %{uuid: uuid}, _resolution) do def find_event(_parent, %{uuid: uuid}, _resolution) do
case Mobilizon.Events.get_event_full_by_uuid(uuid) do case Mobilizon.Events.get_event_full_by_uuid(uuid) do
nil -> nil ->

View File

@ -163,5 +163,83 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do
assert hd(tl(json_response(res, 200)["data"]["search"]))["preferredUsername"] == assert hd(tl(json_response(res, 200)["data"]["search"]))["preferredUsername"] ==
actor.preferred_username actor.preferred_username
end end
test "list_events/3 returns events", context do
event = insert(:event)
query = """
{
events {
uuid,
}
}
"""
res =
context.conn
|> get("/api", AbsintheHelpers.query_skeleton(query, "event"))
assert json_response(res, 200)["data"]["events"] |> Enum.map(& &1["uuid"]) == [event.uuid]
Enum.each(0..15, fn _ ->
insert(:event)
end)
query = """
{
events {
uuid,
}
}
"""
res =
context.conn
|> get("/api", AbsintheHelpers.query_skeleton(query, "event"))
assert json_response(res, 200)["data"]["events"] |> length == 10
query = """
{
events(page: 2) {
uuid,
}
}
"""
res =
context.conn
|> get("/api", AbsintheHelpers.query_skeleton(query, "event"))
assert json_response(res, 200)["data"]["events"] |> length == 7
query = """
{
events(page: 2, limit: 15) {
uuid,
}
}
"""
res =
context.conn
|> get("/api", AbsintheHelpers.query_skeleton(query, "event"))
assert json_response(res, 200)["data"]["events"] |> length == 2
query = """
{
events(page: 3, limit: 15) {
uuid,
}
}
"""
res =
context.conn
|> get("/api", AbsintheHelpers.query_skeleton(query, "event"))
assert json_response(res, 200)["data"]["events"] |> length == 0
end
end end
end end