This repository has been archived by the owner on Aug 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
107 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,45 @@ | ||
defmodule CurrencyConversion.UpdateWorkerTest do | ||
use ExUnit.Case, async: false | ||
doctest CurrencyConversion.UpdateWorker | ||
|
||
import CurrencyConversion.UpdateWorker | ||
alias CurrencyConversion.UpdateWorker | ||
|
||
import ExUnit.CaptureLog | ||
doctest UpdateWorker | ||
|
||
import Mock | ||
|
||
defmodule Source do | ||
@moduledoc false | ||
|
||
@behaviour CurrencyConversion.Source | ||
|
||
def load do | ||
{:ok, %CurrencyConversion.Rates{base: :CHF, rates: %{}}} | ||
end | ||
end | ||
|
||
test "initial load called" do | ||
capture_log(fn -> | ||
Application.stop(:currency_conversion) | ||
test "initial load called", %{test: test_name} do | ||
name = Module.concat(__MODULE__, test_name) | ||
start_supervised!({UpdateWorker, source: Source, name: name}) | ||
|
||
Application.put_env( | ||
:currency_conversion, | ||
:source, | ||
CurrencyConversion.UpdateWorkerTest.Source | ||
) | ||
assert UpdateWorker.get_rates(name) == %CurrencyConversion.Rates{base: :CHF, rates: %{}} | ||
end | ||
|
||
Application.ensure_started(:logger) | ||
Application.ensure_all_started(:currency_conversion) | ||
end) | ||
test "refresh load called", %{test: test_name} do | ||
test_pid = self() | ||
name = Module.concat(__MODULE__, test_name) | ||
|
||
with_mock CurrencyConversion.Source.Test, | ||
load: fn -> | ||
send(test_pid, :load) | ||
{:ok, %CurrencyConversion.Rates{base: :CHF, rates: %{}}} | ||
end do | ||
start_supervised!( | ||
{UpdateWorker, | ||
source: CurrencyConversion.Source.Test, name: name, refresh_interval: 1_000} | ||
) | ||
|
||
assert get_rates() == %CurrencyConversion.Rates{base: :CHF, rates: %{}} | ||
assert_received :load | ||
assert_receive :load, 1_100 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
ExUnit.start() | ||
ExUnit.start(capture_log: true) |