The personal finance app for everyone (by everyone)
Ruby
fix: omit SimpleFin pending param when pending transactions are disabled (#2796)
RealDiligentd61ee3abeada
diff --git a/app/models/provider/simplefin.rb b/app/models/provider/simplefin.rbindex 67c540745e..39a0d88988 100644--- a/app/models/provider/simplefin.rb+++ b/app/models/provider/simplefin.rb@@ -66,7 +66,11 @@ class Provider::Simplefinquery_params["end-date"] = end_timestamp.to_send- query_params["pending"] = pending ? "1" : "0" unless pending.nil?+ # Per the SimpleFIN protocol, pending transactions are excluded by default+ # and only included when `pending=1` is present. Bridges presence-check the+ # param, so sending `pending=0` behaves like `pending=1` — the only+ # spec-compliant way to exclude pending is to omit the param entirely.+ query_params["pending"] = "1" if pendingaccounts_url = "#{access_url}/accounts"accounts_url += "?#{URI.encode_www_form(query_params)}" unless query_params.empty?diff --git a/test/models/provider/simplefin_test.rb b/test/models/provider/simplefin_test.rbindex a795b73428..194c330378 100644--- a/test/models/provider/simplefin_test.rb+++ b/test/models/provider/simplefin_test.rb@@ -102,6 +102,39 @@ class Provider::SimplefinTest < ActiveSupport::TestCaseassert_equal :server_error, error.error_typeend+ test "get_accounts sends pending=1 when pending is enabled" do+ mock_response = OpenStruct.new(code: 200, body: '{"accounts": []}')++ Provider::Simplefin.expects(:get)+ .with { |url| url.include?("pending=1") }+ .returns(mock_response)++ @provider.get_accounts(@access_url, pending: true)+ end++ test "get_accounts omits the pending param when pending is disabled" do+ # The SimpleFIN protocol has no pending=0 — bridges presence-check the+ # param, so pending=0 behaves like pending=1. Disabling pending must omit+ # the param entirely.+ mock_response = OpenStruct.new(code: 200, body: '{"accounts": []}')++ Provider::Simplefin.expects(:get)+ .with { |url| !url.include?("pending") }+ .returns(mock_response)++ @provider.get_accounts(@access_url, pending: false)+ end++ test "get_accounts omits the pending param when pending is nil" do+ mock_response = OpenStruct.new(code: 200, body: '{"accounts": []}')++ Provider::Simplefin.expects(:get)+ .with { |url| !url.include?("pending") }+ .returns(mock_response)++ @provider.get_accounts(@access_url, pending: nil)+ end+test "claim_access_url retries on network errors" dosetup_token = Base64.encode64("https://example.com/claim")mock_response = OpenStruct.new(code: 200, body: "https://example.com/access")