[#1062] added option to disable send email
parent
b00620b378
commit
12b1454245
@ -0,0 +1,37 @@
|
||||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Emails.AdminEmailTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Emails.AdminEmail
|
||||
alias Pleroma.Web.Router.Helpers
|
||||
|
||||
test "build report email" do
|
||||
config = Pleroma.Config.get(:instance)
|
||||
to_user = insert(:user)
|
||||
reporter = insert(:user)
|
||||
account = insert(:user)
|
||||
|
||||
res =
|
||||
AdminEmail.report(to_user, reporter, account, [%{name: "Test", id: "12"}], "Test comment")
|
||||
|
||||
status_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, "12")
|
||||
reporter_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :feed_redirect, reporter.nickname)
|
||||
account_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :feed_redirect, account.nickname)
|
||||
|
||||
assert res.to == [{to_user.name, to_user.email}]
|
||||
assert res.from == {config[:name], config[:notify_email]}
|
||||
assert res.reply_to == {reporter.name, reporter.email}
|
||||
assert res.subject == "#{config[:name]} Report"
|
||||
|
||||
assert res.html_body ==
|
||||
"<p>Reported by: <a href=\"#{reporter_url}\">#{reporter.nickname}</a></p>\n<p>Reported Account: <a href=\"#{
|
||||
account_url
|
||||
}\">#{account.nickname}</a></p>\n<p>Comment: Test comment\n<p> Statuses:\n <ul>\n <li><a href=\"#{
|
||||
status_url
|
||||
}\">#{status_url}</li>\n </ul>\n</p>\n\n"
|
||||
end
|
||||
end
|
@ -0,0 +1,57 @@
|
||||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Emails.MailerTest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Emails.Mailer
|
||||
|
||||
import Swoosh.TestAssertions
|
||||
|
||||
@email %Swoosh.Email{
|
||||
from: {"Pleroma", "noreply@example.com"},
|
||||
html_body: "Test email",
|
||||
subject: "Pleroma test email",
|
||||
to: [{"Test User", "user1@example.com"}]
|
||||
}
|
||||
|
||||
setup do
|
||||
value = Pleroma.Config.get([Pleroma.Emails.Mailer, :enabled])
|
||||
on_exit(fn -> Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], value) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
test "not send email when mailer is disabled" do
|
||||
Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
|
||||
Mailer.deliver(@email)
|
||||
|
||||
refute_email_sent(
|
||||
from: {"Pleroma", "noreply@example.com"},
|
||||
to: [{"Test User", "user1@example.com"}],
|
||||
html_body: "Test email",
|
||||
subject: "Pleroma test email"
|
||||
)
|
||||
end
|
||||
|
||||
test "send email" do
|
||||
Mailer.deliver(@email)
|
||||
|
||||
assert_email_sent(
|
||||
from: {"Pleroma", "noreply@example.com"},
|
||||
to: [{"Test User", "user1@example.com"}],
|
||||
html_body: "Test email",
|
||||
subject: "Pleroma test email"
|
||||
)
|
||||
end
|
||||
|
||||
test "perform" do
|
||||
Mailer.perform(:deliver_async, @email, [])
|
||||
|
||||
assert_email_sent(
|
||||
from: {"Pleroma", "noreply@example.com"},
|
||||
to: [{"Test User", "user1@example.com"}],
|
||||
html_body: "Test email",
|
||||
subject: "Pleroma test email"
|
||||
)
|
||||
end
|
||||
end
|
@ -0,0 +1,48 @@
|
||||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Emails.UserEmailTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Emails.UserEmail
|
||||
alias Pleroma.Web.Endpoint
|
||||
alias Pleroma.Web.Router
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "build password reset email" do
|
||||
config = Pleroma.Config.get(:instance)
|
||||
user = insert(:user)
|
||||
email = UserEmail.password_reset_email(user, "test_token")
|
||||
assert email.from == {config[:name], config[:notify_email]}
|
||||
assert email.to == [{user.name, user.email}]
|
||||
assert email.subject == "Password reset"
|
||||
assert email.html_body =~ Router.Helpers.reset_password_url(Endpoint, :reset, "test_token")
|
||||
end
|
||||
|
||||
test "build user invitation email" do
|
||||
config = Pleroma.Config.get(:instance)
|
||||
user = insert(:user)
|
||||
token = %Pleroma.UserInviteToken{token: "test-token"}
|
||||
email = UserEmail.user_invitation_email(user, token, "test@test.com", "Jonh")
|
||||
assert email.from == {config[:name], config[:notify_email]}
|
||||
assert email.subject == "Invitation to Pleroma"
|
||||
assert email.to == [{"Jonh", "test@test.com"}]
|
||||
|
||||
assert email.html_body =~
|
||||
Router.Helpers.redirect_url(Endpoint, :registration_page, token.token)
|
||||
end
|
||||
|
||||
test "build account confirmation email" do
|
||||
config = Pleroma.Config.get(:instance)
|
||||
user = insert(:user, info: %Pleroma.User.Info{confirmation_token: "conf-token"})
|
||||
email = UserEmail.account_confirmation_email(user)
|
||||
assert email.from == {config[:name], config[:notify_email]}
|
||||
assert email.to == [{user.name, user.email}]
|
||||
assert email.subject == "#{config[:name]} account confirmation"
|
||||
|
||||
assert email.html_body =~
|
||||
Router.Helpers.confirm_email_url(Endpoint, :confirm_email, user.id, "conf-token")
|
||||
end
|
||||
end
|
Loading…
Reference in new issue