Fix tests with scheduler notifications

Close #390

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2020-11-27 15:47:34 +01:00
parent 74e59b2398
commit 10eb64720e
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
2 changed files with 12 additions and 7 deletions

View File

@ -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

View File

@ -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(