-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch ProjectUserAcceptance email to SparkPost
- Loading branch information
Showing
8 changed files
with
89 additions
and
70 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
42 changes: 42 additions & 0 deletions
42
lib/code_corps/sparkpost/emails/project_user_acceptance.ex
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,42 @@ | ||
defmodule CodeCorps.SparkPost.Emails.ProjectUserAcceptance do | ||
alias SparkPost.{Content, Transmission} | ||
|
||
alias CodeCorps.{ | ||
Presenters.ImagePresenter, | ||
Project, | ||
ProjectUser, | ||
Repo, | ||
SparkPost.Emails.Recipient, | ||
User, | ||
WebClient | ||
} | ||
|
||
@spec build(ProjectUser.t) :: %Transmission{} | ||
def build(%ProjectUser{project: project, user: user}) do | ||
%Transmission{ | ||
content: %Content.TemplateRef{template_id: "project-user-acceptance"}, | ||
options: %Transmission.Options{inline_css: true}, | ||
recipients: [user |> Recipient.build], | ||
substitution_data: %{ | ||
from_name: "Code Corps", | ||
from_email: "[email protected]", | ||
project_logo_url: ImagePresenter.large(project), | ||
project_title: project.title, | ||
project_url: project |> preload() |> url(), | ||
subject: "#{project.title} just added you as a contributor", | ||
user_first_name: user.first_name, | ||
user_image_url: ImagePresenter.large(user) | ||
} | ||
} | ||
end | ||
|
||
@spec preload(Project.t) :: Project.t | ||
defp preload(%Project{} = project), do: project |> Repo.preload(:organization) | ||
|
||
@spec url(Project.t) :: String.t | ||
defp url(project) do | ||
WebClient.url() | ||
|> URI.merge(project.organization.slug <> "/" <> project.slug) | ||
|> URI.to_string | ||
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
25 changes: 0 additions & 25 deletions
25
test/lib/code_corps/emails/project_user_acceptance_email_test.exs
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
test/lib/code_corps/sparkpost/emails/project_user_acceptance_test.exs
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,38 @@ | ||
defmodule CodeCorps.SparkPost.Emails.ProjectUserAcceptanceTest do | ||
use CodeCorps.DbAccessCase | ||
|
||
alias CodeCorps.SparkPost.Emails.ProjectUserAcceptance | ||
|
||
describe "build/1" do | ||
test "provides substitution data for all keys used by template" do | ||
project_user = insert(:project_user) | ||
|
||
%{substitution_data: data} = ProjectUserAcceptance.build(project_user) | ||
|
||
expected_keys = | ||
"project-user-acceptance" | ||
|> CodeCorps.SparkPostHelpers.get_keys_used_by_template | ||
assert data |> Map.keys == expected_keys | ||
end | ||
|
||
test "builds correct transmission model" do | ||
%{project: project, user: user} = project_user = insert(:project_user) | ||
|
||
%{substitution_data: data, recipients: [recipient]} = | ||
ProjectUserAcceptance.build(project_user) | ||
|
||
assert data.from_name == "Code Corps" | ||
assert data.from_email == "[email protected]" | ||
|
||
assert data.project_title == project.title | ||
assert data.project_url == "http://localhost:4200/#{project.organization.slug}/#{project.slug}" | ||
assert data.project_logo_url == "#{Application.get_env(:code_corps, :asset_host)}/icons/project_default_large_.png" | ||
assert data.user_image_url == "#{Application.get_env(:code_corps, :asset_host)}/icons/user_default_large_.png" | ||
assert data.user_first_name == user.first_name | ||
assert data.subject == "#{project.title} just added you as a contributor" | ||
|
||
assert recipient.address.email == user.email | ||
assert recipient.address.name == user.first_name | ||
end | ||
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