From 3b76d6a39e55f32afaf9a099f99ae7cee660de16 Mon Sep 17 00:00:00 2001 From: ColinBruce Date: Fri, 10 Jan 2025 10:51:48 +0000 Subject: [PATCH 1/2] Chore: Address transaction type todo Remove the citizen values and update tests to stop referring to them. They were phased out many years ago and were left in place --- config/locales/cy/transaction_types.yml | 12 ------------ config/locales/en/transaction_types.yml | 15 --------------- spec/helpers/user_transactions_helper_spec.rb | 8 ++++---- 3 files changed, 4 insertions(+), 31 deletions(-) diff --git a/config/locales/cy/transaction_types.yml b/config/locales/cy/transaction_types.yml index d88e45dd1a..eff64a0c32 100644 --- a/config/locales/cy/transaction_types.yml +++ b/config/locales/cy/transaction_types.yml @@ -2,18 +2,6 @@ cy: transaction_types: names: - citizens: - benefits: stifeneB - child_care: stnemyap eracdlihC - excluded_benefits: stifeneb dedragersiD - friends_or_family: ylimaf ro sdneirf morf pleh laicnaniF - legal_aid: esac lanimirc a ni dia lagel sdrawot stnemyaP - maintenance_in: rentrap remrof a morf stnemyap ecnanetniaM - maintenance_out: rentrap remrof a ot stnemyap ecnanetniaM - pension: noisneP - property_or_lodger: regdol ro ytreporp a morf emocnI - rent_or_mortgage: stnemyap gnisuoH - salary: segaw ro yralaS providers: benefits: stifeneB child_care: stnemyap eracdlihC diff --git a/config/locales/en/transaction_types.yml b/config/locales/en/transaction_types.yml index d0086dbb34..83014cc01a 100644 --- a/config/locales/en/transaction_types.yml +++ b/config/locales/en/transaction_types.yml @@ -1,21 +1,6 @@ en: transaction_types: names: - # TODO: remove this as we don't actually show transaction categories to citizens anymore, however these categories are still - # being used in a few places, and have tests and helper methods which will also need to be updated/removed - citizens: - benefits: Benefits, charitable or government payments - child_care: Childcare payments - excluded_benefits: Disregarded benefits - friends_or_family: Financial help from friends or family - housing_benefit: Housing Benefit - legal_aid: Payments towards legal aid in a criminal case - maintenance_in: Maintenance payments from a former partner - maintenance_out: Maintenance payments to a former partner - pension: Pension - property_or_lodger: Income from a property or lodger - rent_or_mortgage: Housing payments - salary: Salary or wages providers: benefits: Benefits, charitable or government payments child_care: Childcare payments diff --git a/spec/helpers/user_transactions_helper_spec.rb b/spec/helpers/user_transactions_helper_spec.rb index b1253fc36a..d21b653c2f 100644 --- a/spec/helpers/user_transactions_helper_spec.rb +++ b/spec/helpers/user_transactions_helper_spec.rb @@ -16,8 +16,8 @@ describe "#incomings_list" do subject(:helper_incomings_list) { helper.incomings_list(legal_aid_application.transaction_types.credits, locale_namespace:) } - context "when for a citizen" do - let(:locale_namespace) { "transaction_types.names.citizens" } + context "when for a provider" do + let(:locale_namespace) { "transaction_types.names.providers" } it "returns correct hash" do expect(helper_incomings_list[:items].first.to_h).to match hash_result @@ -46,8 +46,8 @@ let(:transaction_type) { create(:transaction_type, :maintenance_out) } - context "when for a citizen" do - let(:locale_namespace) { "transaction_types.names.citizens" } + context "when for a provider" do + let(:locale_namespace) { "transaction_types.names.providers" } it "returns correct hash" do expect(helper_payments_list[:items].first.to_h).to match hash_result From ad6a666bcc4173a5c3cdb94e25dbcef09faf1449 Mon Sep 17 00:00:00 2001 From: ColinBruce Date: Fri, 10 Jan 2025 11:06:49 +0000 Subject: [PATCH 2/2] Remove the user_transactions_helper completely I cannot find a reference to eother of the methods in this class being called, anywhere in the code. This is a speculative commit to see if that is a false positive and tests start to fail --- app/helpers/user_transactions_helper.rb | 35 --------- spec/helpers/user_transactions_helper_spec.rb | 73 ------------------- 2 files changed, 108 deletions(-) delete mode 100644 app/helpers/user_transactions_helper.rb delete mode 100644 spec/helpers/user_transactions_helper_spec.rb diff --git a/app/helpers/user_transactions_helper.rb b/app/helpers/user_transactions_helper.rb deleted file mode 100644 index 604777a844..0000000000 --- a/app/helpers/user_transactions_helper.rb +++ /dev/null @@ -1,35 +0,0 @@ -module UserTransactionsHelper - TransactionItemStruct = Struct.new(:label, :name, :amount_text) - - def incomings_list(incomings, locale_namespace:) - items = TransactionType.credits&.map do |income_type| - next if income_type.disregarded_benefit? - - TransactionItemStruct.new(t("#{locale_namespace}.#{income_type.name}"), - income_type.name, - yes_no(incomings.pluck(:name).include?(income_type.name))) - end - - return nil if items.blank? - - { - items: items.compact, - } - end - - def payments_list(payments, locale_namespace:) - items = TransactionType.debits&.map do |payment_type| - TransactionItemStruct.new( - t("#{locale_namespace}.#{payment_type.name}"), - payment_type.name, - yes_no(payments.pluck(:name).include?(payment_type.name)), - ) - end - - return nil if items.blank? - - { - items:, - } - end -end diff --git a/spec/helpers/user_transactions_helper_spec.rb b/spec/helpers/user_transactions_helper_spec.rb deleted file mode 100644 index d21b653c2f..0000000000 --- a/spec/helpers/user_transactions_helper_spec.rb +++ /dev/null @@ -1,73 +0,0 @@ -require "rails_helper" - -RSpec.describe UserTransactionsHelper do - let(:transaction_type) { create(:transaction_type, :pension) } - let(:legal_aid_application) do - create(:legal_aid_application, :with_applicant, transaction_types: [transaction_type]) - end - let(:locale_namespace) { "" } - - before do - allow(helper).to( - receive(:yes_no).with(boolean).and_return(true), - ) - end - - describe "#incomings_list" do - subject(:helper_incomings_list) { helper.incomings_list(legal_aid_application.transaction_types.credits, locale_namespace:) } - - context "when for a provider" do - let(:locale_namespace) { "transaction_types.names.providers" } - - it "returns correct hash" do - expect(helper_incomings_list[:items].first.to_h).to match hash_result - end - - context "with excluded state benefit" do - let(:transaction_type) { create(:transaction_type, :excluded_benefits) } - - it "returns correct hash" do - expect(helper_incomings_list[:items]).to be_empty - end - end - - context "with no transactions" do - let(:legal_aid_application) { create(:legal_aid_application) } - - it "returns nil" do - expect(helper_incomings_list).to be_nil - end - end - end - end - - describe "#payments_list" do - subject(:helper_payments_list) { helper.payments_list(legal_aid_application.transaction_types.debits, locale_namespace:) } - - let(:transaction_type) { create(:transaction_type, :maintenance_out) } - - context "when for a provider" do - let(:locale_namespace) { "transaction_types.names.providers" } - - it "returns correct hash" do - expect(helper_payments_list[:items].first.to_h).to match hash_result - end - - context "with no transactions" do - let(:legal_aid_application) { create(:legal_aid_application) } - - it "returns nil" do - expect(helper_payments_list).to be_nil - end - end - end - end - - def hash_result - { - label: I18n.t("#{locale_namespace}.#{transaction_type.name}"), - name: transaction_type.name, - amount_text: true, - } - end -end