-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds email notifications when a response has been made to some feedback
- Loading branch information
1 parent
1d3ea9e
commit 11f9e58
Showing
10 changed files
with
113 additions
and
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
defmodule Feedback.Email do | ||
use Bamboo.Phoenix, view: Feedback.FeedbackView | ||
|
||
def send_email(to_email_address, subject, message) do | ||
new_email() | ||
|> to(to_email_address) | ||
|> from(System.get_env("ADMIN_EMAIL")) # also needs to be a validated email | ||
|> subject(subject) | ||
|> text_body(message) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
defmodule Feedback.Mailer do | ||
use Bamboo.Mailer, otp_app: :feedback | ||
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
defmodule Feedback.FeedbackControllerTest do | ||
use Feedback.ConnCase, async: false | ||
alias Feedback.{Email, Mailer} | ||
|
||
import Mock | ||
|
||
test "/feedback/new", %{conn: conn} do | ||
conn = get conn, "/feedback/new" | ||
|
@@ -54,18 +57,35 @@ defmodule Feedback.FeedbackControllerTest do | |
end | ||
|
||
test "/feedback/:id update different request header", %{conn: conn} do | ||
feedback = insert_feedback(%{submitter_email: "[email protected]"}) | ||
with_mock Mailer, [deliver_now: fn(_) -> nil end] do | ||
conn = | ||
conn | ||
|> put_req_header("referer", "http://localhost:4000/feedback") | ||
conn = put conn, feedback_path(conn, :update, feedback.id, %{"feedback" => %{"response" => "response"}}) | ||
assert redirected_to(conn, 302) =~ "/feedback/#{feedback.permalink_string}" | ||
end | ||
end | ||
|
||
test "/feedback/:id update error email", %{conn: conn} do | ||
feedback = insert_feedback() | ||
conn = put conn, feedback_path(conn, :update, feedback.id, %{"feedback" => %{"submitter_email" => "invalid_email_format"}}) | ||
assert html_response(conn, 200) =~ "feedback" | ||
end | ||
|
||
test "/feedback/:id update error response", %{conn: conn} do | ||
feedback = insert_feedback() | ||
conn = | ||
conn | ||
|> put_req_header("referer", "http://localhost:4000/feedback") | ||
conn = put conn, feedback_path(conn, :update, feedback.id, %{"feedback" => %{"response" => "response"}}) | ||
assert redirected_to(conn, 302) =~ "/feedback/#{feedback.permalink_string}" | ||
conn = put conn, feedback_path(conn, :update, feedback.id, %{"feedback" => %{"response" => "a"}}) | ||
assert html_response(conn, 200) =~ "feedback" | ||
end | ||
|
||
test "/feedback/:id update error", %{conn: conn} do | ||
test "/feedback/:id update email submit", %{conn: conn} do | ||
feedback = insert_feedback() | ||
conn = put conn, feedback_path(conn, :update, feedback.id, %{"feedback" => %{"submitter_email" => "invalid_email_format"}}) | ||
assert html_response(conn, 200) =~ "feedback" | ||
conn = put conn, feedback_path(conn, :update, feedback.id, %{"feedback" => %{"submitter_email" => "[email protected]"}}) | ||
assert redirected_to(conn, 302) =~ "/feedback/#{feedback.permalink_string}" | ||
end | ||
|
||
test "/happy", %{conn: conn} do | ||
|
@@ -122,4 +142,11 @@ defmodule Feedback.FeedbackControllerTest do | |
conn = get conn, feedback_path(conn, :angry) | ||
assert html_response(conn, 200) =~ "angry" | ||
end | ||
|
||
test "strucuture of email is ok" do | ||
email = Email.send_email("[email protected]", "Welcome", "Hello there") | ||
assert email.to == "[email protected]" | ||
assert email.subject == "Welcome" | ||
assert email.text_body =~ "Hello there" | ||
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