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 3700b58
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 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
20 changes: 15 additions & 5 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 @@ -26,10 +26,12 @@
end

context "with one dep" do
let(:intake) { create(:state_file_nj_intake, :df_data_one_dep, municipality_code: "0101") }
let(:intake) { create(:state_file_nj_intake, :df_data_one_dep) }
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 @@ -41,15 +43,17 @@
end

context "with two deps" do
let(:intake) { create(:state_file_nj_intake, :df_data_two_deps, municipality_code: "0101") }
let(:intake) { create(:state_file_nj_intake, :df_data_two_deps) }
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

context "with many deps all under 5 yrs old" do
let(:intake) { create(:state_file_nj_intake, :df_data_many_deps, municipality_code: "0101") }
let(:intake) { create(:state_file_nj_intake, :df_data_many_deps) }

before do
five_years = Date.new(MultiTenantService.new(:statefile).current_tax_year - 5, 1, 1)
Expand All @@ -61,22 +65,28 @@
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

context "with many w2s" do
let(:intake) { create(:state_file_nj_intake, municipality_code: "0101", raw_direct_file_data: StateFile::DirectFileApiResponseSampleService.new.read_xml('nj_zeus_many_w2s')) }
let(:intake) { create(:state_file_nj_intake, raw_direct_file_data: StateFile::DirectFileApiResponseSampleService.new.read_xml('nj_zeus_many_w2s')) }
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

context "with two w2s" do
let(:intake) { create(:state_file_nj_intake, municipality_code: "0101", raw_direct_file_data: StateFile::DirectFileApiResponseSampleService.new.read_xml('nj_zeus_two_w2s')) }
let(:intake) { create(:state_file_nj_intake, raw_direct_file_data: StateFile::DirectFileApiResponseSampleService.new.read_xml('nj_zeus_two_w2s')) }
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 3700b58

Please sign in to comment.