-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Swoosh to format User models into recipients (#2374)
* Use Swoosh to format User models into recipients
- Loading branch information
Showing
10 changed files
with
65 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ defmodule Lightning.Accounts.UserNotifierTest do | |
|
||
assert_email_sent( | ||
subject: "Project scheduled for deletion", | ||
to: "[email protected]", | ||
to: Swoosh.Email.Recipient.format(user), | ||
text_body: """ | ||
Hi User,\n\nYour OpenFn project "project-a" has been scheduled for deletion.\n\nAll of the workflows in this project have been disabled, and it's associated resources will be deleted on #{actual_deletion_date}.\n\nIf you don't want this project deleted, please email #{admin_email} as soon as possible.\n\nOpenFn | ||
""" | ||
|
@@ -54,7 +54,7 @@ defmodule Lightning.Accounts.UserNotifierTest do | |
|
||
assert_email_sent( | ||
subject: "You now have access to \"#{project.name}\"", | ||
to: "[email protected]", | ||
to: Swoosh.Email.Recipient.format(user), | ||
text_body: """ | ||
Hi Anna,\n\nYou've been granted "editor" access to the "a-test-project" project on OpenFn.\n\nVisit the URL below to check it out:\n\n#{url}\n\nOpenFn | ||
""" | ||
|
@@ -91,7 +91,7 @@ defmodule Lightning.Accounts.UserNotifierTest do | |
|
||
UserNotifier.deliver_confirmation_instructions( | ||
%User{first_name: "Sizwe", email: "[email protected]"}, | ||
%User{ | ||
to_user = %User{ | ||
first_name: "Joe", | ||
email: "[email protected]" | ||
}, | ||
|
@@ -107,7 +107,7 @@ defmodule Lightning.Accounts.UserNotifierTest do | |
|
||
assert_email_sent( | ||
subject: "Confirm your OpenFn account", | ||
to: "[email protected]", | ||
to: Swoosh.Email.Recipient.format(to_user), | ||
text_body: """ | ||
Hi Joe, | ||
|
@@ -123,27 +123,29 @@ defmodule Lightning.Accounts.UserNotifierTest do | |
end | ||
|
||
test "send_deletion_notification_email/1" do | ||
UserNotifier.send_deletion_notification_email(%User{ | ||
email: "[email protected]" | ||
}) | ||
UserNotifier.send_deletion_notification_email( | ||
to_user = %User{ | ||
email: "[email protected]" | ||
} | ||
) | ||
|
||
assert_email_sent( | ||
subject: "Your account has been scheduled for deletion", | ||
to: "[email protected]" | ||
to: Swoosh.Email.Recipient.format(to_user) | ||
) | ||
end | ||
|
||
test "send_credential_deletion_notification_email/2" do | ||
UserNotifier.send_credential_deletion_notification_email( | ||
%User{ | ||
to_user = %User{ | ||
email: "[email protected]" | ||
}, | ||
%Credential{name: "Test"} | ||
) | ||
|
||
assert_email_sent( | ||
subject: "Your \"Test\" credential will be deleted", | ||
to: "[email protected]" | ||
to: Swoosh.Email.Recipient.format(to_user) | ||
) | ||
end | ||
|
||
|
@@ -219,7 +221,7 @@ defmodule Lightning.Accounts.UserNotifierTest do | |
|
||
assert_email_sent( | ||
subject: "Daily digest for project Real Project", | ||
to: "[email protected]", | ||
to: Swoosh.Email.Recipient.format(user), | ||
text_body: """ | ||
Hi Elias, | ||
|
@@ -297,7 +299,7 @@ defmodule Lightning.Accounts.UserNotifierTest do | |
|
||
assert_email_sent( | ||
subject: "Weekly digest for project Real Project", | ||
to: "[email protected]", | ||
to: Swoosh.Email.Recipient.format(user), | ||
text_body: """ | ||
Hi Elias, | ||
|
@@ -377,7 +379,7 @@ defmodule Lightning.Accounts.UserNotifierTest do | |
|
||
assert_email_sent( | ||
subject: "Monthly digest for project Real Project", | ||
to: "[email protected]", | ||
to: Swoosh.Email.Recipient.format(user), | ||
text_body: """ | ||
Hi Elias, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
defmodule Lightning.MailerTest do | ||
use ExUnit.Case, async: true | ||
|
||
alias Lightning.Accounts.User | ||
|
||
test "correctly formats User models" do | ||
user = %User{email: "[email protected]", first_name: "John", last_name: "Doe"} | ||
|
||
assert Swoosh.Email.Recipient.format(user) == | ||
{"John Doe", "[email protected]"} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,12 +152,12 @@ defmodule LightningWeb.ProjectLiveTest do | |
project_name = String.replace(@create_attrs.raw_name, " ", "-") | ||
|
||
assert_email_sent( | ||
to: [{"", user_1.email}], | ||
to: [Swoosh.Email.Recipient.format(user_1)], | ||
subject: "You now have access to \"#{project_name}\"" | ||
) | ||
|
||
assert_email_sent( | ||
to: [{"", user_2.email}], | ||
to: [Swoosh.Email.Recipient.format(user_2)], | ||
subject: "You now have access to \"#{project_name}\"" | ||
) | ||
end | ||
|
@@ -2101,12 +2101,12 @@ defmodule LightningWeb.ProjectLiveTest do | |
assert html =~ "Invite sent successfully" | ||
|
||
refute_email_sent( | ||
to: [{"", "[email protected]"}], | ||
to: [{"Non Exists", "[email protected]"}], | ||
subject: "You now have access to \"my-project\"" | ||
) | ||
|
||
assert_email_sent( | ||
to: [{"", "[email protected]"}], | ||
to: [{"Non Exists", "[email protected]"}], | ||
subject: "Join my-project on OpenFn as a collaborator" | ||
) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters