Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Account Explorer.Account.Notifier.Email module tests #7954

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

### Chore

- [#7954](https://github.com/blockscout/blockscout/pull/7954) - Enhance Account Explorer.Account.Notifier.Email module tests
- [#7950](https://github.com/blockscout/blockscout/pull/7950) - Add GA CI for Eth Goerli chain
- [#7934](https://github.com/blockscout/blockscout/pull/7934), [#7936](https://github.com/blockscout/blockscout/pull/7936) - Explicitly set consensus == true in queries (convenient for search), remove logger requirements, where it is not used anymore
- [#7901](https://github.com/blockscout/blockscout/pull/7901) - Fix Docker image build
Expand Down
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,23 +122,41 @@ 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
Application.get_env(:block_scout_web, BlockScoutWeb.Endpoint)[:url][:host]
url_params()[:host]
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,11 @@ 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 +36,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 +94,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
Loading