Skip to content

Commit

Permalink
Update registrations from email for unmnemonic
Browse files Browse the repository at this point in the history
  • Loading branch information
backspace committed Nov 28, 2023
1 parent 064383c commit ac2a2fb
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 14 deletions.
30 changes: 19 additions & 11 deletions registrations/lib/adventure_registrations/mailer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -20,8 +20,8 @@ defmodule AdventureRegistrations.Mailer do

def send_question(attributes) do
new()
|> to("[email protected]")
|> from(@from)
|> to(adventure_from())
|> from(adventure_from())
|> subject(
"Question from #{attributes["name"]} <#{attributes["email"]}>: #{attributes["subject"]}"
)
Expand All @@ -31,26 +31,26 @@ 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
end

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
end

def send_registration(user) do
new()
|> to(@from)
|> from(@from)
|> to(adventure_from())
|> from(adventure_from())
|> subject("#{user.email} registered")
|> text_body("Yes")
|> deliver
Expand All @@ -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))
Expand All @@ -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 <a href='#{Router.Helpers.reset_url(Endpoint, :edit, user.recovery_hash)}'>password reset link</a>"
Expand Down Expand Up @@ -149,6 +149,14 @@ defmodule AdventureRegistrations.Mailer do
end
end

defp adventure_from() do
if AdventureRegistrationsWeb.SharedHelpers.is_unmnemonic_devices() do
"[email protected]"
else
@from
end
end

def message_from_string(message) do
case message.from_address do
"" -> nil
Expand Down
4 changes: 2 additions & 2 deletions registrations/test/integration/questions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>: A Word to Tramps"
Expand Down
43 changes: 42 additions & 1 deletion registrations/test/integration/registrations_test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule AdventureRegistrations.Integration.Registrations do
defmodule AdventureRegistrations.Integration.ClandestineRendezvous.Registrations do
use AdventureRegistrationsWeb.ConnCase
use AdventureRegistrations.SwooshHelper
use AdventureRegistrations.ResetRegistrationClosed
Expand Down Expand Up @@ -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("[email protected]")
Register.fill_password("nestofspiders")
Register.submit()

[welcome_email, admin_email] = AdventureRegistrations.SwooshHelper.sent_email()

assert admin_email.to == [{"", "[email protected]"}]
assert admin_email.from == {"", "[email protected]"}
assert admin_email.subject == "[email protected] registered"

assert welcome_email.to == [{"", "[email protected]"}]
assert welcome_email.from == {"", "[email protected]"}
assert welcome_email.subject == "[unmnemonic] Welcome!"
end
end

0 comments on commit ac2a2fb

Please sign in to comment.