Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Fix Plaid sync failure for loan subtypes missing from Loan::SUBTYPES (#2298)

BeltaKoda749d54dd9689
diff --git a/app/models/loan.rb b/app/models/loan.rb
index 980c198852..4b6b88ccaf 100644
--- a/app/models/loan.rb
+++ b/app/models/loan.rb
@@ -5,6 +5,9 @@ class Loan < ApplicationRecord
"mortgage" => { short: "Mortgage", long: "Mortgage" },
"student" => { short: "Student Loan", long: "Student Loan" },
"auto" => { short: "Auto Loan", long: "Auto Loan" },
+ "home_equity" => { short: "Home Equity", long: "Home Equity Loan" },
+ "line_of_credit" => { short: "Line of Credit", long: "Line of Credit" },
+ "business" => { short: "Business Loan", long: "Business Loan" },
"other" => { short: "Other Loan", long: "Other Loan" }
}.freeze
diff --git a/test/models/plaid_account/type_mappable_test.rb b/test/models/plaid_account/type_mappable_test.rb
index b3bc67083e..ffc530bc28 100644
--- a/test/models/plaid_account/type_mappable_test.rb
+++ b/test/models/plaid_account/type_mappable_test.rb
@@ -32,4 +32,18 @@ class PlaidAccount::TypeMappableTest < ActiveSupport::TestCase
assert_equal "other", @mock_processor.map_subtype("depository", nil)
assert_equal "other", @mock_processor.map_subtype("depository", "unknown")
end
+
+ test "every mapped subtype is a valid subtype of its accountable" do
+ PlaidAccount::TypeMappable::TYPE_MAPPING.each do |plaid_type, config|
+ accountable_class = config[:accountable]
+ next unless accountable_class.const_defined?(:SUBTYPES)
+
+ config[:subtype_mapping].each do |plaid_subtype, subtype|
+ assert_includes accountable_class::SUBTYPES.keys, subtype,
+ "TYPE_MAPPING maps #{plaid_type}/#{plaid_subtype.inspect} to #{subtype.inspect}, " \
+ "which is not a valid #{accountable_class} subtype — syncing such an account fails " \
+ "with 'Validation failed: Accountable subtype is not included in the list'"
+ end
+ end
+ end
end