Move mailer from Bamboo to Swoosh
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -1,14 +1,13 @@
|
||||
defmodule Mobilizon.GraphQL.Resolvers.AdminTest do
|
||||
use Mobilizon.Web.ConnCase
|
||||
use Bamboo.Test
|
||||
import Mobilizon.Factory
|
||||
import Swoosh.TestAssertions
|
||||
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Federation.ActivityPub.Relay
|
||||
alias Mobilizon.Reports.{Note, Report}
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.Web.Email
|
||||
|
||||
alias Mobilizon.GraphQL.{AbsintheHelpers, API}
|
||||
|
||||
@@ -563,13 +562,7 @@ defmodule Mobilizon.GraphQL.Resolvers.AdminTest do
|
||||
variables: %{"id" => user.id, "email" => "new@email.com", "notify" => false}
|
||||
)
|
||||
|
||||
refute_delivered_email(
|
||||
Email.Admin.user_email_change_old(%User{user | email: "new@email.com"}, user.email)
|
||||
)
|
||||
|
||||
refute_delivered_email(
|
||||
Email.Admin.user_email_change_new(%User{user | email: "new@email.com"}, user.email)
|
||||
)
|
||||
refute_email_sent()
|
||||
|
||||
assert res["errors"] == nil
|
||||
assert res["data"]["adminUpdateUser"]["email"] == "new@email.com"
|
||||
@@ -584,13 +577,18 @@ defmodule Mobilizon.GraphQL.Resolvers.AdminTest do
|
||||
variables: %{"id" => user.id, "email" => "new@email.com", "notify" => true}
|
||||
)
|
||||
|
||||
assert_delivered_email(
|
||||
Email.Admin.user_email_change_old(%User{user | email: "new@email.com"}, user.email)
|
||||
assert_email_sent(
|
||||
to: user.email,
|
||||
subject:
|
||||
"An administrator manually changed the email attached to your account on Test instance"
|
||||
)
|
||||
|
||||
assert_delivered_email(
|
||||
Email.Admin.user_email_change_new(%User{user | email: "new@email.com"}, user.email)
|
||||
)
|
||||
# # Swoosh.TestAssertions can't test multiple emails sent
|
||||
# assert_email_sent(
|
||||
# to: "new@email.com",
|
||||
# subject:
|
||||
# "An administrator manually changed the email attached to your account on Test instance"
|
||||
# )
|
||||
|
||||
assert res["errors"] == nil
|
||||
assert res["data"]["adminUpdateUser"]["email"] == "new@email.com"
|
||||
@@ -639,9 +637,7 @@ defmodule Mobilizon.GraphQL.Resolvers.AdminTest do
|
||||
variables: %{"id" => user.id, "role" => "MODERATOR", "notify" => false}
|
||||
)
|
||||
|
||||
refute_delivered_email(
|
||||
Email.Admin.user_role_change(%User{user | role: :moderator}, user.role)
|
||||
)
|
||||
refute_email_sent()
|
||||
|
||||
assert res["errors"] == nil
|
||||
assert res["data"]["adminUpdateUser"]["role"] == "MODERATOR"
|
||||
@@ -656,9 +652,7 @@ defmodule Mobilizon.GraphQL.Resolvers.AdminTest do
|
||||
variables: %{"id" => user.id, "role" => "MODERATOR", "notify" => true}
|
||||
)
|
||||
|
||||
assert_delivered_email(
|
||||
Email.Admin.user_role_change(%User{user | role: :moderator}, user.role)
|
||||
)
|
||||
assert_email_sent(to: user.email)
|
||||
|
||||
assert res["errors"] == nil
|
||||
assert res["data"]["adminUpdateUser"]["role"] == "MODERATOR"
|
||||
@@ -681,7 +675,7 @@ defmodule Mobilizon.GraphQL.Resolvers.AdminTest do
|
||||
variables: %{"id" => user.id, "confirmed" => true, "notify" => false}
|
||||
)
|
||||
|
||||
refute_delivered_email(Email.Admin.user_confirmation(user))
|
||||
refute_email_sent()
|
||||
|
||||
assert hd(res["errors"])["message"] == "Can't confirm an already confirmed user"
|
||||
end
|
||||
@@ -695,7 +689,7 @@ defmodule Mobilizon.GraphQL.Resolvers.AdminTest do
|
||||
variables: %{"id" => user.id, "confirmed" => false, "notify" => false}
|
||||
)
|
||||
|
||||
refute_delivered_email(Email.Admin.user_confirmation(user))
|
||||
refute_email_sent()
|
||||
|
||||
assert hd(res["errors"])["message"] == "Deconfirming users is not supported"
|
||||
end
|
||||
@@ -711,7 +705,7 @@ defmodule Mobilizon.GraphQL.Resolvers.AdminTest do
|
||||
variables: %{"id" => user.id, "confirmed" => true, "notify" => false}
|
||||
)
|
||||
|
||||
refute_delivered_email(Email.Admin.user_confirmation(user))
|
||||
refute_email_sent()
|
||||
|
||||
assert res["errors"] == nil
|
||||
refute res["data"]["adminUpdateUser"]["confirmedAt"] == nil
|
||||
@@ -728,7 +722,7 @@ defmodule Mobilizon.GraphQL.Resolvers.AdminTest do
|
||||
variables: %{"id" => user.id, "confirmed" => true, "notify" => true}
|
||||
)
|
||||
|
||||
assert_delivered_email(Email.Admin.user_confirmation(user))
|
||||
assert_email_sent(to: user.email)
|
||||
|
||||
assert res["errors"] == nil
|
||||
refute res["data"]["adminUpdateUser"]["confirmedAt"] == nil
|
||||
|
||||
@@ -2,7 +2,6 @@ defmodule Mobilizon.GraphQL.Resolvers.ConfigTest do
|
||||
use Mobilizon.Web.ConnCase
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
use Bamboo.Test
|
||||
|
||||
alias Mobilizon.GraphQL.AbsintheHelpers
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
defmodule Mobilizon.Web.Resolvers.EventTest do
|
||||
use Mobilizon.Web.ConnCase
|
||||
use Bamboo.Test, shared: true
|
||||
use Oban.Testing, repo: Mobilizon.Storage.Repo
|
||||
|
||||
import Mobilizon.Factory
|
||||
@@ -12,8 +11,7 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
alias Mobilizon.GraphQL.AbsintheHelpers
|
||||
|
||||
alias Mobilizon.Web.Email
|
||||
import Swoosh.TestAssertions
|
||||
|
||||
@event %{
|
||||
description: "some body",
|
||||
@@ -981,12 +979,11 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
|
||||
%Event{uuid: event_uuid, title: event_title} =
|
||||
event = insert(:event, organizer_actor: actor)
|
||||
|
||||
creator = insert(:participant, event: event, actor: actor, role: :creator)
|
||||
insert(:participant, event: event, actor: actor, role: :creator)
|
||||
participant_user = insert(:user)
|
||||
participant_actor = insert(:actor, user: participant_user)
|
||||
|
||||
participant =
|
||||
insert(:participant, event: event, actor: participant_actor, role: :participant)
|
||||
insert(:participant, event: event, actor: participant_actor, role: :participant)
|
||||
|
||||
address = insert(:address)
|
||||
|
||||
@@ -1073,33 +1070,10 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
|
||||
|
||||
Oban.drain_queue(queue: :default, with_scheduled: true)
|
||||
|
||||
{:ok, new_event} = Mobilizon.Events.get_event_with_preload(event.id)
|
||||
{:ok, _new_event} = Mobilizon.Events.get_event_with_preload(event.id)
|
||||
|
||||
assert_delivered_email(
|
||||
Email.Event.event_updated(
|
||||
user.email,
|
||||
creator,
|
||||
actor,
|
||||
event,
|
||||
new_event,
|
||||
MapSet.new([:title, :begins_on, :ends_on, :status, :physical_address]),
|
||||
"Etc/UTC",
|
||||
"en"
|
||||
)
|
||||
)
|
||||
|
||||
assert_delivered_email(
|
||||
Email.Event.event_updated(
|
||||
participant_user.email,
|
||||
participant,
|
||||
participant_actor,
|
||||
event,
|
||||
new_event,
|
||||
MapSet.new([:title, :begins_on, :ends_on, :status, :physical_address]),
|
||||
"Etc/UTC",
|
||||
"en"
|
||||
)
|
||||
)
|
||||
assert_email_sent(to: {actor.name, user.email})
|
||||
assert_email_sent(to: {participant_actor.name, participant_user.email})
|
||||
end
|
||||
|
||||
test "update_event/3 updates an event with a new picture", %{
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
defmodule Mobilizon.GraphQL.Resolvers.MediaTest do
|
||||
use Mobilizon.Web.ConnCase
|
||||
use Bamboo.Test
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
defmodule Mobilizon.GraphQL.Resolvers.ParticipantTest do
|
||||
use Mobilizon.Web.ConnCase
|
||||
use Bamboo.Test
|
||||
use Mobilizon.Tests.Helpers
|
||||
|
||||
alias Mobilizon.Config
|
||||
@@ -8,9 +7,9 @@ defmodule Mobilizon.GraphQL.Resolvers.ParticipantTest do
|
||||
alias Mobilizon.Events.{Event, EventParticipantStats, Participant}
|
||||
alias Mobilizon.GraphQL.AbsintheHelpers
|
||||
alias Mobilizon.Storage.Page
|
||||
alias Mobilizon.Web.Email
|
||||
|
||||
import Mobilizon.Factory
|
||||
import Swoosh.TestAssertions
|
||||
|
||||
@event %{
|
||||
description: "some body",
|
||||
@@ -720,9 +719,9 @@ defmodule Mobilizon.GraphQL.Resolvers.ParticipantTest do
|
||||
assert json_response(res, 200)["data"]["updateParticipation"]["actor"]["id"] ==
|
||||
to_string(actor.id)
|
||||
|
||||
participation = Events.get_participant(participation_id)
|
||||
assert %Participant{} = Events.get_participant(participation_id)
|
||||
|
||||
assert_delivered_email(Email.Participation.participation_updated(user, participation))
|
||||
assert_email_sent(to: user.email)
|
||||
|
||||
res =
|
||||
conn
|
||||
@@ -864,8 +863,8 @@ defmodule Mobilizon.GraphQL.Resolvers.ParticipantTest do
|
||||
assert json_response(res, 200)["data"]["updateParticipation"]["actor"]["id"] ==
|
||||
to_string(actor.id)
|
||||
|
||||
participation = Events.get_participant(participation_id)
|
||||
assert_delivered_email(Email.Participation.participation_updated(user, participation))
|
||||
assert %Participant{} = Events.get_participant(participation_id)
|
||||
assert_email_sent(to: user.email)
|
||||
|
||||
res =
|
||||
conn
|
||||
@@ -1112,12 +1111,7 @@ defmodule Mobilizon.GraphQL.Resolvers.ParticipantTest do
|
||||
assert %Participant{
|
||||
metadata: %{confirmation_token: confirmation_token},
|
||||
role: :not_confirmed
|
||||
} =
|
||||
participant =
|
||||
event.id |> Events.list_participants_for_event([]) |> Map.get(:elements) |> hd()
|
||||
|
||||
# hack to avoid preloading event in participant
|
||||
participant = Map.put(participant, :event, event)
|
||||
} = event.id |> Events.list_participants_for_event([]) |> Map.get(:elements) |> hd()
|
||||
|
||||
res =
|
||||
conn
|
||||
@@ -1128,9 +1122,7 @@ defmodule Mobilizon.GraphQL.Resolvers.ParticipantTest do
|
||||
|
||||
assert hd(res["errors"])["message"] == "You are already a participant of this event"
|
||||
|
||||
assert_delivered_email(
|
||||
Email.Participation.anonymous_participation_confirmation(@email, participant)
|
||||
)
|
||||
assert_email_sent(to: @email)
|
||||
|
||||
res =
|
||||
conn
|
||||
@@ -1142,10 +1134,9 @@ defmodule Mobilizon.GraphQL.Resolvers.ParticipantTest do
|
||||
assert is_nil(res["errors"])
|
||||
|
||||
assert %Participant{role: :participant} =
|
||||
participant =
|
||||
event.id |> Events.list_participants_for_event() |> Map.get(:elements) |> hd()
|
||||
|
||||
assert_delivered_email(Email.Participation.participation_updated(@email, participant))
|
||||
assert_email_sent(to: @email)
|
||||
end
|
||||
|
||||
test "I can participate anonymously and and confirm my participation with bad token",
|
||||
@@ -1377,8 +1368,8 @@ defmodule Mobilizon.GraphQL.Resolvers.ParticipantTest do
|
||||
}
|
||||
}} = Events.get_event(event.id)
|
||||
|
||||
participant = Events.get_participant(participant_id)
|
||||
assert_delivered_email(Email.Participation.participation_updated(@email, participant))
|
||||
assert %Participant{} = Events.get_participant(participant_id)
|
||||
assert_email_sent(to: @email)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
defmodule Mobilizon.GraphQL.Resolvers.UserTest do
|
||||
use Mobilizon.Web.ConnCase
|
||||
use Bamboo.Test
|
||||
use Oban.Testing, repo: Mobilizon.Storage.Repo
|
||||
|
||||
import Mobilizon.Factory
|
||||
@@ -15,6 +14,7 @@ defmodule Mobilizon.GraphQL.Resolvers.UserTest do
|
||||
alias Mobilizon.GraphQL.AbsintheHelpers
|
||||
|
||||
alias Mobilizon.Web.Email
|
||||
import Swoosh.TestAssertions
|
||||
|
||||
@get_user_query """
|
||||
query GetUser($id: ID!) {
|
||||
@@ -362,7 +362,7 @@ defmodule Mobilizon.GraphQL.Resolvers.UserTest do
|
||||
|
||||
{:ok, user} = Users.get_user_by_email(@user_creation.email)
|
||||
|
||||
assert_delivered_email(Email.User.confirmation_email(user, @user_creation.locale))
|
||||
assert_email_sent(to: user.email)
|
||||
|
||||
res =
|
||||
conn
|
||||
@@ -705,7 +705,7 @@ defmodule Mobilizon.GraphQL.Resolvers.UserTest do
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|
||||
assert json_response(res, 200)["data"]["resendConfirmationEmail"] == user.email
|
||||
assert_delivered_email(Email.User.confirmation_email(user))
|
||||
assert_email_sent(to: user.email)
|
||||
end
|
||||
|
||||
test "test resend_confirmation_email/3 with invalid email resends an validation email",
|
||||
@@ -1279,8 +1279,8 @@ defmodule Mobilizon.GraphQL.Resolvers.UserTest do
|
||||
assert user.email == @old_email
|
||||
assert user.unconfirmed_email == @new_email
|
||||
|
||||
assert_delivered_email(Email.User.send_email_reset_old_email(user))
|
||||
assert_delivered_email(Email.User.send_email_reset_new_email(user))
|
||||
assert_email_sent(to: user.email)
|
||||
assert_email_sent(to: user.unconfirmed_email)
|
||||
|
||||
conn
|
||||
|> AbsintheHelpers.graphql_query(
|
||||
@@ -1329,8 +1329,8 @@ defmodule Mobilizon.GraphQL.Resolvers.UserTest do
|
||||
assert user.email == @old_email
|
||||
assert user.unconfirmed_email == @new_email
|
||||
|
||||
assert_delivered_email(Email.User.send_email_reset_old_email(user))
|
||||
assert_delivered_email(Email.User.send_email_reset_new_email(user))
|
||||
assert_email_sent(to: user.email)
|
||||
assert_email_sent(to: user.unconfirmed_email)
|
||||
|
||||
res =
|
||||
conn
|
||||
|
||||
@@ -7,11 +7,9 @@ defmodule Mobilizon.Service.Notifier.EmailTest do
|
||||
alias Mobilizon.Config
|
||||
alias Mobilizon.Service.Notifier.Email
|
||||
alias Mobilizon.Users.{ActivitySetting, Setting, User}
|
||||
alias Mobilizon.Web.Email.Activity, as: EmailActivity
|
||||
|
||||
use Mobilizon.DataCase
|
||||
use Bamboo.Test
|
||||
|
||||
import Swoosh.TestAssertions
|
||||
import Mobilizon.Factory
|
||||
|
||||
describe "Returns if the module is loaded" do
|
||||
@@ -35,12 +33,7 @@ defmodule Mobilizon.Service.Notifier.EmailTest do
|
||||
|
||||
assert {:ok, :skipped} == Email.send(user, activity)
|
||||
|
||||
refute_delivered_email(
|
||||
EmailActivity.direct_activity(
|
||||
user.email,
|
||||
[activity]
|
||||
)
|
||||
)
|
||||
refute_email_sent()
|
||||
end
|
||||
|
||||
test "when the user allows it" do
|
||||
@@ -57,12 +50,7 @@ defmodule Mobilizon.Service.Notifier.EmailTest do
|
||||
|
||||
assert {:ok, :sent} == Email.send(user, activity)
|
||||
|
||||
assert_delivered_email(
|
||||
EmailActivity.direct_activity(
|
||||
user.email,
|
||||
[activity]
|
||||
)
|
||||
)
|
||||
assert_email_sent(to: user.email)
|
||||
end
|
||||
|
||||
test "if it's been an hour since the last notification" do
|
||||
@@ -84,12 +72,7 @@ defmodule Mobilizon.Service.Notifier.EmailTest do
|
||||
|
||||
assert {:ok, :sent} == Email.send(user, activity)
|
||||
|
||||
assert_delivered_email(
|
||||
EmailActivity.direct_activity(
|
||||
user.email,
|
||||
[activity]
|
||||
)
|
||||
)
|
||||
assert_email_sent(to: user.email)
|
||||
end
|
||||
|
||||
test "if there's no delay since the last notification" do
|
||||
@@ -111,12 +94,7 @@ defmodule Mobilizon.Service.Notifier.EmailTest do
|
||||
|
||||
assert {:ok, :sent} == Email.send(user, activity)
|
||||
|
||||
assert_delivered_email(
|
||||
EmailActivity.direct_activity(
|
||||
user.email,
|
||||
[activity]
|
||||
)
|
||||
)
|
||||
assert_email_sent(to: user.email)
|
||||
end
|
||||
|
||||
test "not if we already have sent notifications" do
|
||||
@@ -138,12 +116,7 @@ defmodule Mobilizon.Service.Notifier.EmailTest do
|
||||
|
||||
assert {:ok, :skipped} == Email.send(user, activity)
|
||||
|
||||
refute_delivered_email(
|
||||
EmailActivity.direct_activity(
|
||||
user.email,
|
||||
[activity]
|
||||
)
|
||||
)
|
||||
refute_email_sent()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -155,7 +128,7 @@ defmodule Mobilizon.Service.Notifier.EmailTest do
|
||||
|
||||
Email.send_anonymous_activity(@email, activity, locale: "en")
|
||||
|
||||
assert_delivered_email(EmailActivity.anonymous_activity(@email, activity, locale: "en"))
|
||||
assert_email_sent(to: @email)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,7 +9,6 @@ defmodule Mobilizon.Service.Notifier.PushTest do
|
||||
alias Mobilizon.Users.{ActivitySetting, Setting, User}
|
||||
|
||||
use Mobilizon.DataCase
|
||||
use Bamboo.Test
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
||||
|
||||
@@ -8,13 +8,14 @@ defmodule Mobilizon.Service.Workers.NotificationTest do
|
||||
alias Mobilizon.Events.{Event, Participant}
|
||||
alias Mobilizon.Service.Workers.Notification
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.Web.Email.Notification, as: NotificationMailer
|
||||
|
||||
use Mobilizon.DataCase
|
||||
use Bamboo.Test
|
||||
|
||||
import Swoosh.TestAssertions
|
||||
import Mobilizon.Factory
|
||||
|
||||
@email "someone@somewhere.tld"
|
||||
|
||||
describe "A before_event_notification job sends an email" do
|
||||
test "if the user is still participating" do
|
||||
%User{id: user_id} = user = insert(:user)
|
||||
@@ -36,12 +37,7 @@ defmodule Mobilizon.Service.Workers.NotificationTest do
|
||||
args: %{"op" => "before_event_notification", "participant_id" => participant_id}
|
||||
})
|
||||
|
||||
assert_delivered_email(
|
||||
NotificationMailer.before_event_notification(
|
||||
participant.actor.user.email,
|
||||
participant
|
||||
)
|
||||
)
|
||||
assert_email_sent(to: participant.actor.user.email)
|
||||
end
|
||||
|
||||
test "unless the person is no longer participating" do
|
||||
@@ -63,30 +59,19 @@ defmodule Mobilizon.Service.Workers.NotificationTest do
|
||||
args: %{"op" => "before_event_notification", "participant_id" => participant_id}
|
||||
})
|
||||
|
||||
refute_delivered_email(
|
||||
NotificationMailer.before_event_notification(
|
||||
participant.actor.user.email,
|
||||
participant
|
||||
)
|
||||
)
|
||||
refute_email_sent()
|
||||
end
|
||||
|
||||
test "unless the event has been cancelled" do
|
||||
%Event{} = event = insert(:event, status: :cancelled)
|
||||
|
||||
%Participant{id: participant_id} =
|
||||
participant = insert(:participant, role: :participant, event: event)
|
||||
%Participant{id: participant_id} = insert(:participant, role: :participant, event: event)
|
||||
|
||||
Notification.perform(%Oban.Job{
|
||||
args: %{"op" => "before_event_notification", "participant_id" => participant_id}
|
||||
})
|
||||
|
||||
refute_delivered_email(
|
||||
NotificationMailer.before_event_notification(
|
||||
participant.actor.user.email,
|
||||
participant
|
||||
)
|
||||
)
|
||||
refute_email_sent()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -100,19 +85,13 @@ defmodule Mobilizon.Service.Workers.NotificationTest do
|
||||
user = Map.put(user, :settings, settings)
|
||||
%Actor{} = actor = insert(:actor, user: user)
|
||||
|
||||
%Participant{} = participant = insert(:participant, role: :participant, actor: actor)
|
||||
%Participant{} = insert(:participant, role: :participant, actor: actor)
|
||||
|
||||
Notification.perform(%Oban.Job{
|
||||
args: %{"op" => "on_day_notification", "user_id" => user_id}
|
||||
})
|
||||
|
||||
assert_delivered_email(
|
||||
NotificationMailer.on_day_notification(
|
||||
user,
|
||||
[participant],
|
||||
1
|
||||
)
|
||||
)
|
||||
assert_email_sent(to: user.email)
|
||||
end
|
||||
|
||||
test "unless the person is no longer participating" do
|
||||
@@ -138,13 +117,7 @@ defmodule Mobilizon.Service.Workers.NotificationTest do
|
||||
args: %{"op" => "on_day_notification", "user_id" => user_id}
|
||||
})
|
||||
|
||||
refute_delivered_email(
|
||||
NotificationMailer.on_day_notification(
|
||||
user,
|
||||
[participant],
|
||||
1
|
||||
)
|
||||
)
|
||||
refute_email_sent()
|
||||
end
|
||||
|
||||
test "unless the event has been cancelled" do
|
||||
@@ -157,24 +130,17 @@ defmodule Mobilizon.Service.Workers.NotificationTest do
|
||||
%Actor{} = actor = insert(:actor, user: user)
|
||||
%Event{} = event = insert(:event, status: :cancelled)
|
||||
|
||||
%Participant{} =
|
||||
participant = insert(:participant, role: :participant, event: event, actor: actor)
|
||||
%Participant{} = insert(:participant, role: :participant, event: event, actor: actor)
|
||||
|
||||
Notification.perform(%Oban.Job{
|
||||
args: %{"op" => "on_day_notification", "user_id" => user_id}
|
||||
})
|
||||
|
||||
refute_delivered_email(
|
||||
NotificationMailer.on_day_notification(
|
||||
user,
|
||||
[participant],
|
||||
1
|
||||
)
|
||||
)
|
||||
refute_email_sent()
|
||||
end
|
||||
|
||||
test "with a lot of events" do
|
||||
%User{id: user_id} = user = insert(:user)
|
||||
%User{id: user_id} = user = insert(:user, email: @email)
|
||||
|
||||
settings =
|
||||
insert(:settings, user_id: user_id, notification_on_day: true, timezone: "Europe/Paris")
|
||||
@@ -182,23 +148,16 @@ defmodule Mobilizon.Service.Workers.NotificationTest do
|
||||
user = Map.put(user, :settings, settings)
|
||||
%Actor{} = actor = insert(:actor, user: user)
|
||||
|
||||
participants =
|
||||
Enum.reduce(0..10, [], fn _i, acc ->
|
||||
%Participant{} = participant = insert(:participant, role: :participant, actor: actor)
|
||||
acc ++ [participant]
|
||||
end)
|
||||
Enum.reduce(0..10, [], fn _i, acc ->
|
||||
%Participant{} = participant = insert(:participant, role: :participant, actor: actor)
|
||||
acc ++ [participant]
|
||||
end)
|
||||
|
||||
Notification.perform(%Oban.Job{
|
||||
args: %{"op" => "on_day_notification", "user_id" => user_id}
|
||||
})
|
||||
|
||||
refute_delivered_email(
|
||||
NotificationMailer.on_day_notification(
|
||||
user,
|
||||
participants,
|
||||
3
|
||||
)
|
||||
)
|
||||
assert_email_sent(to: @email, subject: "11 events planned today")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -212,19 +171,13 @@ defmodule Mobilizon.Service.Workers.NotificationTest do
|
||||
user = Map.put(user, :settings, settings)
|
||||
%Actor{} = actor = insert(:actor, user: user)
|
||||
|
||||
%Participant{} = participant = insert(:participant, role: :participant, actor: actor)
|
||||
%Participant{} = insert(:participant, role: :participant, actor: actor)
|
||||
|
||||
Notification.perform(%Oban.Job{
|
||||
args: %{"op" => "weekly_notification", "user_id" => user_id}
|
||||
})
|
||||
|
||||
assert_delivered_email(
|
||||
NotificationMailer.weekly_notification(
|
||||
user,
|
||||
[participant],
|
||||
1
|
||||
)
|
||||
)
|
||||
assert_email_sent(to: user.email)
|
||||
end
|
||||
|
||||
test "unless the person is no longer participating" do
|
||||
@@ -250,13 +203,7 @@ defmodule Mobilizon.Service.Workers.NotificationTest do
|
||||
args: %{"op" => "weekly_notification", "user_id" => user_id}
|
||||
})
|
||||
|
||||
refute_delivered_email(
|
||||
NotificationMailer.weekly_notification(
|
||||
user,
|
||||
[participant],
|
||||
1
|
||||
)
|
||||
)
|
||||
refute_email_sent()
|
||||
end
|
||||
|
||||
test "unless the event has been cancelled" do
|
||||
@@ -269,24 +216,17 @@ defmodule Mobilizon.Service.Workers.NotificationTest do
|
||||
%Actor{} = actor = insert(:actor, user: user)
|
||||
%Event{} = event = insert(:event, status: :cancelled)
|
||||
|
||||
%Participant{} =
|
||||
participant = insert(:participant, role: :participant, event: event, actor: actor)
|
||||
%Participant{} = insert(:participant, role: :participant, event: event, actor: actor)
|
||||
|
||||
Notification.perform(%Oban.Job{
|
||||
args: %{"op" => "weekly_notification", "user_id" => user_id}
|
||||
})
|
||||
|
||||
refute_delivered_email(
|
||||
NotificationMailer.weekly_notification(
|
||||
user,
|
||||
[participant],
|
||||
1
|
||||
)
|
||||
)
|
||||
refute_email_sent()
|
||||
end
|
||||
|
||||
test "with a lot of events" do
|
||||
%User{id: user_id} = user = insert(:user)
|
||||
%User{id: user_id} = user = insert(:user, email: @email)
|
||||
|
||||
settings =
|
||||
insert(:settings, user_id: user_id, notification_each_week: true, timezone: "Europe/Paris")
|
||||
@@ -294,23 +234,16 @@ defmodule Mobilizon.Service.Workers.NotificationTest do
|
||||
user = Map.put(user, :settings, settings)
|
||||
%Actor{} = actor = insert(:actor, user: user)
|
||||
|
||||
participants =
|
||||
Enum.reduce(0..10, [], fn _i, acc ->
|
||||
%Participant{} = participant = insert(:participant, role: :participant, actor: actor)
|
||||
acc ++ [participant]
|
||||
end)
|
||||
Enum.reduce(0..10, [], fn _i, acc ->
|
||||
%Participant{} = participant = insert(:participant, role: :participant, actor: actor)
|
||||
acc ++ [participant]
|
||||
end)
|
||||
|
||||
Notification.perform(%Oban.Job{
|
||||
args: %{"op" => "weekly_notification", "user_id" => user_id}
|
||||
})
|
||||
|
||||
refute_delivered_email(
|
||||
NotificationMailer.weekly_notification(
|
||||
user,
|
||||
participants,
|
||||
3
|
||||
)
|
||||
)
|
||||
assert_email_sent(to: @email, subject: "11 events planned this week")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -318,11 +251,10 @@ defmodule Mobilizon.Service.Workers.NotificationTest do
|
||||
test "if there are participants to approve" do
|
||||
%User{id: user_id} = user = insert(:user)
|
||||
|
||||
settings =
|
||||
insert(:settings,
|
||||
user_id: user_id,
|
||||
timezone: "Europe/Paris"
|
||||
)
|
||||
insert(:settings,
|
||||
user_id: user_id,
|
||||
timezone: "Europe/Paris"
|
||||
)
|
||||
|
||||
%Event{id: event_id} = event = insert(:event)
|
||||
|
||||
@@ -337,13 +269,7 @@ defmodule Mobilizon.Service.Workers.NotificationTest do
|
||||
}
|
||||
})
|
||||
|
||||
assert_delivered_email(
|
||||
NotificationMailer.pending_participation_notification(
|
||||
%User{user | settings: settings},
|
||||
event,
|
||||
2
|
||||
)
|
||||
)
|
||||
assert_email_sent(to: user.email)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user