Merge branch 'email-spam' into 'main'
Move mailer from Bamboo to Swoosh Closes #491 See merge request framasoft/mobilizon!1203
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
|
||||
|
||||
Reference in New Issue
Block a user