From eeef7c94cd432cba238a853cfdedd346e4c311d5 Mon Sep 17 00:00:00 2001 From: shibao Date: Sun, 28 Jul 2024 13:00:53 -0400 Subject: [PATCH] fix emails --- changelog.md | 1 + config/test.exs | 2 +- lib/memex/{accounts => }/email.ex | 0 lib/memex/{accounts => }/email_worker.ex | 0 priv/gettext/de/LC_MESSAGES/emails.po | 6 ++-- priv/gettext/emails.pot | 6 ++-- priv/gettext/en/LC_MESSAGES/emails.po | 6 ++-- test/memex/email_worker_test.exs | 40 ++++++++++++++++++++++++ test/support/fixtures.ex | 5 +-- 9 files changed, 54 insertions(+), 12 deletions(-) rename lib/memex/{accounts => }/email.ex (100%) rename lib/memex/{accounts => }/email_worker.ex (100%) create mode 100644 test/memex/email_worker_test.exs diff --git a/changelog.md b/changelog.md index ca8c096..88f2b0c 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,7 @@ # v0.1.16 - Fix empty invite index page - Fix faq copy +- Fix issue with emails - Update deps # v0.1.15 diff --git a/config/test.exs b/config/test.exs index 6096bf1..b13bf60 100644 --- a/config/test.exs +++ b/config/test.exs @@ -32,4 +32,4 @@ config :logger, level: :warning config :phoenix, :plug_init_mode, :runtime # Disable Oban -config :memex, Oban, queues: false, plugins: false +config :memex, Oban, queues: false, plugins: false, testing: :manual diff --git a/lib/memex/accounts/email.ex b/lib/memex/email.ex similarity index 100% rename from lib/memex/accounts/email.ex rename to lib/memex/email.ex diff --git a/lib/memex/accounts/email_worker.ex b/lib/memex/email_worker.ex similarity index 100% rename from lib/memex/accounts/email_worker.ex rename to lib/memex/email_worker.ex diff --git a/priv/gettext/de/LC_MESSAGES/emails.po b/priv/gettext/de/LC_MESSAGES/emails.po index 48a8bef..2ea4f8e 100644 --- a/priv/gettext/de/LC_MESSAGES/emails.po +++ b/priv/gettext/de/LC_MESSAGES/emails.po @@ -66,12 +66,12 @@ msgstr "" msgid "Welcome to memEx" msgstr "" -#: lib/memex/accounts/email.ex:31 +#: lib/memex/email.ex:31 #, elixir-autogen, elixir-format, fuzzy msgid "confirm your memEx account" msgstr "" -#: lib/memex/accounts/email.ex:37 +#: lib/memex/email.ex:37 #, elixir-autogen, elixir-format, fuzzy msgid "reset your memEx password" msgstr "" @@ -86,7 +86,7 @@ msgstr "" msgid "this email was sent from memEx at %{url}" msgstr "" -#: lib/memex/accounts/email.ex:43 +#: lib/memex/email.ex:43 #, elixir-autogen, elixir-format, fuzzy msgid "update your memEx email" msgstr "" diff --git a/priv/gettext/emails.pot b/priv/gettext/emails.pot index 2c0d03f..9751bc8 100644 --- a/priv/gettext/emails.pot +++ b/priv/gettext/emails.pot @@ -66,12 +66,12 @@ msgstr "" msgid "Welcome to memEx" msgstr "" -#: lib/memex/accounts/email.ex:31 +#: lib/memex/email.ex:31 #, elixir-autogen, elixir-format msgid "confirm your memEx account" msgstr "" -#: lib/memex/accounts/email.ex:37 +#: lib/memex/email.ex:37 #, elixir-autogen, elixir-format msgid "reset your memEx password" msgstr "" @@ -86,7 +86,7 @@ msgstr "" msgid "this email was sent from memEx at %{url}" msgstr "" -#: lib/memex/accounts/email.ex:43 +#: lib/memex/email.ex:43 #, elixir-autogen, elixir-format msgid "update your memEx email" msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/emails.po b/priv/gettext/en/LC_MESSAGES/emails.po index a14625e..c1f0a59 100644 --- a/priv/gettext/en/LC_MESSAGES/emails.po +++ b/priv/gettext/en/LC_MESSAGES/emails.po @@ -67,12 +67,12 @@ msgstr "" msgid "Welcome to memEx" msgstr "" -#: lib/memex/accounts/email.ex:31 +#: lib/memex/email.ex:31 #, elixir-autogen, elixir-format, fuzzy msgid "confirm your memEx account" msgstr "" -#: lib/memex/accounts/email.ex:37 +#: lib/memex/email.ex:37 #, elixir-autogen, elixir-format, fuzzy msgid "reset your memEx password" msgstr "" @@ -87,7 +87,7 @@ msgstr "" msgid "this email was sent from memEx at %{url}" msgstr "" -#: lib/memex/accounts/email.ex:43 +#: lib/memex/email.ex:43 #, elixir-autogen, elixir-format, fuzzy msgid "update your memEx email" msgstr "" diff --git a/test/memex/email_worker_test.exs b/test/memex/email_worker_test.exs new file mode 100644 index 0000000..3fb46e6 --- /dev/null +++ b/test/memex/email_worker_test.exs @@ -0,0 +1,40 @@ +defmodule Memex.EmailWorkerTest do + use Memex.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(Memex.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(Memex.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(Memex.EmailWorker, %{ + "email" => "update_email", + "user_id" => user.id, + "attrs" => %{"url" => "test_url"} + }) + end +end diff --git a/test/support/fixtures.ex b/test/support/fixtures.ex index bd78e1c..83afbcd 100644 --- a/test/support/fixtures.ex +++ b/test/support/fixtures.ex @@ -38,8 +38,9 @@ defmodule Memex.Fixtures do def extract_user_token(fun) do %{args: %{attrs: attrs, email: email_key, user_id: user_id}} = fun.(&"[TOKEN]#{&1}[TOKEN]") - # convert atoms to string keys - attrs = attrs |> Map.new(fn {atom_key, value} -> {atom_key |> Atom.to_string(), value} end) + attrs = + attrs + |> Map.new(fn {key, value} -> {Atom.to_string(key), value} end) email = email_key