From f80d9c1f578b6c13c0b3a9517bb6d0ac10eef465 Mon Sep 17 00:00:00 2001 From: Doc Ritezel Date: Fri, 16 Feb 2018 08:32:03 -0800 Subject: [PATCH] Add test coverage for RefreshBalance.perform/1 --- lib/explorer/workers/refresh_balance.ex | 4 ++-- .../explorer/workers/refresh_balance_test.exs | 24 ++++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/explorer/workers/refresh_balance.ex b/lib/explorer/workers/refresh_balance.ex index c6406d6044..5a0ba5d207 100644 --- a/lib/explorer/workers/refresh_balance.ex +++ b/lib/explorer/workers/refresh_balance.ex @@ -12,8 +12,8 @@ defmodule Explorer.Workers.RefreshBalance do def perform("debit"), do: unless refreshing("debits"), do: Debit.refresh() def perform do - perform_later("credit") - perform_later("debit") + perform_later(["credit"]) + perform_later(["debit"]) end def perform_later(args \\ []) do diff --git a/test/explorer/workers/refresh_balance_test.exs b/test/explorer/workers/refresh_balance_test.exs index aca218948c..e2d44767f8 100644 --- a/test/explorer/workers/refresh_balance_test.exs +++ b/test/explorer/workers/refresh_balance_test.exs @@ -7,9 +7,9 @@ defmodule Explorer.Workers.RefreshBalanceTest do alias Explorer.Debit alias Explorer.Workers.RefreshBalance - describe "perform/1" do + describe "perform/0" do test "refreshes credit balances" do - with_mock Exq, [enqueue: fn (_, _, _, _) -> Credit.refresh() end] do + with_mock Exq, [enqueue: fn (_, _, _, [type]) -> RefreshBalance.perform(type) end] do address = insert(:address) transaction = insert(:transaction, value: 20) insert(:to_address, address: address, transaction: transaction) @@ -19,7 +19,7 @@ defmodule Explorer.Workers.RefreshBalanceTest do end test "refreshes debit balances" do - with_mock Exq, [enqueue: fn (_, _, _, _) -> Debit.refresh() end] do + with_mock Exq, [enqueue: fn (_, _, _, [type]) -> RefreshBalance.perform(type) end] do address = insert(:address) transaction = insert(:transaction, value: 20) insert(:from_address, address: address, transaction: transaction) @@ -28,4 +28,22 @@ defmodule Explorer.Workers.RefreshBalanceTest do end end end + + describe "perform/1" do + test "refreshes credit balances" do + address = insert(:address) + transaction = insert(:transaction, value: 20) + insert(:to_address, address: address, transaction: transaction) + RefreshBalance.perform("credit") + assert Repo.one(Credit).value == Decimal.new(20) + end + + test "refreshes debit balances" do + address = insert(:address) + transaction = insert(:transaction, value: 20) + insert(:from_address, address: address, transaction: transaction) + RefreshBalance.perform("debit") + assert Repo.one(Debit).value == Decimal.new(20) + end + end end