From 74e59b239809d65b33718e23981e49fe99d14ef7 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 27 Nov 2020 14:56:48 +0100 Subject: [PATCH 1/2] Fix tests failure with Group test find_group/3 Signed-off-by: Thomas Citharel --- test/graphql/resolvers/group_test.exs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/graphql/resolvers/group_test.exs b/test/graphql/resolvers/group_test.exs index 6514a33b6..e23bed6c1 100644 --- a/test/graphql/resolvers/group_test.exs +++ b/test/graphql/resolvers/group_test.exs @@ -155,6 +155,7 @@ defmodule Mobilizon.Web.Resolvers.GroupTest do group.preferred_username assert res["data"]["group"]["members"]["total"] == 2 + assert res["data"]["group"]["members"]["elements"] == [] res = conn @@ -170,9 +171,12 @@ defmodule Mobilizon.Web.Resolvers.GroupTest do assert res["errors"] == nil assert res["data"]["group"]["members"]["total"] == 2 - assert hd(res["data"]["group"]["members"]["elements"])["role"] == "ADMINISTRATOR" - assert hd(res["data"]["group"]["members"]["elements"])["actor"]["preferredUsername"] == + admin = + res["data"]["group"]["members"]["elements"] + |> Enum.find(&(&1["role"] == "ADMINISTRATOR")) + + assert admin["actor"]["preferredUsername"] == actor.preferred_username res = From 10eb64720ed55b71d6c13763a438e0e1f9b7e95d Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 27 Nov 2020 15:47:34 +0100 Subject: [PATCH 2/2] Fix tests with scheduler notifications Close #390 Signed-off-by: Thomas Citharel --- lib/service/notifications/scheduler.ex | 9 +++------ test/service/notifications/scheduler_test.exs | 10 +++++++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/service/notifications/scheduler.ex b/lib/service/notifications/scheduler.ex index 9bde9fff6..773bb4689 100644 --- a/lib/service/notifications/scheduler.ex +++ b/lib/service/notifications/scheduler.ex @@ -145,7 +145,6 @@ defmodule Mobilizon.Service.Notifications.Scheduler do with %Actor{user_id: user_id} when not is_nil(user_id) <- Actors.get_actor(organizer_actor_id), %User{ - locale: locale, settings: %Setting{ notification_pending_participation: notification_pending_participation, timezone: timezone @@ -160,7 +159,7 @@ defmodule Mobilizon.Service.Notifications.Scheduler do :direct :one_day -> - calculate_next_day_notification(Date.utc_today(), timezone, locale) + calculate_next_day_notification(Date.utc_today(), timezone) :one_hour -> DateTime.utc_now() @@ -219,7 +218,6 @@ defmodule Mobilizon.Service.Notifications.Scheduler do defp pending_membership_admin_notification_user( %User{ id: user_id, - locale: locale, settings: %Setting{ notification_pending_membership: notification_pending_membership, timezone: timezone @@ -236,7 +234,7 @@ defmodule Mobilizon.Service.Notifications.Scheduler do :direct :one_day -> - calculate_next_day_notification(Date.utc_today(), timezone, locale) + calculate_next_day_notification(Date.utc_today(), timezone) :one_hour -> DateTime.utc_now() @@ -280,13 +278,12 @@ defmodule Mobilizon.Service.Notifications.Scheduler do else: calculate_first_day_of_week(Date.add(date, -1), locale) end - defp calculate_next_day_notification(%Date{} = day, timezone, locale) do + defp calculate_next_day_notification(%Date{} = day, timezone) do send_at = date_to_datetime(day, ~T[18:00:00], timezone) if DateTime.compare(send_at, DateTime.utc_now()) == :lt do day |> Date.add(1) - |> calculate_first_day_of_week(locale) |> date_to_datetime(~T[18:00:00], timezone) else send_at diff --git a/test/service/notifications/scheduler_test.exs b/test/service/notifications/scheduler_test.exs index 3f0d9ce7c..60b7e05ef 100644 --- a/test/service/notifications/scheduler_test.exs +++ b/test/service/notifications/scheduler_test.exs @@ -249,7 +249,15 @@ defmodule Mobilizon.Service.Notifications.SchedulerTest do Scheduler.pending_participation_notification(event) - {:ok, scheduled_at} = NaiveDateTime.new(Date.utc_today(), ~T[18:00:00]) + now = Time.utc_now() + + {:ok, scheduled_at} = + if now.hour <= 18 do + NaiveDateTime.new(Date.utc_today(), ~T[18:00:00]) + else + Date.utc_today() |> Date.add(1) |> NaiveDateTime.new(~T[18:00:00]) + end + {:ok, scheduled_at} = DateTime.from_naive(scheduled_at, "Europe/Paris") assert_enqueued(