Skip to content

Commit

Permalink
[FYST-1788] Guard against nil values when summing up w2, 1099R state …
Browse files Browse the repository at this point in the history
…income tax / withheld amounts (#5635)

Co-authored-by: Martha Pidcock <[email protected]>
  • Loading branch information
arinchoi03 and mpidcock authored Feb 25, 2025
1 parent 096be0b commit 6d8f801
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/lib/efile/az/az140_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/lib/efile/id/id40_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions spec/lib/efile/az/az140_calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 35 additions & 7 deletions spec/lib/efile/id/id40_calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 6d8f801

Please sign in to comment.