mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 15:49:39 +02:00
Fix foreign account sync crash (#794)
* Fix foreign account sync crash * Refactor synth provider and show UI error if not configured * Generate error message on missing exchange rates while converting balances * Ignore sync messaged in i18n-tasks unused * Generate missing exchange rate error during entry normalization * Update alert classes
This commit is contained in:
parent
e9c8897eaf
commit
483d67846c
12 changed files with 102 additions and 45 deletions
|
@ -7,36 +7,44 @@ class ExchangeRateTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
test "fetch rate from provider when it's not found in db" do
|
||||
ExchangeRate
|
||||
.expects(:fetch_rate_from_provider)
|
||||
.returns(ExchangeRate.new(base_currency: "USD", converted_currency: "MXN", rate: 1.0, date: Date.current))
|
||||
with_env_overrides SYNTH_API_KEY: "true" do
|
||||
ExchangeRate
|
||||
.expects(:fetch_rate_from_provider)
|
||||
.returns(ExchangeRate.new(base_currency: "USD", converted_currency: "MXN", rate: 1.0, date: Date.current))
|
||||
|
||||
ExchangeRate.find_rate_or_fetch from: "USD", to: "MXN", date: Date.current
|
||||
ExchangeRate.find_rate_or_fetch from: "USD", to: "MXN", date: Date.current
|
||||
end
|
||||
end
|
||||
|
||||
test "provided rates are saved to the db" do
|
||||
VCR.use_cassette "synth_exchange_rate" do
|
||||
assert_difference "ExchangeRate.count", 1 do
|
||||
ExchangeRate.find_rate_or_fetch from: "USD", to: "MXN", date: Date.current
|
||||
with_env_overrides SYNTH_API_KEY: "true" do
|
||||
VCR.use_cassette "synth_exchange_rate" do
|
||||
assert_difference "ExchangeRate.count", 1 do
|
||||
ExchangeRate.find_rate_or_fetch from: "USD", to: "MXN", date: Date.current
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "retrying, then raising on provider error" do
|
||||
Faraday.expects(:get).returns(OpenStruct.new(success?: false)).times(3)
|
||||
with_env_overrides SYNTH_API_KEY: "true" do
|
||||
Faraday.expects(:get).returns(OpenStruct.new(success?: false)).times(3)
|
||||
|
||||
error = assert_raises Provider::Base::ProviderError do
|
||||
ExchangeRate.find_rate_or_fetch from: "USD", to: "MXN", date: Date.current
|
||||
error = assert_raises Provider::Base::ProviderError do
|
||||
ExchangeRate.find_rate_or_fetch from: "USD", to: "MXN", date: Date.current
|
||||
end
|
||||
|
||||
assert_match "Failed to fetch exchange rate from Provider::Synth", error.message
|
||||
end
|
||||
|
||||
assert_match "Failed to fetch exchange rate from Provider::Synth", error.message
|
||||
end
|
||||
|
||||
test "retrying, then raising on network error" do
|
||||
Faraday.expects(:get).raises(Faraday::TimeoutError).times(3)
|
||||
with_env_overrides SYNTH_API_KEY: "true" do
|
||||
Faraday.expects(:get).raises(Faraday::TimeoutError).times(3)
|
||||
|
||||
assert_raises Faraday::TimeoutError do
|
||||
ExchangeRate.find_rate_or_fetch from: "USD", to: "MXN", date: Date.current
|
||||
assert_raises Faraday::TimeoutError do
|
||||
ExchangeRate.find_rate_or_fetch from: "USD", to: "MXN", date: Date.current
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue