Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add XSD validations for NC D-400 Schedule S #5294

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,27 @@ class D400ScheduleS < SubmissionBuilder::Document
def document
build_xml_doc("FormNCD400ScheduleS") do |xml|
xml.DedFedAGI do
add_non_zero_value(xml, :USInterestInc, :NCD400_S_LINE_18)
add_non_zero_value(xml, :TaxPortSSRRB, :NCD400_S_LINE_19)
add_non_zero_value(xml, :ExmptIncFedRecInd, :NCD400_S_LINE_27)
add_non_zero_value(xml, :TotDedFromFAGI, :NCD400_S_LINE_41)
add_nc_amount_nn_value(xml, :USInterestInc, :NCD400_S_LINE_18)
add_nc_amount_nn_value(xml, :TaxPortSSRRB, :NCD400_S_LINE_19)
add_nc_amount_nn_value(xml, :ExmptIncFedRecInd, :NCD400_S_LINE_27)
add_nc_amount_nn_value(xml, :TotDedFromFAGI, :NCD400_S_LINE_41)
end
end
end

private

def calculated_fields
@calculated_fields ||= @submission.data_source.tax_calculator.calculate
end

def add_nc_amount_nn_value(xml, elem_name, line)
# validates based on NCUSAmountNNType
value = calculated_fields.fetch(line)&.round
if value&.positive? && value.to_s.size <= 12
xml.send(elem_name, value)
end
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
let(:xml) { Nokogiri::XML::Document.parse(build_response.document.to_xml) }

context "calculating DedFedAGI" do

before do
interest_report = instance_double(DirectFileJsonData::DfJsonInterestReport)
allow(interest_report).to receive(:interest_on_government_bonds).and_return 323.00
Expand All @@ -26,5 +25,35 @@
expect(xml.document.at('DedFedAGI TotDedFromFAGI').text).to eq "546"
end
end

context "values that aren't greater than 0, contain more than 12 digits or are nil" do
before do
allow_any_instance_of(Efile::Nc::D400ScheduleSCalculator).to receive(:calculate_line_18).and_return -100
intake.direct_file_data.fed_taxable_ssb = 0
allow_any_instance_of(Efile::Nc::D400ScheduleSCalculator).to receive(:calculate_line_27).and_return 9_999_999_999_999 # 13 digits
allow_any_instance_of(Efile::Nc::D400ScheduleSCalculator).to receive(:calculate_line_41).and_return nil
end

it "doesn't include them in the xml" do
expect(xml.document.at('DedFedAGI USInterestInc')).not_to be_present
expect(xml.document.at('DedFedAGI TaxPortSSRRB')).not_to be_present
expect(xml.document.at('DedFedAGI ExmptIncFedRecInd')).not_to be_present
expect(xml.document.at('DedFedAGI TotDedFromFAGI')).not_to be_present
end
end

context "values that are decimals" do
before do
allow_any_instance_of(Efile::Nc::D400ScheduleSCalculator).to receive(:calculate_line_18).and_return 100.24
allow_any_instance_of(Efile::Nc::D400ScheduleSCalculator).to receive(:calculate_line_27).and_return 100.77
allow_any_instance_of(Efile::Nc::D400ScheduleSCalculator).to receive(:calculate_line_41).and_return 100.34
end

it "rounds them to the closest integer" do
expect(xml.document.at('DedFedAGI USInterestInc').text).to eq "100"
expect(xml.document.at('DedFedAGI ExmptIncFedRecInd').text).to eq "101"
expect(xml.document.at('DedFedAGI TotDedFromFAGI').text).to eq "100"
end
end
end
end
Loading