Skip to content

Commit

Permalink
Enhance Account email building module test
Browse files Browse the repository at this point in the history
  • Loading branch information
vbaranov committed Jul 17, 2023
1 parent 10f7fff commit 36cdc50
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
26 changes: 22 additions & 4 deletions apps/explorer/lib/explorer/account/notifier/email.ex
Original file line number Diff line number Diff line change
Expand Up @@ -122,27 +122,45 @@ defmodule Explorer.Account.Notifier.Email do
end

defp block_url(notification) do
URI.to_string(uri()) <> "block/" <> Integer.to_string(notification.block_number)
Helpers.block_url(uri(), :show, Integer.to_string(notification.block_number))
end

defp transaction_url(notification) do
Helpers.transaction_url(uri(), :show, notification.transaction_hash)
end

defp url_params do
Application.get_env(:block_scout_web, BlockScoutWeb.Endpoint)[:url]
end

defp uri do
%URI{scheme: "https", host: host(), path: path()}
%URI{scheme: scheme(), host: host(), port: port(), path: path()}
end

defp scheme do
Keyword.get(url_params(), :scheme, "http")
end

defp host do
if System.get_env("MIX_ENV") == "prod" do
"blockscout.com"
else
Application.get_env(:block_scout_web, BlockScoutWeb.Endpoint)[:url][:host]
url_params()[:host]
end
end

defp port do
url_params()[:http][:port]
end

defp path do
Application.get_env(:block_scout_web, BlockScoutWeb.Endpoint)[:url][:path]
raw_path = url_params()[:path]

if raw_path |> String.ends_with?("/") do
raw_path |> String.slice(0..-2)
else
raw_path
end
end

defp sender do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Explorer.Account.Notify.EmailTest do
defmodule Explorer.Account.Notifier.EmailTest do
use ExUnit.Case

alias Explorer.Account.{
Expand All @@ -20,8 +20,9 @@ defmodule Explorer.Account.Notify.EmailTest do
setup do
host = Application.get_env(:block_scout_web, BlockScoutWeb.Endpoint)[:url][:host]
path = Application.get_env(:block_scout_web, BlockScoutWeb.Endpoint)[:url][:path]
scheme = Application.get_env(:block_scout_web, BlockScoutWeb.Endpoint)[:url][:scheme]

Application.put_env(:block_scout_web, BlockScoutWeb.Endpoint, url: [host: "localhost", path: "/"])
Application.put_env(:block_scout_web, BlockScoutWeb.Endpoint, url: [scheme: "https", host: "eth.blockscout.com", path: "/", port: 443])

Application.put_env(:explorer, Explorer.Account,
sendgrid: [
Expand All @@ -33,7 +34,7 @@ defmodule Explorer.Account.Notify.EmailTest do
:ok

on_exit(fn ->
Application.put_env(:block_scout_web, BlockScoutWeb.Endpoint, url: [host: host, path: path])
Application.put_env(:block_scout_web, BlockScoutWeb.Endpoint, url: [scheme: scheme, host: host, path: path])
end)
end

Expand Down Expand Up @@ -91,20 +92,20 @@ defmodule Explorer.Account.Notify.EmailTest do
dynamic_template_data: %{
"address_hash" => "0xe1f4dd38f00b0d8d4d2b4b5010be53f2a0b934e5",
"address_name" => "wallet",
"address_url" => "https://localhost//address/0xe1f4dd38f00b0d8d4d2b4b5010be53f2a0b934e5",
"address_url" => "https://eth.blockscout.com/address/0xe1f4dd38f00b0d8d4d2b4b5010be53f2a0b934e5",
"amount" => Decimal.new(1),
"block_number" => 24_121_177,
"block_url" => "https://localhost/block/24121177",
"block_url" => "https://eth.blockscout.com/block/24121177",
"direction" => "received at",
"from_address_hash" => "0x092d537737e767dae48c28ae509f34094496f030",
"from_url" => "https://localhost//address/0x092d537737e767dae48c28ae509f34094496f030",
"from_url" => "https://eth.blockscout.com/address/0x092d537737e767dae48c28ae509f34094496f030",
"method" => "transfer",
"name" => "wallet",
"to_address_hash" => "0xe1f4dd38f00b0d8d4d2b4b5010be53f2a0b934e5",
"to_url" => "https://localhost//address/0xe1f4dd38f00b0d8d4d2b4b5010be53f2a0b934e5",
"to_url" => "https://eth.blockscout.com/address/0xe1f4dd38f00b0d8d4d2b4b5010be53f2a0b934e5",
"transaction_hash" => "0x5d5ff210261f1b2d6e4af22ea494f428f9997d4ab614a629d4f1390004b3e80d",
"transaction_url" =>
"https://localhost//tx/0x5d5ff210261f1b2d6e4af22ea494f428f9997d4ab614a629d4f1390004b3e80d",
"https://eth.blockscout.com/tx/0x5d5ff210261f1b2d6e4af22ea494f428f9997d4ab614a629d4f1390004b3e80d",
"tx_fee" => Decimal.new(210_000),
"username" => "John Snow"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Explorer.Account.Notify.NotifyTest do
defmodule Explorer.Account.Notifier.NotifyTest do
# use ExUnit.Case
use Explorer.DataCase

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Explorer.Account.Notify.SummaryTest do
defmodule Explorer.Account.Notifier.SummaryTest do
use Explorer.DataCase

import Explorer.Factory
Expand Down

0 comments on commit 36cdc50

Please sign in to comment.