1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-25 08:09:38 +02:00

Show UI warning to user when they need provider data but have not setup Synth yet (#1926)

* Simplify provider concerns

* Update tests

* Add UI warning for missing Synth key if family requires external data
This commit is contained in:
Zach Gollwitzer 2025-02-28 11:35:10 -05:00 committed by GitHub
parent 624faa10d0
commit fa0248056d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 184 additions and 136 deletions

View file

@ -5,14 +5,16 @@ class ExchangeRateTest < ActiveSupport::TestCase
setup do
@provider = mock
ExchangeRate.stubs(:exchange_rates_provider).returns(@provider)
ExchangeRate.stubs(:provider).returns(@provider)
end
test "exchange rate provider nil if no api key configured" do
ExchangeRate.unstub(:exchange_rates_provider)
ExchangeRate.unstub(:provider)
Setting.stubs(:synth_api_key).returns(nil)
with_env_overrides SYNTH_API_KEY: nil do
assert_not ExchangeRate.exchange_rates_provider
assert_not ExchangeRate.provider
end
end
@ -42,7 +44,9 @@ class ExchangeRateTest < ActiveSupport::TestCase
end
test "nil if rate is not found in DB and provider is disabled" do
ExchangeRate.unstub(:exchange_rates_provider)
ExchangeRate.unstub(:provider)
Setting.stubs(:synth_api_key).returns(nil)
with_env_overrides SYNTH_API_KEY: nil do
assert_not ExchangeRate.find_rate(from: "USD", to: "EUR", date: Date.current)
@ -102,7 +106,9 @@ class ExchangeRateTest < ActiveSupport::TestCase
end
test "returns empty array if no rates found in DB or provider" do
ExchangeRate.unstub(:exchange_rates_provider)
ExchangeRate.unstub(:provider)
Setting.stubs(:synth_api_key).returns(nil)
with_env_overrides SYNTH_API_KEY: nil do
assert_equal [], ExchangeRate.find_rates(from: "USD", to: "JPY", start_date: 10.days.ago.to_date)

View file

@ -5,14 +5,16 @@ class Security::PriceTest < ActiveSupport::TestCase
setup do
@provider = mock
Security::Price.stubs(:security_prices_provider).returns(@provider)
Security::Price.stubs(:provider).returns(@provider)
end
test "security price provider nil if no api key provided" do
Security::Price.unstub(:security_prices_provider)
Security::Price.unstub(:provider)
Setting.stubs(:synth_api_key).returns(nil)
with_env_overrides SYNTH_API_KEY: nil do
assert_not Security::Price.security_prices_provider
assert_not Security::Price.provider
end
end
@ -60,7 +62,10 @@ class Security::PriceTest < ActiveSupport::TestCase
end
test "returns nil if price not found in DB and provider disabled" do
Security::Price.unstub(:security_prices_provider)
Security::Price.unstub(:provider)
Setting.stubs(:synth_api_key).returns(nil)
security = Security.new(ticker: "NVDA")
with_env_overrides SYNTH_API_KEY: nil do
@ -105,7 +110,9 @@ class Security::PriceTest < ActiveSupport::TestCase
end
test "returns empty array if no prices found in DB or from provider" do
Security::Price.unstub(:security_prices_provider)
Security::Price.unstub(:provider)
Setting.stubs(:synth_api_key).returns(nil)
with_env_overrides SYNTH_API_KEY: nil do
assert_equal [], Security::Price.find_prices(security: Security.new(ticker: "NVDA"), start_date: 10.days.ago.to_date, end_date: Date.current)

View file

@ -12,30 +12,20 @@ class TradeImportTest < ActiveSupport::TestCase
# Create an existing AAPL security with no exchange_operating_mic
aapl = Security.create!(ticker: "AAPL", exchange_operating_mic: nil)
provider = mock
# We should only hit the provider for GOOGL since AAPL already exists
provider.expects(:search_securities).with(
Security.expects(:search_provider).with(
query: "GOOGL",
exchange_operating_mic: "XNAS"
).returns(
OpenStruct.new(
securities: [
{
ticker: "GOOGL",
name: "Google Inc.",
country_code: "US",
exchange_mic: "XNGS",
exchange_operating_mic: "XNAS",
exchange_acronym: "NGS"
}
],
success?: true,
raw_response: nil
).returns([
Security.new(
ticker: "GOOGL",
name: "Google Inc.",
country_code: "US",
exchange_mic: "XNGS",
exchange_operating_mic: "XNAS",
exchange_acronym: "NGS"
)
).once
Security.stubs(:security_prices_provider).returns(provider)
]).once
import = <<~CSV
date,ticker,qty,price,currency,account,name,exchange_operating_mic