2020-07-21 23:58:06 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2022-02-25 23:11:42 -07:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2020-07-21 23:58:06 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.User.WelcomeEmailTest do
|
|
|
|
use Pleroma.DataCase
|
|
|
|
|
|
|
|
alias Pleroma.Config
|
|
|
|
alias Pleroma.Tests.ObanHelpers
|
|
|
|
alias Pleroma.User.WelcomeEmail
|
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
import Swoosh.TestAssertions
|
|
|
|
|
|
|
|
setup do: clear_config([:welcome])
|
|
|
|
|
|
|
|
describe "send_email/1" do
|
|
|
|
test "send a welcome email" do
|
|
|
|
user = insert(:user, name: "Jimm")
|
|
|
|
|
2021-01-26 10:58:43 -07:00
|
|
|
clear_config([:welcome, :email, :enabled], true)
|
|
|
|
clear_config([:welcome, :email, :sender], "welcome@pleroma.app")
|
2020-07-21 23:58:06 -06:00
|
|
|
|
2021-01-26 10:58:43 -07:00
|
|
|
clear_config(
|
2020-07-21 23:58:06 -06:00
|
|
|
[:welcome, :email, :subject],
|
|
|
|
"Hello, welcome to pleroma: <%= instance_name %>"
|
|
|
|
)
|
|
|
|
|
2021-01-26 10:58:43 -07:00
|
|
|
clear_config(
|
2020-07-21 23:58:06 -06:00
|
|
|
[:welcome, :email, :html],
|
|
|
|
"<h1>Hello <%= user.name %>.</h1> <p>Welcome to <%= instance_name %></p>"
|
|
|
|
)
|
|
|
|
|
|
|
|
instance_name = Config.get([:instance, :name])
|
|
|
|
|
|
|
|
{:ok, _job} = WelcomeEmail.send_email(user)
|
|
|
|
|
|
|
|
ObanHelpers.perform_all()
|
|
|
|
|
|
|
|
assert_email_sent(
|
2020-07-22 06:34:47 -06:00
|
|
|
from: {instance_name, "welcome@pleroma.app"},
|
|
|
|
to: {user.name, user.email},
|
|
|
|
subject: "Hello, welcome to pleroma: #{instance_name}",
|
|
|
|
html_body: "<h1>Hello #{user.name}.</h1> <p>Welcome to #{instance_name}</p>"
|
|
|
|
)
|
|
|
|
|
2021-01-26 10:58:43 -07:00
|
|
|
clear_config([:welcome, :email, :sender], {"Pleroma App", "welcome@pleroma.app"})
|
2020-07-22 06:34:47 -06:00
|
|
|
|
|
|
|
{:ok, _job} = WelcomeEmail.send_email(user)
|
|
|
|
|
|
|
|
ObanHelpers.perform_all()
|
|
|
|
|
|
|
|
assert_email_sent(
|
|
|
|
from: {"Pleroma App", "welcome@pleroma.app"},
|
2020-07-21 23:58:06 -06:00
|
|
|
to: {user.name, user.email},
|
|
|
|
subject: "Hello, welcome to pleroma: #{instance_name}",
|
|
|
|
html_body: "<h1>Hello #{user.name}.</h1> <p>Welcome to #{instance_name}</p>"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|