Skip to content

Commit

Permalink
Fix return header for MD (#5232)
Browse files Browse the repository at this point in the history
  • Loading branch information
tahsinaislam authored Dec 19, 2024
1 parent 7eb681a commit 6630dbb
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 15 deletions.
10 changes: 5 additions & 5 deletions app/lib/submission_builder/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ def extract_apartment_from_mailing_street(xml)
truncated_mailing_street = mailing_street[0...key_position].rstrip
excess_characters = mailing_street[key_position..].lstrip

xml.AddressLine1Txt sanitize_for_xml(truncated_mailing_street, 35)
xml.AddressLine1Txt sanitize_for_xml(truncated_mailing_street, 30)
if @submission.data_source.direct_file_data.mailing_apartment.present?
apartment = sanitize_for_xml(@submission.data_source.direct_file_data.mailing_apartment)
if apartment.length + excess_characters.length > 35
truncated_apartment = apartment[0, 35 - excess_characters.length].rpartition(' ').first
if apartment.length + excess_characters.length > 30
truncated_apartment = apartment[0, 30 - excess_characters.length].rpartition(' ').first
xml.AddressLine2Txt "#{excess_characters} #{truncated_apartment}"
else
xml.AddressLine2Txt "#{excess_characters} #{apartment}"
Expand All @@ -135,8 +135,8 @@ def extract_apartment_from_mailing_street(xml)
xml.AddressLine2Txt excess_characters
end
else
xml.AddressLine1Txt sanitize_for_xml(mailing_street, 35)
xml.AddressLine2Txt sanitize_for_xml(@submission.data_source.direct_file_data.mailing_apartment, 35) if @submission.data_source.direct_file_data.mailing_apartment.present?
xml.AddressLine1Txt sanitize_for_xml(mailing_street, 30)
xml.AddressLine2Txt sanitize_for_xml(@submission.data_source.direct_file_data.mailing_apartment, 30) if @submission.data_source.direct_file_data.mailing_apartment.present?
end
end

Expand Down
4 changes: 3 additions & 1 deletion app/lib/submission_builder/return_header.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ def document
xml.AddressLine1Txt sanitize_for_xml(@submission.data_source.direct_file_data.mailing_street, 35) if @submission.data_source.direct_file_data.mailing_street.present?
xml.AddressLine2Txt sanitize_for_xml(@submission.data_source.direct_file_data.mailing_apartment, 35) if @submission.data_source.direct_file_data.mailing_apartment.present?
end
xml.CityNm sanitize_for_xml(@submission.data_source.direct_file_data.mailing_city, 22) if @submission.data_source.direct_file_data.mailing_city.present?
if @submission.data_source.direct_file_data.mailing_city.present?
xml.CityNm sanitize_for_xml(@submission.data_source.direct_file_data.mailing_city, @submission.data_source.city_name_length_20? ? 20 : 22)
end
xml.StateAbbreviationCd @submission.data_source.state_code.upcase
xml.ZIPCd @submission.data_source.direct_file_data.mailing_zip if @submission.data_source.direct_file_data.mailing_zip.present?
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ def document
xml.MarylandAddress do
if @intake.confirmed_permanent_address_yes?
extract_apartment_from_mailing_street(xml)
xml.CityNm sanitize_for_xml(@intake.direct_file_data.mailing_city, 22)
xml.CityNm sanitize_for_xml(@intake.direct_file_data.mailing_city, 20)
xml.StateAbbreviationCd @intake.state_code.upcase
xml.ZIPCd @intake.direct_file_data.mailing_zip
elsif @intake.confirmed_permanent_address_no?
xml.AddressLine1Txt sanitize_for_xml(@intake.permanent_street, 35)
xml.AddressLine2Txt sanitize_for_xml(@intake.permanent_apartment, 35) if @intake.permanent_apartment.present?
xml.CityNm sanitize_for_xml(@intake.permanent_city, 22)
xml.AddressLine1Txt sanitize_for_xml(@intake.permanent_street, 30)
xml.AddressLine2Txt sanitize_for_xml(@intake.permanent_apartment, 30) if @intake.permanent_apartment.present?
xml.CityNm sanitize_for_xml(@intake.permanent_city, 20)
xml.StateAbbreviationCd @intake.state_code.upcase
xml.ZIPCd @intake.permanent_zip
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/state_file_base_intake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ def extract_apartment_from_mailing_street?
false
end

def city_name_length_20?
false
end

def ask_spouse_esign?
filing_status_mfj? && !spouse_deceased?
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/state_file_md_intake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ def extract_apartment_from_mailing_street?
true
end

def city_name_length_20?
true
end

def allows_refund_amount_in_xml?
false
end
Expand Down
32 changes: 32 additions & 0 deletions spec/lib/submission_builder/ty2022/states/return_header_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,38 @@
end
end

context "city field character limit" do
let(:mailing_city) { "This is a Very Long City Name" }

before do
intake.direct_file_data.mailing_city = mailing_city
end

StateFile::StateInformationService.active_state_codes.without("md").each do |state_code|
context "if state is not MD" do
let(:intake) { create "state_file_#{state_code}_intake".to_sym }
let(:submission) { create(:efile_submission, data_source: intake) }
let(:doc) { SubmissionBuilder::ReturnHeader.new(submission).document }

it "truncates city name to 22 characters" do
expect(doc.at("USAddress CityNm").text.length).to be 22
expect(doc.at("USAddress CityNm").text).to eq('This is a Very Long Ci')
end
end
end

context "if state is MD" do
let(:intake) { create :state_file_md_intake }
let(:submission) { create(:efile_submission, data_source: intake) }
let(:doc) { SubmissionBuilder::ReturnHeader.new(submission).document }

it "truncates city name to 20 characters" do
expect(doc.at("USAddress CityNm").text.length).to be 19
expect(doc.at("USAddress CityNm").text).to eq('This is a Very Long')
end
end
end

context "MD filer personal info includes signature PINs" do
let(:intake) {
create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,22 @@
end

it 'puts apartment on second address line' do
expect(xml.at("MarylandAddress AddressLine1Txt").text.length).to be <= 35
expect(xml.at("MarylandAddress AddressLine1Txt").text.length).to be 26
expect(xml.at("MarylandAddress AddressLine1Txt").text).to eq('2598 HICKORY HEIGHTS DRIVE')
expect(xml.at("MarylandAddress AddressLine2Txt").text).to eq('APT 21')
end
end

context "when mailing address is longer than 35 characters" do
context "when mailing address is longer than 30 characters" do
before do
intake.confirmed_permanent_address_yes!
intake.direct_file_data.mailing_street = '211212 SUBDIVISION DRIVE POST OFFICE BOX NUMBER 157'
intake.direct_file_data.mailing_apartment = ''
end

it 'truncates mailing address under 35 characters' do
expect(xml.at("MarylandAddress AddressLine1Txt").text.length).to be <= 35
expect(xml.at("MarylandAddress AddressLine1Txt").text).to eq('211212 SUBDIVISION DRIVE POST OFFIC')
it 'truncates mailing address to 30 characters' do
expect(xml.at("MarylandAddress AddressLine1Txt").text.length).to be 29
expect(xml.at("MarylandAddress AddressLine1Txt").text).to eq('211212 SUBDIVISION DRIVE POST')
expect(xml.at("MarylandAddress AddressLine2Txt")).not_to be_present
end
end
Expand Down

0 comments on commit 6630dbb

Please sign in to comment.