Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

List Wise profiles from v2 so no business profile is missing (#4839)

Krish Wanchood4c27891383b
diff --git a/app/models/provider/wise.rb b/app/models/provider/wise.rb
index 45100eba76..518701d304 100644
--- a/app/models/provider/wise.rb
+++ b/app/models/provider/wise.rb
@@ -55,8 +55,20 @@ class Provider::Wise
get("/v1/me")
end
+ # v1 leaves out some business profiles the token can read (one with an
+ # empty companyRole); v2 lists them all. Each profile is returned in the v1
+ # shape the profile picker reads: a lowercase type and the name in details.
def get_profiles
- get("/v1/profiles")
+ Array(get("/v2/profiles")).map do |profile|
+ business = profile["type"].to_s.casecmp?("business")
+ name = business ? profile["businessName"] : profile["fullName"]
+
+ {
+ "id" => profile["id"],
+ "type" => business ? "business" : "personal",
+ "details" => profile["details"].presence || { "name" => name.presence }.compact
+ }
+ end
end
def get_balances(profile_id)
diff --git a/test/models/provider/wise_test.rb b/test/models/provider/wise_test.rb
index ca7415fd4d..a949b4f75b 100644
--- a/test/models/provider/wise_test.rb
+++ b/test/models/provider/wise_test.rb
@@ -148,6 +148,23 @@ class Provider::WiseTest < ActiveSupport::TestCase
assert_equal({ profile: 123, limit: 100, offset: 200, createdDateStart: "2025-10-07" }, sent)
end
+ test "lists profiles from v2 in the shape the profile picker reads" do
+ body = [
+ { id: 1, type: "PERSONAL", fullName: "Jane Doe", profileRole: "DIRECT_CUSTOMER_PROFILE" },
+ { id: 2, type: "BUSINESS", businessName: "Owned Ltd", companyRole: "OWNER" },
+ { id: 3, type: "BUSINESS", businessName: "Missing From V1 Ltd", companyRole: "" }
+ ].to_json
+ Provider::Wise.expects(:get)
+ .with { |url, _options| url == "https://api.wise.com/v2/profiles" }
+ .returns(fake_response(code: 200, body: body))
+
+ assert_equal [
+ { "id" => 1, "type" => "personal", "details" => { "name" => "Jane Doe" } },
+ { "id" => 2, "type" => "business", "details" => { "name" => "Owned Ltd" } },
+ { "id" => 3, "type" => "business", "details" => { "name" => "Missing From V1 Ltd" } }
+ ], @provider.get_profiles
+ end
+
test "reads the multi-currency account from the v4 endpoint" do
Provider::Wise.expects(:get)
.with { |url, _options| url == "https://api.wise.com/v4/profiles/123/multi-currency-account" }