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 da817d35c4
commit bee896a485
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
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.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)}
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
case Mobilizon.Events.get_event_full_by_uuid(uuid) do
nil ->

View File

@ -163,5 +163,83 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do
assert hd(tl(json_response(res, 200)["data"]["search"]))["preferredUsername"] ==
actor.preferred_username
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