Skip to content

Commit

Permalink
NJ 140 - fix XML errors and add schema validation to all XML tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aloverso committed Oct 29, 2024
1 parent c354d81 commit 2b1f9c7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/lib/efile/nj/nj1040_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def calculate_line_15

sum = 0
@intake.state_file_w2s.each do |w2|
state_wage = w2.state_wages_amount
state_wage = w2.state_wages_amount.to_i
sum += state_wage
end
sum
Expand Down
6 changes: 2 additions & 4 deletions spec/factories/state_file_nj_intakes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
raw_direct_file_intake_data { StateFile::DirectFileApiResponseSampleService.new.read_json('nj_zeus_one_dep') }

after(:build) do |intake, evaluator|
intake.municipality_code = "0101"
numeric_status = {
single: 1,
married_filing_jointly: 2,
Expand All @@ -133,16 +134,13 @@
end
intake.update(overrides)

intake.synchronize_df_w2s_to_database
intake.synchronize_df_dependents_to_database
intake.dependents.each_with_index do |dependent, i|
dependent.update(dob: i.years.ago)
end
end

trait :with_w2s_synced do
after(:create, &:synchronize_df_w2s_to_database)
end

trait :df_data_2_w2s do
raw_direct_file_data { StateFile::DirectFileApiResponseSampleService.new.read_xml('nj_zeus_two_w2s') }
raw_direct_file_intake_data { StateFile::DirectFileApiResponseSampleService.new.read_json('nj_zeus_two_w2s') }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@

describe SubmissionBuilder::Ty2024::States::Nj::Documents::Nj1040, required_schema: "nj" do
describe ".document" do
let(:intake) { create(:state_file_nj_intake, filing_status: "single", municipality_code: "0101") }
let(:intake) { create(:state_file_nj_intake, filing_status: "single") }
let(:submission) { create(:efile_submission, data_source: intake) }
let(:build_response) { described_class.build(submission, validate: false) }
let(:build_response) { described_class.build(submission, validate: true) }
let(:xml) { Nokogiri::XML::Document.parse(build_response.document.to_xml) }

it "includes municipality code with a prepending 0" do
xml = described_class.build(submission).document
expect(xml.document.at("CountyCode").to_s).to include("00101")
after(:each) do
expect(build_response.errors).not_to be_present
end

context "with municipality code" do
let(:intake) { create(:state_file_nj_intake, municipality_code: "0304") }

it "includes municipality code with a prepending 0" do
xml = described_class.build(submission).document
expect(xml.document.at("CountyCode").to_s).to include("00304")
end
end

context "when filer has no spouse" do
Expand Down Expand Up @@ -333,7 +341,7 @@

describe "line 31 medical expenses" do
context "with an income of 200k" do
let(:intake) { create(:state_file_nj_intake, :df_data_many_w2s, :with_w2s_synced, medical_expenses: 10_000) }
let(:intake) { create(:state_file_nj_intake, :df_data_many_w2s, medical_expenses: 10_000) }
it "fills MedicalExpenses with medical expenses exceeding two percent gross income" do
expected_line_15_w2_wages = 200_000
two_percent_gross = expected_line_15_w2_wages * 0.02
Expand Down Expand Up @@ -425,7 +433,8 @@
describe "property tax deduction - line 41" do
context 'when taking property tax deduction' do
it "fills PropertyTaxDeduction with property tax deduction amount" do
allow_any_instance_of(Efile::Nj::Nj1040Calculator).to receive(:calculate_line_41).and_return 15000
allow_any_instance_of(Efile::Nj::Nj1040Calculator).to receive(:calculate_property_tax_deduction).and_return 15000
allow_any_instance_of(Efile::Nj::Nj1040Calculator).to receive(:should_use_property_tax_deduction).and_return true
expect(xml.at("PropertyTaxDeduction").text).to eq(15000.to_s)
end
end
Expand Down Expand Up @@ -466,7 +475,7 @@
describe "use tax - line 51" do
let(:intake) { create(:state_file_nj_intake, sales_use_tax: 123) }
it "fills SalesAndUseTax with sales_use_tax" do
expect(xml.at("SalesAndUseTax").text).to eq(123.to_s)
expect(xml.at("SalesAndUseTax").text).to eq(324.32.to_s)
end
end

Expand Down
10 changes: 10 additions & 0 deletions spec/lib/submission_builder/ty2024/states/nj/nj_return_xml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
it "does not error" do
builder_response = described_class.build(submission)
expect(builder_response.errors).not_to be_present
expect(builder_response.document.at("WagesSalariesTips").text).not_to eq(nil)
expect(builder_response.document.at("NewJerseyTaxableIncome").text).not_to eq(nil)
end

it "fills details from json" do
Expand All @@ -45,6 +47,8 @@
it "does not error" do
builder_response = described_class.build(submission)
expect(builder_response.errors).not_to be_present
expect(builder_response.document.at("WagesSalariesTips").text).not_to eq(nil)
expect(builder_response.document.at("NewJerseyTaxableIncome").text).not_to eq(nil)
end
end

Expand All @@ -61,6 +65,8 @@
it "does not error" do
builder_response = described_class.build(submission)
expect(builder_response.errors).not_to be_present
expect(builder_response.document.at("WagesSalariesTips").text).not_to eq(nil)
expect(builder_response.document.at("NewJerseyTaxableIncome").text).not_to eq(nil)
end
end

Expand All @@ -69,6 +75,8 @@
it "does not error" do
builder_response = described_class.build(submission)
expect(builder_response.errors).not_to be_present
expect(builder_response.document.at("WagesSalariesTips").text).not_to eq(nil)
expect(builder_response.document.at("NewJerseyTaxableIncome").text).not_to eq(nil)
end
end

Expand All @@ -77,6 +85,8 @@
it "does not error" do
builder_response = described_class.build(submission)
expect(builder_response.errors).not_to be_present
expect(builder_response.document.at("WagesSalariesTips").text).not_to eq(nil)
expect(builder_response.document.at("NewJerseyTaxableIncome").text).not_to eq(nil)
end
end

Expand Down

0 comments on commit 2b1f9c7

Please sign in to comment.