The personal finance app for everyone (by everyone)
Ruby
Expose reporting exclusion on account API responses (#5344)
al0816-netizen34ad5e9bc49f
diff --git a/app/views/api/v1/accounts/_account.json.jbuilder b/app/views/api/v1/accounts/_account.json.jbuilderindex b38c3b1a6d..080f054602 100644--- a/app/views/api/v1/accounts/_account.json.jbuilder+++ b/app/views/api/v1/accounts/_account.json.jbuilder@@ -14,6 +14,7 @@ json.classification account.classificationjson.account_type account.accountable_type&.underscorejson.subtype account.subtypejson.status account.status+json.exclude_from_reports account.exclude_from_reports?json.institution_name account.institution_namejson.institution_domain account.institution_domainjson.created_at account.created_at.iso8601diff --git a/docs/api/openapi.yaml b/docs/api/openapi.yamlindex 860664dad9..baf61043fc 100644--- a/docs/api/openapi.yaml+++ b/docs/api/openapi.yaml@@ -668,6 +668,7 @@ components:- classification- account_type- status+ - exclude_from_reports- created_at- updated_atproperties:@@ -703,6 +704,10 @@ components:- draft- disabled- pending_deletion+ exclude_from_reports:+ type: boolean+ readOnly: true+ description: Whether this account is excluded from financial reportsinstitution_name:type: stringnullable: truediff --git a/spec/swagger_helper.rb b/spec/swagger_helper.rbindex 236b70b9a3..cbd0dddd44 100644--- a/spec/swagger_helper.rb+++ b/spec/swagger_helper.rb@@ -433,7 +433,7 @@ RSpec.configure do |config|},AccountDetail: {type: :object,- required: %w[id name balance balance_cents cash_balance cash_balance_cents currency classification account_type status created_at updated_at],+ required: %w[id name balance balance_cents cash_balance cash_balance_cents currency classification account_type status exclude_from_reports created_at updated_at],properties: {id: { type: :string, format: :uuid },name: { type: :string },@@ -446,6 +446,7 @@ RSpec.configure do |config|account_type: { type: :string, nullable: true },subtype: { type: :string, nullable: true },status: { type: :string, enum: %w[active draft disabled pending_deletion] },+ exclude_from_reports: { type: :boolean, readOnly: true, description: 'Whether this account is excluded from financial reports' },institution_name: { type: :string, nullable: true },institution_domain: { type: :string, nullable: true },created_at: { type: :string, format: :'date-time' },diff --git a/test/controllers/api/v1/accounts_controller_test.rb b/test/controllers/api/v1/accounts_controller_test.rbindex 65e1715cde..5ac659ea9f 100644--- a/test/controllers/api/v1/accounts_controller_test.rb+++ b/test/controllers/api/v1/accounts_controller_test.rb@@ -96,6 +96,24 @@ class Api::V1::AccountsControllerTest < ActionDispatch::IntegrationTestassert_not_includes account_names, inactive_account.nameend+ test "reports the exclusion flag without hiding excluded account identities" do+ account = accounts(:depository)+ get "/api/v1/accounts/#{account.id}", headers: api_headers(@api_key)+ assert_response :success+ assert_equal false, JSON.parse(response.body).fetch("exclude_from_reports")++ account.update!(exclude_from_reports: true)+ get "/api/v1/accounts", params: { per_page: 100 }, headers: api_headers(@api_key)+ assert_response :success+ row = JSON.parse(response.body).fetch("accounts").find { |item| item["id"] == account.id }+ assert_not_nil row+ assert_equal true, row.fetch("exclude_from_reports")++ get "/api/v1/accounts/#{account.id}", headers: api_headers(@api_key)+ assert_response :success+ assert_equal true, JSON.parse(response.body).fetch("exclude_from_reports")+ end+test "should include disabled accounts when requested" doinactive_account = accounts(:depository)inactive_account.disable!