fix emails
This commit is contained in:
parent
179d67a896
commit
33e4d26a3d
@ -1,4 +1,5 @@
|
||||
# v0.9.11
|
||||
- Fix an issue with emails not being able to be sent for real this time
|
||||
- Update deps
|
||||
|
||||
# v0.9.10
|
||||
|
@ -32,4 +32,4 @@ config :logger, level: :warning
|
||||
config :phoenix, :plug_init_mode, :runtime
|
||||
|
||||
# Disable Oban
|
||||
config :cannery, Oban, queues: false, plugins: false
|
||||
config :cannery, Oban, queues: false, plugins: false, testing: :manual
|
||||
|
@ -26,21 +26,21 @@ defmodule Cannery.Email do
|
||||
end
|
||||
|
||||
@spec generate_email(key :: String.t(), User.t(), attrs :: map()) :: t()
|
||||
def generate_email("welcome", user, %{url: url}) do
|
||||
def generate_email("welcome", user, %{"url" => url}) do
|
||||
user
|
||||
|> base_email(dgettext("emails", "Confirm your Cannery account"))
|
||||
|> html_email(:confirm_email_html, %{user: user, url: url})
|
||||
|> text_email(:confirm_email_text, %{user: user, url: url})
|
||||
end
|
||||
|
||||
def generate_email("reset_password", user, %{url: url}) do
|
||||
def generate_email("reset_password", user, %{"url" => url}) do
|
||||
user
|
||||
|> base_email(dgettext("emails", "Reset your Cannery password"))
|
||||
|> html_email(:reset_password_html, %{user: user, url: url})
|
||||
|> text_email(:reset_password_text, %{user: user, url: url})
|
||||
end
|
||||
|
||||
def generate_email("update_email", user, %{url: url}) do
|
||||
def generate_email("update_email", user, %{"url" => url}) do
|
||||
user
|
||||
|> base_email(dgettext("emails", "Update your Cannery email"))
|
||||
|> html_email(:update_email_html, %{user: user, url: url})
|
@ -7,7 +7,7 @@ defmodule Cannery.EmailWorker do
|
||||
alias Cannery.{Accounts, Email, Mailer}
|
||||
|
||||
@impl Oban.Worker
|
||||
def perform(%Oban.Job{args: %{email: email, user_id: user_id, attrs: attrs}}) do
|
||||
def perform(%Oban.Job{args: %{"email" => email, "user_id" => user_id, "attrs" => attrs}}) do
|
||||
Email.generate_email(email, user_id |> Accounts.get_user!(), attrs) |> Mailer.deliver()
|
||||
end
|
||||
end
|
40
test/cannery/email_worker_test.exs
Normal file
40
test/cannery/email_worker_test.exs
Normal file
@ -0,0 +1,40 @@
|
||||
defmodule Cannery.EmailWorkerTest do
|
||||
use Cannery.DataCase, async: true
|
||||
|
||||
def perform_job(worker, args) do
|
||||
Oban.Testing.perform_job(worker, args, [])
|
||||
end
|
||||
|
||||
test "sending welcome email" do
|
||||
user = user_fixture()
|
||||
|
||||
{:ok, _user} =
|
||||
perform_job(Cannery.EmailWorker, %{
|
||||
"email" => "welcome",
|
||||
"user_id" => user.id,
|
||||
"attrs" => %{"url" => "test_url"}
|
||||
})
|
||||
end
|
||||
|
||||
test "sending reset password email" do
|
||||
user = user_fixture()
|
||||
|
||||
{:ok, _user} =
|
||||
perform_job(Cannery.EmailWorker, %{
|
||||
"email" => "reset_password",
|
||||
"user_id" => user.id,
|
||||
"attrs" => %{"url" => "test_url"}
|
||||
})
|
||||
end
|
||||
|
||||
test "sending update email email" do
|
||||
user = user_fixture()
|
||||
|
||||
{:ok, _user} =
|
||||
perform_job(Cannery.EmailWorker, %{
|
||||
"email" => "update_email",
|
||||
"user_id" => user.id,
|
||||
"attrs" => %{"url" => "test_url"}
|
||||
})
|
||||
end
|
||||
end
|
@ -48,6 +48,10 @@ defmodule Cannery.Fixtures do
|
||||
def extract_user_token(fun) do
|
||||
%{args: %{attrs: attrs, email: email_key, user_id: user_id}} = fun.(&"[TOKEN]#{&1}[TOKEN]")
|
||||
|
||||
attrs =
|
||||
attrs
|
||||
|> Map.new(fn {key, value} -> {Atom.to_string(key), value} end)
|
||||
|
||||
email =
|
||||
email_key
|
||||
|> Atom.to_string()
|
||||
|
Loading…
Reference in New Issue
Block a user