From ad0086032b27747378d4f08624c8083c8fc7ee9b Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 18 Dec 2020 16:32:54 +0100 Subject: [PATCH] Fix tests with events listing Signed-off-by: Thomas Citharel --- lib/mobilizon/events/events.ex | 8 ++-- test/graphql/resolvers/event_test.exs | 38 +++++++++---------- .../activity_pub_controller_test.exs | 24 ++++++++++-- 3 files changed, 42 insertions(+), 28 deletions(-) diff --git a/lib/mobilizon/events/events.ex b/lib/mobilizon/events/events.ex index c291d8ee..ec3a1b53 100644 --- a/lib/mobilizon/events/events.ex +++ b/lib/mobilizon/events/events.ex @@ -357,15 +357,15 @@ defmodule Mobilizon.Events do direction \\ :asc, is_future \\ true ) do - query = from(e in Event, distinct: true, preload: [:organizer_actor, :participants]) - - query + Event + |> distinct([e], [{^direction, ^sort}, asc: e.id]) + |> preload([:organizer_actor, :participants]) |> sort(sort, direction) |> filter_future_events(is_future) |> filter_public_visibility() |> filter_draft() |> filter_local_or_from_followed_instances_events() - |> Page.build_page(page, limit, sort) + |> Page.build_page(page, limit) end @spec stream_events_for_sitemap :: Enum.t() diff --git a/test/graphql/resolvers/event_test.exs b/test/graphql/resolvers/event_test.exs index a83559e0..7d6ce0d1 100644 --- a/test/graphql/resolvers/event_test.exs +++ b/test/graphql/resolvers/event_test.exs @@ -1166,42 +1166,38 @@ defmodule Mobilizon.Web.Resolvers.EventTest do event.uuid ] - Enum.each(0..15, fn _ -> - insert(:event) - end) - - res = - conn - |> AbsintheHelpers.graphql_query(query: @fetch_events_query) - - assert res["data"]["events"]["total"] == 17 - assert res["data"]["events"]["elements"] |> length == 10 - - res = - conn - |> AbsintheHelpers.graphql_query(query: @fetch_events_query, variables: %{page: 2}) - - assert res["data"]["events"]["total"] == 17 - assert res["data"]["events"]["elements"] |> length == 7 + insert(:event) + # Process.sleep(1000) + insert(:event) res = conn |> AbsintheHelpers.graphql_query( query: @fetch_events_query, - variables: %{page: 2, limit: 15} + variables: %{page: 1, limit: 2} ) - assert res["data"]["events"]["total"] == 17 + assert res["data"]["events"]["total"] == 3 assert res["data"]["events"]["elements"] |> length == 2 res = conn |> AbsintheHelpers.graphql_query( query: @fetch_events_query, - variables: %{page: 3, limit: 15} + variables: %{page: 2, limit: 2} ) - assert res["data"]["events"]["total"] == 17 + assert res["data"]["events"]["total"] == 3 + assert res["data"]["events"]["elements"] |> length == 1 + + res = + conn + |> AbsintheHelpers.graphql_query( + query: @fetch_events_query, + variables: %{page: 3, limit: 2} + ) + + assert res["data"]["events"]["total"] == 3 assert res["data"]["events"]["elements"] |> length == 0 end diff --git a/test/web/controllers/activity_pub_controller_test.exs b/test/web/controllers/activity_pub_controller_test.exs index a400d490..ca962f66 100644 --- a/test/web/controllers/activity_pub_controller_test.exs +++ b/test/web/controllers/activity_pub_controller_test.exs @@ -436,10 +436,28 @@ defmodule Mobilizon.Web.ActivityPubControllerTest do |> get(Actor.build_url(group.preferred_username, :members)) |> json_response(200) - assert [admin_member | [member]] = result["first"]["orderedItems"] + assert members = result["first"]["orderedItems"] + + admin_member = + Enum.find( + members, + fn member -> + member["actor"] == actor_group_admin.url + end + ) + + member = + Enum.find( + members, + fn member -> + member["actor"] == actor_applicant.url + end + ) + assert admin_member["role"] == "administrator" - assert member["role"] == "member" - assert result["totalItems"] == 2 + + assert member["role"] == "member" || + assert(result["totalItems"] == 2) end end