Skip to content

Commit

Permalink
Merge pull request #87 from mbta/pwd-populate_datetime_for_heat
Browse files Browse the repository at this point in the history
Include current date/time in HEAT messages
  • Loading branch information
phildarnowsky authored Jul 18, 2019
2 parents 08629f0 + d3b7359 commit 3b96c34
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion apps/feedback/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ config :feedback,
support_ticket_reply_email: System.get_env("SUPPORT_TICKET_REPLY_EMAIL") || "[email protected]",
mailgun_domain: System.get_env("MAILGUN_DOMAIN") || "",
mailgun_key: System.get_env("MAILGUN_API_KEY") || "",
test_mail_file: "/tmp/mailgun.json"
test_mail_file: "/tmp/mailgun.json",
time_fetcher: DateTime

import_config "#{Mix.env()}.exs"
3 changes: 3 additions & 0 deletions apps/feedback/config/test.exs
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
use Mix.Config

config :feedback,
time_fetcher: Feedback.FakeDateTime
9 changes: 9 additions & 0 deletions apps/feedback/lib/fake_date_time.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule Feedback.FakeDateTime do
@moduledoc "Mock DateTime module for testing"

def utc_now do
# This timestamp is July 8 2019, 08:04:03 UTC
{:ok, test_time} = DateTime.from_unix(1_562_573_043)
test_time
end
end
9 changes: 8 additions & 1 deletion apps/feedback/lib/mailer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule Feedback.Mailer do
<MODE></MODE>
<LINE></LINE>
<STATION></STATION>
<INCIDENTDATE></INCIDENTDATE>
<INCIDENTDATE>#{formatted_utc_timestamp()}</INCIDENTDATE>
<VEHICLE></VEHICLE>
<FIRSTNAME>#{format_first_name(message.name)}</FIRSTNAME>
<LASTNAME>#{format_last_name(message.name)}</LASTNAME>
Expand Down Expand Up @@ -108,4 +108,11 @@ defmodule Feedback.Mailer do
email -> email
end
end

defp formatted_utc_timestamp do
time_fetcher = Application.get_env(:feedback, :time_fetcher) || DateTime

time_fetcher.utc_now
|> Timex.format!("{0M}/{0D}/{YYYY} {h24}:{m}")
end
end
2 changes: 1 addition & 1 deletion apps/feedback/test/mailer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ defmodule Feedback.MailerTest do
<MODE></MODE>
<LINE></LINE>
<STATION></STATION>
<INCIDENTDATE></INCIDENTDATE>
<INCIDENTDATE>07/08/2019 08:04</INCIDENTDATE>
<VEHICLE></VEHICLE>
<FIRSTNAME>Riding</FIRSTNAME>
<LASTNAME>Public</LASTNAME>
Expand Down

0 comments on commit 3b96c34

Please sign in to comment.