distraction.party/test/user/welcome_email_test.exs

50 lines
1.3 KiB
Elixir
Raw Normal View History

2020-07-22 05:58:06 +00:00
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# 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
welcome_user = insert(:user)
user = insert(:user, name: "Jimm")
Config.put([:welcome, :email, :enabled], true)
Config.put([:welcome, :email, :sender_nickname], welcome_user.nickname)
Config.put(
[:welcome, :email, :subject],
"Hello, welcome to pleroma: <%= instance_name %>"
)
Config.put(
[: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(
from: {instance_name, welcome_user.email},
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