diff --git a/app/lib/efile/line_data.yml b/app/lib/efile/line_data.yml index c6867204f7..531d24d1ae 100644 --- a/app/lib/efile/line_data.yml +++ b/app/lib/efile/line_data.yml @@ -766,12 +766,38 @@ MD502_SU_LINE_U: label: "TBD" MD502_SU_LINE_V: label: "TBD" +MD502_SU_LINE_U_PRIMARY: + label: "TBD" +MD502_SU_LINE_V_PRIMARY: + label: "TBD" +MD502_SU_LINE_U_SPOUSE: + label: "TBD" +MD502_SU_LINE_V_SPOUSE: + label: "TBD" MD502_SU_LINE_1: label: "1 Add lines a. through yc. and enter this amount on line 13 of Form 502 with the appropriate code letters" +MD502R_LINE_PRIMARY_DISABLED: + label: "Is Primary Taxpayer totally and permanently disabled? (intake question)" +MD502R_LINE_SPOUSE_DISABLED: + label: "Is Secondary Taxpayer totally and permanently disabled? (intake question)" +MD502R_LINE_1A: + label: "Retirement income received by Primary Taxpayer as a pension, annuity from employee retirement system qualified under Sections 401(a), 403 or 457(b)" +MD502R_LINE_1B: + label: "Retirement income received by Secondary Taxpayer as a pension, annuity from employee retirement system qualified under Sections 401(a), 403 or 457(b)" +MD502R_LINE_7A: + label: "Other retirement income and foreign retirement income received by Primary Taxpayer" +MD502R_LINE_7B: + label: "Other retirement income and foreign retirement income received by Secondary Taxpayer" +MD502R_LINE_8: + label: "Total of all retirement source income for primary and secondary taxpayers" MD502R_LINE_9A: label: "Total social security benefits for primary" MD502R_LINE_9B: label: "Total social security benefits for spouse" +MD502R_LINE_10A: + label: "Primary Taxpayer amount of military income subtracted on Form 502SU with code u and amount of Correctional officers, Law Enforcement officers, or fire, rescue, or emergency services personnel income subtracted on Form 502SU with code v" +MD502R_LINE_10B: + label: "Secondary Taxpayer amount of military income subtracted on Form 502SU with code u and amount of Correctional officers, Law Enforcement officers, or fire, rescue, or emergency services personnel income subtracted on Form 502SU with code v" NCD400_LINE_6: label: '6 Federal Adjusted Gross Income' NCD400_LINE_9: diff --git a/app/lib/efile/md/md502_r_calculator.rb b/app/lib/efile/md/md502_r_calculator.rb index 2b03a5d3e1..3038f32138 100644 --- a/app/lib/efile/md/md502_r_calculator.rb +++ b/app/lib/efile/md/md502_r_calculator.rb @@ -11,12 +11,51 @@ def initialize(value_access_tracker:, lines:, intake:) end def calculate + set_line(:MD502R_LINE_PRIMARY_DISABLED, :calculate_primary_disabled) + set_line(:MD502R_LINE_SPOUSE_DISABLED, :calculate_spouse_disabled) + set_line(:MD502R_LINE_1A, :calculate_line_1a) + set_line(:MD502R_LINE_1B, :calculate_line_1b) + set_line(:MD502R_LINE_7A, :calculate_line_7a) + set_line(:MD502R_LINE_7B, :calculate_line_7b) + set_line(:MD502R_LINE_8, :calculate_line_8) set_line(:MD502R_LINE_9A, :calculate_line_9a) set_line(:MD502R_LINE_9B, :calculate_line_9b) + set_line(:MD502R_LINE_10A, :calculate_line_10a) + set_line(:MD502R_LINE_10B, :calculate_line_10b) end private + def calculate_primary_disabled + @intake.primary_disabled_yes? ? "X" : nil + end + + def calculate_spouse_disabled + return unless @intake.filing_status_mfj? + + @intake.spouse_disabled_yes? ? "X" : nil + end + + def calculate_line_1a + @intake.sum_1099_r_followup_type_for_filer(@intake.filer_1099_rs(:primary), :income_source_pension_annuity_endowment?) + end + + def calculate_line_1b + @intake.sum_1099_r_followup_type_for_filer(@intake.filer_1099_rs(:spouse), :income_source_pension_annuity_endowment?) + end + + def calculate_line_7a + @intake.sum_1099_r_followup_type_for_filer(@intake.filer_1099_rs(:primary), :income_source_other?) + end + + def calculate_line_7b + @intake.sum_1099_r_followup_type_for_filer(@intake.filer_1099_rs(:spouse), :income_source_other?) + end + + def calculate_line_8 + [line_or_zero(:MD502R_LINE_1A), line_or_zero(:MD502R_LINE_1B), line_or_zero(:MD502R_LINE_7A), line_or_zero(:MD502R_LINE_7B)].sum + end + def calculate_line_9a if @intake.direct_file_data.fed_ssb.positive? if @intake.filing_status_mfj? @@ -32,6 +71,14 @@ def calculate_line_9b @intake.spouse_ssb_amount.round end end + + def calculate_line_10a + line_or_zero(:MD502_SU_LINE_U_PRIMARY) + line_or_zero(:MD502_SU_LINE_V_PRIMARY) + end + + def calculate_line_10b + line_or_zero(:MD502_SU_LINE_U_SPOUSE) + line_or_zero(:MD502_SU_LINE_V_SPOUSE) + end end end end diff --git a/app/lib/efile/md/md502_su_calculator.rb b/app/lib/efile/md/md502_su_calculator.rb index b7c610d804..de9a0c1b20 100644 --- a/app/lib/efile/md/md502_su_calculator.rb +++ b/app/lib/efile/md/md502_su_calculator.rb @@ -15,6 +15,10 @@ def calculate set_line(:MD502_SU_LINE_U, :calculate_line_u) # STUBBED: PLEASE REPLACE, don't forget line_data.yml set_line(:MD502_SU_LINE_V, :calculate_line_v) # STUBBED: PLEASE REPLACE, don't forget line_data.yml set_line(:MD502_SU_LINE_1, :calculate_line_1) + set_line(:MD502_SU_LINE_U_PRIMARY, :calculate_line_u_primary) # STUBBED: PLEASE REPLACE, don't forget line_data.yml + set_line(:MD502_SU_LINE_V_PRIMARY, :calculate_line_v_primary) # STUBBED: PLEASE REPLACE, don't forget line_data.yml + set_line(:MD502_SU_LINE_U_SPOUSE, :calculate_line_u_spouse) # STUBBED: PLEASE REPLACE, don't forget line_data.yml + set_line(:MD502_SU_LINE_V_SPOUSE, :calculate_line_v_spouse) # STUBBED: PLEASE REPLACE, don't forget line_data.yml end private @@ -23,6 +27,14 @@ def calculate_line_ab @direct_file_json_data.interest_reports.sum(&:interest_on_government_bonds).round end + def calculate_line_u_primary; end + + def calculate_line_v_primary; end + + def calculate_line_u_spouse; end + + def calculate_line_v_spouse; end + def calculate_line_u; end def calculate_line_v; end diff --git a/app/lib/pdf_filler/md502_r_pdf.rb b/app/lib/pdf_filler/md502_r_pdf.rb index e980b1bb2d..69fade62ca 100644 --- a/app/lib/pdf_filler/md502_r_pdf.rb +++ b/app/lib/pdf_filler/md502_r_pdf.rb @@ -26,6 +26,8 @@ def hash_for_pdf 'Spouses Social Security Number': @xml_document.at('Secondary TaxpayerSSN')&.text, 'Your Age 1': @xml_document.at('PrimaryAge')&.text, 'Spouses Age': @xml_document.at('SecondaryAge')&.text, + You: check_box_if_x(@xml_document.at('PriTotalPermDisabledIndicator')&.text), + Spouse: check_box_if_x(@xml_document.at('SecTotalPermDisabledIndicator')&.text), } if Flipper.enabled?(:show_md_ssa) answers.merge!( @@ -33,7 +35,22 @@ def hash_for_pdf "9b" => @xml_document.at('SecSSecurityRailRoadBenefits')&.text ) end + if Flipper.enabled?(:show_retirement_ui) + answers.merge!( + 'compensation plan or foreign retirement income 1a' => @xml_document.at('SourceRetirementIncome PrimaryTaxpayer EmployeeRetirementSystem')&.text, + '1b' => @xml_document.at('SourceRetirementIncome SecondaryTaxpayer EmployeeRetirementSystem')&.text, + 'including foreign retirement income 7a' => @xml_document.at('SourceRetirementIncome PrimaryTaxpayer OtherAndForeign')&.text, + '7b' => @xml_document.at('SourceRetirementIncome SecondaryTaxpayer OtherAndForeign')&.text, + 'income on lines 1z 4b and 5b of your federal Form 1040 and line 8t of your federal Schedule 1 8' => @xml_document.at('SourceRetirementIncome TotalPensionsIRAsAnnuities')&.text, + 'retirement from code letter v on Form 502SU income subtracted on Maryland Form 502 10a' => @xml_document.at('PriMilLawEnforceIncSub')&.text, + '10b' => @xml_document.at('SecMilLawEnforceIncSub')&.text, + ) + end answers end + + def check_box_if_x(value) + value == "X" ? 'On' : 'Off' + end end end diff --git a/app/lib/submission_builder/ty2024/states/md/documents/md502_r.rb b/app/lib/submission_builder/ty2024/states/md/documents/md502_r.rb index d29df8f25d..8befe3406c 100644 --- a/app/lib/submission_builder/ty2024/states/md/documents/md502_r.rb +++ b/app/lib/submission_builder/ty2024/states/md/documents/md502_r.rb @@ -12,8 +12,29 @@ def document build_xml_doc("Form502R", documentId: "Form502R") do |xml| xml.PrimaryAge @intake.calculate_age(@intake.primary_birth_date, inclusive_of_jan_1: false) xml.SecondaryAge @intake.calculate_age(@intake.spouse_birth_date, inclusive_of_jan_1: false) if @intake.filing_status_mfj? + if Flipper.enabled?(:show_retirement_ui) + add_element_if_present(xml, :PriTotalPermDisabledIndicator, :MD502R_LINE_PRIMARY_DISABLED) + add_element_if_present(xml, :SecTotalPermDisabledIndicator, :MD502R_LINE_SPOUSE_DISABLED) + xml.SourceRetirementIncome do + xml.PrimaryTaxpayer do + add_element_if_present(xml, :EmployeeRetirementSystem, :MD502R_LINE_1A) + add_element_if_present(xml, :OtherAndForeign, :MD502R_LINE_7A) + end + + if @intake.filing_status_mfj? + xml.SecondaryTaxpayer do + add_element_if_present(xml, :EmployeeRetirementSystem, :MD502R_LINE_1B) + add_element_if_present(xml, :OtherAndForeign, :MD502R_LINE_7B) + end + end + add_element_if_present(xml, :TotalPensionsIRAsAnnuities, :MD502R_LINE_8) + end + end + add_element_if_present(xml, :PriSSecurityRailRoadBenefits, :MD502R_LINE_9A) if Flipper.enabled?(:show_md_ssa) + add_element_if_present(xml, :PriMilLawEnforceIncSub, :MD502R_LINE_10A) if Flipper.enabled?(:show_retirement_ui) add_element_if_present(xml, :SecSSecurityRailRoadBenefits, :MD502R_LINE_9B) if Flipper.enabled?(:show_md_ssa) + add_element_if_present(xml, :SecMilLawEnforceIncSub, :MD502R_LINE_10B) if Flipper.enabled?(:show_retirement_ui) end end diff --git a/app/models/state_file_md_intake.rb b/app/models/state_file_md_intake.rb index 512099579f..af6c5d66ce 100644 --- a/app/models/state_file_md_intake.rb +++ b/app/models/state_file_md_intake.rb @@ -211,6 +211,22 @@ def address end end + def filer_1099_rs(primary_or_spouse) + state_file1099_rs.filter do |state_file_1099_r| + state_file_1099_r.recipient_ssn == send(primary_or_spouse).ssn + end + end + + def sum_1099_r_followup_type_for_filer(filer_1099_rs, followup_type) + filer_1099_rs.sum do |state_file_1099_r| + if state_file_1099_r.state_specific_followup&.send(followup_type) + state_file_1099_r.taxable_amount&.round + else + 0 + end + end + end + def extract_apartment_from_mailing_street? true end diff --git a/spec/factories/state_file_md1099_r_followups.rb b/spec/factories/state_file_md1099_r_followups.rb index 2530e9b4ac..a74cc40c07 100644 --- a/spec/factories/state_file_md1099_r_followups.rb +++ b/spec/factories/state_file_md1099_r_followups.rb @@ -10,6 +10,5 @@ # FactoryBot.define do factory :state_file_md1099_r_followup do - end end diff --git a/spec/lib/efile/md/md502_r_calculator_spec.rb b/spec/lib/efile/md/md502_r_calculator_spec.rb index a3edb13a59..b8d24c7cfc 100644 --- a/spec/lib/efile/md/md502_r_calculator_spec.rb +++ b/spec/lib/efile/md/md502_r_calculator_spec.rb @@ -2,7 +2,8 @@ describe Efile::Md::Md502RCalculator do let(:filing_status) { "single" } - let(:intake) { create(:state_file_md_intake, :df_data_2_w2s, filing_status: filing_status) } # df_data_2_w2s has $8000 in federal social security benefits + # df_data_2_w2s has $8000 in federal social security benefits + let(:intake) { create(:state_file_md_intake, :df_data_2_w2s, filing_status: filing_status) } let(:main_calculator) do Efile::Md::Md502Calculator.new( year: MultiTenantService.statefile.current_tax_year, @@ -11,6 +12,161 @@ end let(:instance) { main_calculator.instance_variable_get(:@md502r) } + describe "#calculate_line_00b_primary_disabled" do + let(:primary_disabled) { "no" } + let(:spouse_disabled) { "no" } + + before do + intake.update( + primary_disabled: primary_disabled, + spouse_disabled: spouse_disabled + ) + main_calculator.calculate + end + + context "primary filer is disabled" do + let(:primary_disabled) { "yes" } + + it "returns X" do + expect(instance.lines[:MD502R_LINE_PRIMARY_DISABLED].value).to eq 'X' + end + end + + context "primary filer is not disabled" do + let(:primary_disabled) { "no" } + + it "returns nil" do + expect(instance.lines[:MD502R_LINE_SPOUSE_DISABLED].value).to eq nil + end + end + + context "spouse filer is disabled" do + let(:spouse_disabled) { "yes" } + + it "returns nil" do + expect(instance.lines[:MD502R_LINE_SPOUSE_DISABLED].value).to eq nil + end + end + + context "spouse filer is not disabled" do + let(:spouse_disabled) { "no" } + + it "returns nil" do + expect(instance.lines[:MD502R_LINE_SPOUSE_DISABLED].value).to eq nil + end + end + + context "filing_status mfj" do + let(:filing_status) { "married_filing_jointly" } + + context "spouse filer is disabled" do + let(:spouse_disabled) { "yes" } + + it "returns X" do + expect(instance.lines[:MD502R_LINE_SPOUSE_DISABLED].value).to eq 'X' + end + end + + context "spouse filer is not disabled" do + let(:spouse_disabled) { "no" } + + it "returns nil" do + expect(instance.lines[:MD502R_LINE_SPOUSE_DISABLED].value).to eq nil + end + end + end + end + + [ + ['1a', :primary, :spouse, :pension_annuity_endowment, :other], + ['1b', :spouse, :primary, :pension_annuity_endowment, :other], + ['7a', :primary, :spouse, :other, :pension_annuity_endowment], + ['7b', :spouse, :primary, :other, :pension_annuity_endowment], + ].each do |line, recipient, not_recipient, income_source_to_sum, income_source_to_reject| + describe "#calculate_line_#{line}" do + let(:line_key) { "MD502R_LINE_#{line.upcase}" } + + context "with 1099rs" do + let(:income_source) { income_source_to_sum } + let(:other_income_source) { income_source_to_reject } + let!(:state_1099r_followup) do + create( + :state_file_md1099_r_followup, + income_source: income_source, + state_file1099_r: create(:state_file1099_r, taxable_amount: 25, intake: intake, recipient_ssn: intake.send(recipient).ssn) + ) + end + let!(:other_1099r_followup) { + create( + :state_file_md1099_r_followup, + income_source: other_income_source, + state_file1099_r: create(:state_file1099_r, taxable_amount: 50, intake: intake, recipient_ssn: intake.send(recipient).ssn) + ) + } + + before do + main_calculator.calculate + end + + context "with multiple pension_annunity_endowment 1099rs" do + let(:other_income_source) { income_source_to_sum } + + it "should add up all 1099r taxable_amount if all have pension_annuity_endowment income_source" do + expect(instance.lines[line_key].value).to eq 75 + end + end + + context "with only a single pension_annuity_endowment" do + it "should only return taxable_amount of 1099r with pension_annuity_endowment income_source" do + expect(instance.lines[line_key].value).to eq 25 + end + end + + context "with no single pension_annuity_endowment" do + let(:income_source) { income_source_to_reject } + + it "should return 0" do + expect(instance.lines[line_key].value).to eq 0 + end + end + end + + context "with only 1099rs of spouse" do + let!(:state_1099r_followup) do + create( + :state_file_md1099_r_followup, + income_source: income_source_to_sum, + state_file1099_r: create(:state_file1099_r, taxable_amount: 25, intake: intake, recipient_ssn: intake.send(not_recipient).ssn) + ) + end + + it "returns nil" do + expect(instance.lines[line_key]).to be_nil + end + end + + context "with no 1099rs" do + it "returns nil" do + expect(instance.lines[line_key]).to be_nil + end + end + end + end + + describe "#calculate_8" do + before do + allow_any_instance_of(described_class).to receive(:calculate_line_1a).and_return 100 + allow_any_instance_of(described_class).to receive(:calculate_line_1b).and_return 200 + allow_any_instance_of(described_class).to receive(:calculate_line_7a).and_return 300 + allow_any_instance_of(described_class).to receive(:calculate_line_7b).and_return 500 + end + + it "sums up all income" do + main_calculator.calculate + expect(instance.lines[:MD502R_LINE_8].value).to eq 1100 + end + end + describe '#calculate_9a' do context 'when filing MFJ with positive federal social security benefits' do let(:filing_status) { "married_filing_jointly" } @@ -62,6 +218,30 @@ end end end + + describe "#calculate_line_10a" do + before do + allow_any_instance_of(Efile::Md::Md502SuCalculator).to receive(:calculate_line_u_primary).and_return(10) + allow_any_instance_of(Efile::Md::Md502SuCalculator).to receive(:calculate_line_v_primary).and_return(20) + end + + it "returns the sum of MD502SU Line U and Line V for primary" do + main_calculator.calculate + expect(instance.lines[:MD502R_LINE_10A].value).to eq 30 + end + end + + describe "#calculate_line_10b" do + before do + allow_any_instance_of(Efile::Md::Md502SuCalculator).to receive(:calculate_line_u_spouse).and_return(30) + allow_any_instance_of(Efile::Md::Md502SuCalculator).to receive(:calculate_line_v_spouse).and_return(40) + end + + it "returns the sum of MD502SU Line U and Line V for spouse" do + main_calculator.calculate + expect(instance.lines[:MD502R_LINE_10B].value).to eq 70 + end + end end diff --git a/spec/lib/pdf_filler/md502_r_pdf_spec.rb b/spec/lib/pdf_filler/md502_r_pdf_spec.rb index dc952fff56..0989396db1 100644 --- a/spec/lib/pdf_filler/md502_r_pdf_spec.rb +++ b/spec/lib/pdf_filler/md502_r_pdf_spec.rb @@ -69,6 +69,54 @@ expect(pdf_fields["Spouses Age"]).to eq("64") end + end + + context "Part 3: Disability" do + before do + allow(Flipper).to receive(:enabled?).and_call_original + allow(Flipper).to receive(:enabled?).with(:show_retirement_ui).and_return(true) + end + + context "filers are disabled" do + before do + allow_any_instance_of(Efile::Md::Md502RCalculator).to receive(:calculate_primary_disabled).and_return "X" + allow_any_instance_of(Efile::Md::Md502RCalculator).to receive(:calculate_spouse_disabled).and_return "X" + end + + it "checks the relevant boxes" do + expect(pdf_fields["You"]).to eq("On") + expect(pdf_fields["Spouse"]).to eq("On") + end + end + + context "filers are not disabled" do + it "does not check the boxes" do + expect(pdf_fields["You"]).to eq("Off") + expect(pdf_fields["Spouse"]).to eq("Off") + end + end + end + + context "Part 4: Retirement and Pension Benefits" do + before do + allow(Flipper).to receive(:enabled?).and_call_original + allow(Flipper).to receive(:enabled?).with(:show_retirement_ui).and_return(true) + allow_any_instance_of(Efile::Md::Md502RCalculator).to receive(:calculate_line_1a).and_return 4 + allow_any_instance_of(Efile::Md::Md502RCalculator).to receive(:calculate_line_1b).and_return 3 + allow_any_instance_of(Efile::Md::Md502RCalculator).to receive(:calculate_line_7a).and_return 2 + allow_any_instance_of(Efile::Md::Md502RCalculator).to receive(:calculate_line_7b).and_return 1 + end + + it "output correct information" do + expect(pdf_fields["compensation plan or foreign retirement income 1a"]).to eq("4") + expect(pdf_fields["1b"]).to eq("3") + expect(pdf_fields["including foreign retirement income 7a"]).to eq("2") + expect(pdf_fields["7b"]).to eq("1") + expect(pdf_fields["income on lines 1z 4b and 5b of your federal Form 1040 and line 8t of your federal Schedule 1 8"]).to eq("10") + end + end + + context "Part 5: SecSSecurityRailRoadBenefits and Military/Public Safety Retirement Income" do context "Line 9" do before do allow_any_instance_of(Efile::Md::Md502RCalculator).to receive(:calculate_line_9a).and_return 100 @@ -82,6 +130,20 @@ expect(pdf_fields["9b"]).to eq("200") end end + + context "line 10" do + before do + allow(Flipper).to receive(:enabled?).and_call_original + allow(Flipper).to receive(:enabled?).with(:show_retirement_ui).and_return(true) + allow_any_instance_of(Efile::Md::Md502RCalculator).to receive(:calculate_line_10a).and_return 50 + allow_any_instance_of(Efile::Md::Md502RCalculator).to receive(:calculate_line_10b).and_return 68 + end + + it "output correct information" do + expect(pdf_fields["retirement from code letter v on Form 502SU income subtracted on Maryland Form 502 10a"]).to eq("50") + expect(pdf_fields["10b"]).to eq("68") + end + end end end end diff --git a/spec/lib/submission_builder/ty2024/states/md/documents/md502_r_spec.rb b/spec/lib/submission_builder/ty2024/states/md/documents/md502_r_spec.rb index ef6696ec35..5c244bb6cf 100644 --- a/spec/lib/submission_builder/ty2024/states/md/documents/md502_r_spec.rb +++ b/spec/lib/submission_builder/ty2024/states/md/documents/md502_r_spec.rb @@ -7,11 +7,11 @@ let(:build_response) { described_class.build(submission, validate: false) } let(:xml) { Nokogiri::XML::Document.parse(build_response.document.to_xml) } - it "generates a valid xml" do + after do expect(build_response.errors).to be_empty end - describe ".document" do + describe "Age section" do let(:primary_birth_date) { Date.new(MultiTenantService.statefile.current_tax_year - 65, 1, 1) } let(:secondary_birth_date) { Date.new(MultiTenantService.statefile.current_tax_year - 64, 1, 1) } @@ -20,17 +20,92 @@ intake.spouse_birth_date = secondary_birth_date end - it "Age section" do + it "should show ages of the filers" do expect(xml.at("Form502R PrimaryAge").text.to_i).to eq(65) expect(xml.at("Form502R SecondaryAge").text.to_i).to eq(64) end + end + + context "show_retirement_ui" do + before do + allow(Flipper).to receive(:enabled?).and_call_original + allow(Flipper).to receive(:enabled?).with(:show_retirement_ui).and_return(true) + end + + context "disability" do + context "filers are disabled" do + before do + allow_any_instance_of(Efile::Md::Md502RCalculator).to receive(:calculate_primary_disabled).and_return "X" + allow_any_instance_of(Efile::Md::Md502RCalculator).to receive(:calculate_spouse_disabled).and_return "X" + end + + it "outputs all relevant values" do + expect(xml.at("Form502R PriTotalPermDisabledIndicator").text).to eq("X") + expect(xml.at("Form502R SecTotalPermDisabledIndicator").text).to eq("X") + end + end + + context "filers are not disabled" do + it "outputs no values for disabled indicator" do + expect(xml.at("Form502R PriTotalPermDisabledIndicator")).to be_nil + expect(xml.at("Form502R SecTotalPermDisabledIndicator")).to be_nil + end + end + end + + context "SourceRetirementIncome section" do + context "with income" do + before do + allow_any_instance_of(Efile::Md::Md502RCalculator).to receive(:calculate_line_1a).and_return 100 + allow_any_instance_of(Efile::Md::Md502RCalculator).to receive(:calculate_line_1b).and_return 200 + allow_any_instance_of(Efile::Md::Md502RCalculator).to receive(:calculate_line_7a).and_return 500 + allow_any_instance_of(Efile::Md::Md502RCalculator).to receive(:calculate_line_7b).and_return 333 + allow_any_instance_of(Efile::Md::Md502RCalculator).to receive(:calculate_line_8).and_return 1133 + end + + it "outputs all relevant values" do + expect(xml.at("Form502R SourceRetirementIncome PrimaryTaxpayer EmployeeRetirementSystem").text).to eq("100") + expect(xml.at("Form502R SourceRetirementIncome PrimaryTaxpayer OtherAndForeign").text).to eq("500") + expect(xml.at("Form502R SourceRetirementIncome SecondaryTaxpayer EmployeeRetirementSystem").text).to eq("200") + expect(xml.at("Form502R SourceRetirementIncome SecondaryTaxpayer OtherAndForeign").text).to eq("333") + expect(xml.at("Form502R SourceRetirementIncome TotalPensionsIRAsAnnuities").text).to eq("1133") + end + end + + context "without income" do + it "should have empty nodes for this section" do + expect(xml.at("Form502R SourceRetirementIncome PrimaryTaxpayer EmployeeRetirementSystem").text).to eq("0") + expect(xml.at("Form502R SourceRetirementIncome PrimaryTaxpayer OtherAndForeign").text).to eq("0") + expect(xml.at("Form502R SourceRetirementIncome SecondaryTaxpayer EmployeeRetirementSystem").text).to eq("0") + expect(xml.at("Form502R SourceRetirementIncome SecondaryTaxpayer OtherAndForeign").text).to eq("0") + expect(xml.at("Form502R SourceRetirementIncome TotalPensionsIRAsAnnuities").text).to eq("0") + end + end + end + + context "PriMilLawEnforceIncSub and SecMilLawEnforceIncSub" do + before do + allow_any_instance_of(Efile::Md::Md502RCalculator).to receive(:calculate_line_10a).and_return 33 + allow_any_instance_of(Efile::Md::Md502RCalculator).to receive(:calculate_line_10b).and_return 66 + end + + it "should have empty nodes for this section" do + expect(xml.at("Form502R PriMilLawEnforceIncSub").text).to eq("33") + expect(xml.at("Form502R SecMilLawEnforceIncSub").text).to eq("66") + end + end + end + + context "show_md_ssa" do + before do + allow(Flipper).to receive(:enabled?).and_call_original + allow(Flipper).to receive(:enabled?).with(:show_md_ssa).and_return(true) + end context "Line 9" do before do allow_any_instance_of(Efile::Md::Md502RCalculator).to receive(:calculate_line_9a).and_return 100 allow_any_instance_of(Efile::Md::Md502RCalculator).to receive(:calculate_line_9b).and_return 200 - allow(Flipper).to receive(:enabled?).and_call_original - allow(Flipper).to receive(:enabled?).with(:show_md_ssa).and_return(true) end it "outputs all relevant values" do expect(xml.at("Form502R PriSSecurityRailRoadBenefits").text.to_i).to eq(100)