mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-25 08:09:38 +02:00
Account Issue Model and Resolution Flow + Troubleshooting guides (#1090)
* Rough draft of issue system * Simplify design * Remove stale files from merge conflicts * STI for issues * Cleanup * Improve Synth api key flow * Stub api key for test
This commit is contained in:
parent
c70a08aca2
commit
707c5ca0ca
52 changed files with 507 additions and 211 deletions
|
@ -1,18 +0,0 @@
|
|||
require "test_helper"
|
||||
|
||||
class Help::ArticlesControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in @user = users(:family_admin)
|
||||
|
||||
@article = Help::Article.new(frontmatter: { title: "Test Article", slug: "test-article" }, content: "")
|
||||
|
||||
Help::Article.stubs(:find).returns(@article)
|
||||
end
|
||||
|
||||
test "can view help article" do
|
||||
get help_article_path(@article)
|
||||
|
||||
assert_response :success
|
||||
assert_dom "h1", text: @article.title, count: 1
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
require "test_helper"
|
||||
|
||||
class Issue::ExchangeRateProviderMissingsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in users(:family_admin)
|
||||
@issue = issues(:one)
|
||||
end
|
||||
|
||||
test "should update issue" do
|
||||
patch issue_exchange_rate_provider_missing_url(@issue), params: {
|
||||
issue_exchange_rate_provider_missing: {
|
||||
synth_api_key: "1234"
|
||||
}
|
||||
}
|
||||
|
||||
assert_enqueued_with job: AccountSyncJob
|
||||
assert_redirected_to account_url(@issue.issuable)
|
||||
end
|
||||
end
|
17
test/controllers/issues_controller_test.rb
Normal file
17
test/controllers/issues_controller_test.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
require "test_helper"
|
||||
|
||||
class IssuesControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in users(:family_admin)
|
||||
end
|
||||
|
||||
test "should get show polymorphically" do
|
||||
issues.each do |issue|
|
||||
get issue_url(issue)
|
||||
assert_response :success
|
||||
assert_dom "h2", text: issue.title
|
||||
assert_dom "h3", text: "Issue Description"
|
||||
assert_dom "h3", text: "How to fix this issue"
|
||||
end
|
||||
end
|
||||
end
|
1
test/fixtures/account/syncs.yml
vendored
1
test/fixtures/account/syncs.yml
vendored
|
@ -4,7 +4,6 @@ one:
|
|||
start_date: 2024-07-07
|
||||
last_ran_at: 2024-07-07 09:03:31
|
||||
error: test sync error
|
||||
warnings: [ "test warning 1", "test warning 2" ]
|
||||
|
||||
two:
|
||||
account: investment
|
||||
|
|
6
test/fixtures/files/help_article.md
vendored
6
test/fixtures/files/help_article.md
vendored
|
@ -1,6 +0,0 @@
|
|||
---
|
||||
title: Placeholder
|
||||
slug: placeholder
|
||||
---
|
||||
|
||||
Test help article
|
5
test/fixtures/issues.yml
vendored
Normal file
5
test/fixtures/issues.yml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
one:
|
||||
issuable: depository
|
||||
issuable_type: Account
|
||||
type: Issue::Unknown
|
||||
last_observed_at: 2024-08-15 08:54:04
|
|
@ -4,7 +4,9 @@ module ExchangeRateProviderInterfaceTest
|
|||
extend ActiveSupport::Testing::Declarative
|
||||
|
||||
test "exchange rate provider interface" do
|
||||
assert_respond_to @subject, :healthy?
|
||||
assert_respond_to @subject, :fetch_exchange_rate
|
||||
assert_respond_to @subject, :fetch_exchange_rates
|
||||
end
|
||||
|
||||
test "exchange rate provider response contract" do
|
||||
|
|
|
@ -4,6 +4,7 @@ module SecurityPriceProviderInterfaceTest
|
|||
extend ActiveSupport::Testing::Declarative
|
||||
|
||||
test "security price provider interface" do
|
||||
assert_respond_to @subject, :healthy?
|
||||
assert_respond_to @subject, :fetch_security_prices
|
||||
end
|
||||
|
||||
|
|
|
@ -78,7 +78,9 @@ class Account::Balance::SyncerTest < ActiveSupport::TestCase
|
|||
create_exchange_rate(1.day.ago.to_date, from: "EUR", to: "USD", rate: 2)
|
||||
create_exchange_rate(Date.current, from: "EUR", to: "USD", rate: 2)
|
||||
|
||||
run_sync_for(@account)
|
||||
with_env_overrides SYNTH_API_KEY: ENV["SYNTH_API_KEY"] || "fookey" do
|
||||
run_sync_for(@account)
|
||||
end
|
||||
|
||||
usd_balances = @account.balances.where(currency: "USD").chronological.map(&:balance)
|
||||
eur_balances = @account.balances.where(currency: "EUR").chronological.map(&:balance)
|
||||
|
@ -88,30 +90,29 @@ class Account::Balance::SyncerTest < ActiveSupport::TestCase
|
|||
assert_equal [ 42000, 40000, 40000 ], usd_balances # converted balances at rate of 2:1
|
||||
end
|
||||
|
||||
test "fails with error if exchange rate not available for any entry" do
|
||||
create_transaction(account: @account, currency: "EUR")
|
||||
test "raises issue if missing exchange rates" do
|
||||
create_transaction(date: Date.current, account: @account, currency: "EUR")
|
||||
|
||||
ExchangeRate.expects(:find_rate).with(from: "EUR", to: "USD", date: Date.current).returns(nil)
|
||||
@account.expects(:observe_missing_exchange_rates).with(from: "EUR", to: "USD", dates: [ Date.current ])
|
||||
|
||||
syncer = Account::Balance::Syncer.new(@account)
|
||||
|
||||
with_env_overrides SYNTH_API_KEY: nil do
|
||||
assert_raises Money::ConversionError do
|
||||
syncer.run
|
||||
end
|
||||
end
|
||||
syncer.run
|
||||
end
|
||||
|
||||
# Account is able to calculate balances in its own currency (i.e. can still show a historical graph), but
|
||||
# doesn't have exchange rates available to convert those calculated balances to the family currency
|
||||
test "completes with warning if exchange rates not available to convert to family currency" do
|
||||
test "observes issue if exchange rate provider is not configured" do
|
||||
@account.update! currency: "EUR"
|
||||
|
||||
syncer = Account::Balance::Syncer.new(@account)
|
||||
|
||||
@account.expects(:observe_missing_exchange_rate_provider)
|
||||
|
||||
with_env_overrides SYNTH_API_KEY: nil do
|
||||
syncer.run
|
||||
end
|
||||
|
||||
assert_equal 1, syncer.warnings.count
|
||||
end
|
||||
|
||||
test "overwrites existing balances and purges stale balances" do
|
||||
|
|
|
@ -84,6 +84,8 @@ class Account::Holding::SyncerTest < ActiveSupport::TestCase
|
|||
Security::Price.new(ticker: "AMZN", date: 1.day.ago.to_date, price: 215)
|
||||
])
|
||||
|
||||
@account.expects(:observe_missing_price).with(ticker: "AMZN", date: Date.current).once
|
||||
|
||||
run_sync_for(@account)
|
||||
|
||||
assert_holdings(expected)
|
||||
|
|
7
test/models/account/issue_test.rb
Normal file
7
test/models/account/issue_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class Account::IssueTest < ActiveSupport::TestCase
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
|
@ -14,14 +14,11 @@ class Account::SyncTest < ActiveSupport::TestCase
|
|||
Account::Balance::Syncer.expects(:new).with(@account, start_date: nil).returns(@balance_syncer).once
|
||||
Account::Holding::Syncer.expects(:new).with(@account, start_date: nil).returns(@holding_syncer).once
|
||||
|
||||
@account.expects(:resolve_stale_issues).once
|
||||
@balance_syncer.expects(:run).once
|
||||
@balance_syncer.expects(:warnings).returns([ "test balance sync warning" ]).once
|
||||
|
||||
@holding_syncer.expects(:run).once
|
||||
@holding_syncer.expects(:warnings).returns([ "test holding sync warning" ]).once
|
||||
|
||||
assert_equal "pending", @sync.status
|
||||
assert_equal [], @sync.warnings
|
||||
assert_nil @sync.last_ran_at
|
||||
|
||||
@sync.run
|
||||
|
@ -29,7 +26,6 @@ class Account::SyncTest < ActiveSupport::TestCase
|
|||
streams = capture_turbo_stream_broadcasts [ @account.family, :notifications ]
|
||||
|
||||
assert_equal "completed", @sync.status
|
||||
assert_equal [ "test balance sync warning", "test holding sync warning" ], @sync.warnings
|
||||
assert @sync.last_ran_at
|
||||
|
||||
assert_equal "append", streams.first["action"]
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
require "test_helper"
|
||||
|
||||
class Help::ArticleTest < ActiveSupport::TestCase
|
||||
include ActiveJob::TestHelper
|
||||
|
||||
setup do
|
||||
Help::Article.stubs(:root_path).returns(Rails.root.join("test", "fixtures", "files"))
|
||||
end
|
||||
|
||||
test "returns nil if article not found" do
|
||||
assert_nil Help::Article.find("missing")
|
||||
end
|
||||
|
||||
test "find and renders markdown article" do
|
||||
article = Help::Article.find("placeholder")
|
||||
|
||||
assert_equal "Placeholder", article.title
|
||||
assert_equal "Test help article", article.content
|
||||
assert_equal "<p>Test help article</p>\n", article.html
|
||||
end
|
||||
end
|
7
test/models/issue_test.rb
Normal file
7
test/models/issue_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class IssueTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue