Merge branch 'test-paginated-event-list' into 'master'
Test paginated event list See merge request framasoft/mobilizon!32
This commit is contained in:
commit
9671ba8a02
|
@ -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 ->
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue