From 10eb64720ed55b71d6c13763a438e0e1f9b7e95d Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 27 Nov 2020 15:47:34 +0100 Subject: [PATCH] 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(