diff --git a/app/models/provider/simplefin.rb b/app/models/provider/simplefin.rb index 67c540745..39a0d8898 100644 --- a/app/models/provider/simplefin.rb +++ b/app/models/provider/simplefin.rb @@ -66,7 +66,11 @@ class Provider::Simplefin query_params["end-date"] = end_timestamp.to_s end - 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 pending accounts_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.rb index a795b7342..194c33037 100644 --- a/test/models/provider/simplefin_test.rb +++ b/test/models/provider/simplefin_test.rb @@ -102,6 +102,39 @@ class Provider::SimplefinTest < ActiveSupport::TestCase assert_equal :server_error, error.error_type end + 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" do setup_token = Base64.encode64("https://example.com/claim") mock_response = OpenStruct.new(code: 200, body: "https://example.com/access")