From 6d8f8016ba16017f0766e0ce4ce0c1b7718379fe Mon Sep 17 00:00:00 2001 From: Yejee Arin Choi Date: Tue, 25 Feb 2025 11:32:07 -0800 Subject: [PATCH] [FYST-1788] Guard against nil values when summing up w2, 1099R state income tax / withheld amounts (#5635) Co-authored-by: Martha Pidcock --- app/lib/efile/az/az140_calculator.rb | 4 +-- app/lib/efile/id/id40_calculator.rb | 2 +- spec/lib/efile/az/az140_calculator_spec.rb | 22 ++++++++++++ spec/lib/efile/id/id40_calculator_spec.rb | 42 ++++++++++++++++++---- 4 files changed, 60 insertions(+), 10 deletions(-) diff --git a/app/lib/efile/az/az140_calculator.rb b/app/lib/efile/az/az140_calculator.rb index 2a1ca4926b..cd46978d6e 100644 --- a/app/lib/efile/az/az140_calculator.rb +++ b/app/lib/efile/az/az140_calculator.rb @@ -274,9 +274,9 @@ def calculate_line_52 # AZ income tax withheld: sum of tax withheld from all income documents: W-2, 1099-R, 1099-G, 1099-INT def calculate_line_53 - @intake.state_file_w2s.sum { |item| item.state_income_tax_amount.round } + + @intake.state_file_w2s.sum { |item| item.state_income_tax_amount&.round || 0 } + @intake.state_file1099_gs.sum { |item| item.state_income_tax_withheld_amount.round } + - @intake.state_file1099_rs.sum { |item| item.state_tax_withheld_amount.round } + @intake.state_file1099_rs.sum { |item| item.state_tax_withheld_amount&.round || 0 } end def calculate_line_56 diff --git a/app/lib/efile/id/id40_calculator.rb b/app/lib/efile/id/id40_calculator.rb index e2dbc5a96b..c961dfa6bb 100644 --- a/app/lib/efile/id/id40_calculator.rb +++ b/app/lib/efile/id/id40_calculator.rb @@ -251,7 +251,7 @@ def calculate_line_43 end def calculate_line_46 - @intake.state_file_w2s.sum { |item| item.state_income_tax_amount.round } + + @intake.state_file_w2s.sum { |item| item.state_income_tax_amount&.round || 0 } + @intake.state_file1099_gs.sum { |item| item.state_income_tax_withheld_amount.round } + @intake.state_file1099_rs.sum do |item| item.state_tax_withheld_amount&.round || 0 diff --git a/spec/lib/efile/az/az140_calculator_spec.rb b/spec/lib/efile/az/az140_calculator_spec.rb index 723340d280..7354d23afe 100644 --- a/spec/lib/efile/az/az140_calculator_spec.rb +++ b/spec/lib/efile/az/az140_calculator_spec.rb @@ -392,6 +392,28 @@ instance.calculate expect(instance.lines[:AZ140_LINE_53].value).to eq(900 + 50 + 100) end + + context "with nil state_income_tax_amount for W2" do + before do + intake.state_file_w2s.first&.update(state_income_tax_amount: nil) + end + + it "sums up all relevant values without error" do + instance.calculate + expect(instance.lines[:AZ140_LINE_53].value).to eq(50 + 100) + end + end + + context "with nil state_income_tax_amount for W2" do + before do + intake.state_file1099_rs.first&.update(state_tax_withheld_amount: nil) + end + + it "sums up all relevant values without error" do + instance.calculate + expect(instance.lines[:AZ140_LINE_53].value).to eq(900 + 100) + end + end end describe "Line 56: Increased Excise Tax Credit" do diff --git a/spec/lib/efile/id/id40_calculator_spec.rb b/spec/lib/efile/id/id40_calculator_spec.rb index c7896d2a8e..9b098f69e1 100644 --- a/spec/lib/efile/id/id40_calculator_spec.rb +++ b/spec/lib/efile/id/id40_calculator_spec.rb @@ -568,17 +568,34 @@ end context "when there are income forms" do - context "which have no state tax withheld" do - # Miranda has two W-2s with state tax withheld amount (507, 1502) and two 1099Rs with no state tax withheld - # but we will not sync in this context to leave values blank in db + # Miranda has two W-2s with state tax withheld amount (507, 1502) and two 1099Rs with no state tax withheld + # but we will not sync in this context to leave values blank in db + let(:intake) { + create(:state_file_id_intake, + raw_direct_file_data: StateFile::DirectFileApiResponseSampleService.new.read_xml('id_miranda_1099r')) + } + let!(:state_file1099_g) { create(:state_file1099_g, intake: intake, state_income_tax_withheld_amount: 0) } + let!(:state_file1099_r) { create(:state_file1099_r, intake: intake, state_tax_withheld_amount: 0) } + + context "which have 0 state tax withheld" do + it "should return 0" do + instance.calculate + expect(instance.lines[:ID40_LINE_46].value).to eq(0) + end + end + + context "which have nil state tax withheld" do let(:intake) { create(:state_file_id_intake, - raw_direct_file_data: StateFile::DirectFileApiResponseSampleService.new.read_xml('id_miranda_1099r')) + :with_eligible_1099r_income, + raw_direct_file_data: StateFile::DirectFileApiResponseSampleService.new.read_xml('id_miranda_1099r'), + ) } - let!(:state_file1099_g) { create(:state_file1099_g, intake: intake, state_income_tax_withheld_amount: 0) } - let!(:state_file1099_r) { create(:state_file1099_r, intake: intake, state_tax_withheld_amount: 0) } + before do + intake.state_file1099_rs.first&.update!(state_tax_withheld_amount: nil) + end - it "should return 0" do + it 'sums the ID tax withheld from 1099gs and 1099rs without error' do instance.calculate expect(instance.lines[:ID40_LINE_46].value).to eq(0) end @@ -597,6 +614,17 @@ instance.calculate expect(instance.lines[:ID40_LINE_46].value).to eq(10 + 507 + 1502 + 200) end + + context "which have nil state_income_tax_amount" do + before do + intake.state_file_w2s.first&.update(state_income_tax_amount: nil) + end + + it 'sums the ID tax withheld from 1099gs and 1099rs without error' do + instance.calculate + expect(instance.lines[:ID40_LINE_46].value).to eq(10 + 1502 + 200) + end + end end context "which have state tax withheld on ineligible 1099s" do