Notifier specs

account
Oleg Sovetnik 3 years ago committed by Viktor Baranov
parent 9fbf903e5c
commit b55a965b26
  1. 91
      apps/explorer/test/explorer/accounts/notify/notify_test.exs
  2. 46
      apps/explorer/test/support/factory.ex

@ -0,0 +1,91 @@
defmodule Explorer.Accounts.Notify.NotifyTest do
# use ExUnit.Case
use Explorer.DataCase
import Explorer.Factory
alias Explorer.Accounts.Notifier.Notify
alias Explorer.Accounts.{WatchlistAddress, WatchlistNotification}
alias Explorer.Chain
alias Explorer.Chain.{Address, Token, TokenTransfer, Transaction, Wei}
alias Explorer.Repo
setup do
Application.put_env(:explorer, Explorer.Accounts,
sendgrid: [
sender: "noreply@blockscout.com",
template: "d-666"
]
)
Application.put_env(:explorer, Explorer.Mailer,
adapter: Bamboo.SendGridAdapter,
api_key: "SENDGRID_API_KEY"
)
Application.put_env(
:ueberauth,
Ueberauth,
providers: [
auth0: {
Ueberauth.Strategy.Auth0,
[callback_url: "callback.url"]
}
],
logout_url: "logout.url",
logout_return_to_url: "return.url"
)
end
describe "notify" do
test "when address not in any watchlist" do
tx = with_block(insert(:transaction))
notify = Notify.call([tx])
wn =
WatchlistNotification
|> first
|> Repo.one()
assert notify == [[:ok]]
assert wn == nil
end
test "when address apears in watchlist" do
wa =
%WatchlistAddress{
address: address
} = insert(:account_watchlist_address)
watchlist_address = Repo.preload(wa, :address, watchlist: :identity)
tx =
%Transaction{
from_address: from_address,
to_address: to_address,
block_number: block_number,
hash: tx_hash
} = with_block(insert(:transaction, to_address: address))
{_, fee} = Chain.fee(tx, :gwei)
amount = Wei.to(tx.value, :ether)
notify = Notify.call([tx])
wn =
WatchlistNotification
|> first
|> Repo.one()
assert notify == [[:ok]]
assert wn.amount == amount
assert wn.direction == "incoming"
assert wn.method == "transfer"
assert wn.subject == "Coin transaction"
assert wn.tx_fee == fee
assert wn.type == "COIN"
end
end
end

@ -6,8 +6,18 @@ defmodule Explorer.Factory do
import Ecto.Query
import Kernel, except: [+: 2]
alias Bcrypt
alias Explorer.Accounts.{User, UserContact}
alias Comeonin.Bcrypt
alias Explorer.Accounts.{
User,
UserContact,
Identity,
TagAddress,
Watchlist,
WatchlistAddress,
WatchlistNotification
}
alias Explorer.Admin.Administrator
alias Explorer.Chain.Block.{EmissionReward, Range, Reward}
@ -37,6 +47,38 @@ defmodule Explorer.Factory do
alias Explorer.Market.MarketHistory
alias Explorer.Repo
def account_identity_factory do
%Identity{
uid: sequence("github|"),
email: sequence(:email, &"me-#{&1}@blockscout.com"),
name: sequence("John")
}
end
def account_watchlist_factory do
%Watchlist{
name: "default",
identity: build(:account_identity)
}
end
def account_watchlist_address_factory do
%WatchlistAddress{
name: "wallet",
watchlist: build(:account_watchlist),
address: build(:address),
watch_coin_input: true,
watch_coin_output: true,
watch_erc_20_input: true,
watch_erc_20_output: true,
watch_erc_721_input: true,
watch_erc_721_output: true,
watch_erc_1155_input: true,
watch_erc_1155_output: true,
notify_email: true
}
end
def address_factory do
%Address{
hash: address_hash()

Loading…
Cancel
Save