From ac2a2fbe66a38ce7b966efcb02a86deb1dc8e925 Mon Sep 17 00:00:00 2001 From: Buck Doyle Date: Mon, 27 Nov 2023 22:14:12 -0600 Subject: [PATCH] Update registrations from email for unmnemonic --- .../lib/adventure_registrations/mailer.ex | 30 ++++++++----- .../test/integration/questions_test.exs | 4 +- .../test/integration/registrations_test.exs | 43 ++++++++++++++++++- 3 files changed, 63 insertions(+), 14 deletions(-) diff --git a/registrations/lib/adventure_registrations/mailer.ex b/registrations/lib/adventure_registrations/mailer.ex index fa06727e..1eb2be2c 100644 --- a/registrations/lib/adventure_registrations/mailer.ex +++ b/registrations/lib/adventure_registrations/mailer.ex @@ -11,7 +11,7 @@ defmodule AdventureRegistrations.Mailer do def send_welcome_email(email) do new() |> to(email) - |> from(@from) + |> from(adventure_from()) |> subject("[#{phrase("email_title")}] Welcome!") |> html_body(welcome_html()) |> text_body(welcome_text()) @@ -20,8 +20,8 @@ defmodule AdventureRegistrations.Mailer do def send_question(attributes) do new() - |> to("b@events.chromatin.ca") - |> from(@from) + |> to(adventure_from()) + |> from(adventure_from()) |> subject( "Question from #{attributes["name"]} <#{attributes["email"]}>: #{attributes["subject"]}" ) @@ -31,8 +31,8 @@ defmodule AdventureRegistrations.Mailer do def send_user_changes(user, changes) do new() - |> to(@from) - |> from(@from) + |> to(adventure_from()) + |> from(adventure_from()) |> subject("#{user.email} details changed: #{Enum.join(Map.keys(changes), ", ")}") |> text_body(inspect(changes)) |> deliver @@ -40,8 +40,8 @@ defmodule AdventureRegistrations.Mailer do def send_user_deletion(user) do new() - |> to(@from) - |> from(@from) + |> to(adventure_from()) + |> from(adventure_from()) |> subject("#{user.email} deleted their account") |> text_body(inspect(user)) |> deliver @@ -49,8 +49,8 @@ defmodule AdventureRegistrations.Mailer do def send_registration(user) do new() - |> to(@from) - |> from(@from) + |> to(adventure_from()) + |> from(adventure_from()) |> subject("#{user.email} registered") |> text_body("Yes") |> deliver @@ -75,7 +75,7 @@ defmodule AdventureRegistrations.Mailer do new() |> to(user.email) - |> from(@from) + |> from(adventure_from()) |> subject("[#{phrase("email_title")}] #{subject}") |> text_body(backlog_text(messages)) |> html_body(backlog_html(messages)) @@ -87,7 +87,7 @@ defmodule AdventureRegistrations.Mailer do def send_password_reset(user) do new() |> to(user.email) - |> from(@from) + |> from(adventure_from()) |> subject("[#{phrase("email_title")}] Password reset") |> html_body( "Here is a password reset link" @@ -149,6 +149,14 @@ defmodule AdventureRegistrations.Mailer do end end + defp adventure_from() do + if AdventureRegistrationsWeb.SharedHelpers.is_unmnemonic_devices() do + "knut@chromatin.ca" + else + @from + end + end + def message_from_string(message) do case message.from_address do "" -> nil diff --git a/registrations/test/integration/questions_test.exs b/registrations/test/integration/questions_test.exs index 90cedbb3..daeed0bb 100644 --- a/registrations/test/integration/questions_test.exs +++ b/registrations/test/integration/questions_test.exs @@ -65,8 +65,8 @@ defmodule AdventureRegistrations.UnmnemonicDevices.Integration.Questions do assert Nav.info_text() == "Your question has been submitted." [sent_email] = AdventureRegistrations.SwooshHelper.sent_email() - assert sent_email.to == [{"", "b@events.chromatin.ca"}] - assert sent_email.from == {"", "b@events.chromatin.ca"} + assert sent_email.to == [{"", "knut@chromatin.ca"}] + assert sent_email.from == {"", "knut@chromatin.ca"} assert sent_email.subject == "Question from Lucy Parsons : A Word to Tramps" diff --git a/registrations/test/integration/registrations_test.exs b/registrations/test/integration/registrations_test.exs index 71ebd67a..cfbcf3d4 100644 --- a/registrations/test/integration/registrations_test.exs +++ b/registrations/test/integration/registrations_test.exs @@ -1,4 +1,4 @@ -defmodule AdventureRegistrations.Integration.Registrations do +defmodule AdventureRegistrations.Integration.ClandestineRendezvous.Registrations do use AdventureRegistrationsWeb.ConnCase use AdventureRegistrations.SwooshHelper use AdventureRegistrations.ResetRegistrationClosed @@ -240,3 +240,44 @@ defmodule AdventureRegistrations.Integration.Registrations do "You may change your details but it’s too late to guarantee the changes can be integrated" end end + +defmodule AdventureRegistrations.Integration.UnmnemonicDevices.Registrations do + use AdventureRegistrationsWeb.ConnCase + use AdventureRegistrations.SwooshHelper + use AdventureRegistrations.ResetRegistrationClosed + use AdventureRegistrations.UnmnemonicDevices + + alias AdventureRegistrations.Pages.Register + alias AdventureRegistrations.Pages.Nav + + # Import Hound helpers + use Hound.Helpers + + # Start a Hound session + hound_session() + + def set_window_to_show_account do + set_window_size(current_window_handle(), 720, 450) + end + + test "registering sends email from and to a different address" do + set_window_to_show_account() + + navigate_to("/") + Nav.register_link().click + + Register.fill_email("samuel.delaney@example.com") + Register.fill_password("nestofspiders") + Register.submit() + + [welcome_email, admin_email] = AdventureRegistrations.SwooshHelper.sent_email() + + assert admin_email.to == [{"", "knut@chromatin.ca"}] + assert admin_email.from == {"", "knut@chromatin.ca"} + assert admin_email.subject == "samuel.delaney@example.com registered" + + assert welcome_email.to == [{"", "samuel.delaney@example.com"}] + assert welcome_email.from == {"", "knut@chromatin.ca"} + assert welcome_email.subject == "[unmnemonic] Welcome!" + end +end