Skip to content

Commit

Permalink
dbex/94369: Remove dates from LH submit request for unselected locati…
Browse files Browse the repository at this point in the history
…on/hazard options - "other" objects (#18781)
  • Loading branch information
aurora-a-k-a-lightning authored Oct 8, 2024
1 parent 83fe089 commit 3179069
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ def transform_toxic_exposure(toxic_exposure_source) # rubocop:disable Metrics/Me
MULTIPLE_EXPOSURES_TYPE[:herbicide])
end

if values_present(toxic_exposure_source['otherHerbicideLocations'])
if values_present(other_herbicide_locations) && other_herbicide_locations['description'].present?
multiple_exposures +=
transform_multiple_exposures_other_details(toxic_exposure_source['otherHerbicideLocations'],
transform_multiple_exposures_other_details(other_herbicide_locations,
MULTIPLE_EXPOSURES_TYPE[:herbicide])
end

Expand All @@ -300,9 +300,9 @@ def transform_toxic_exposure(toxic_exposure_source) # rubocop:disable Metrics/Me
MULTIPLE_EXPOSURES_TYPE[:hazard])
end

if values_present(toxic_exposure_source['specifyOtherExposures'])
if values_present(specify_other_exposures) && specify_other_exposures['description'].present?
multiple_exposures +=
transform_multiple_exposures_other_details(toxic_exposure_source['specifyOtherExposures'],
transform_multiple_exposures_other_details(specify_other_exposures,
MULTIPLE_EXPOSURES_TYPE[:hazard])
end

Expand Down Expand Up @@ -410,7 +410,7 @@ def transform_gulf_war(gulf_war1990, gulf_war2001)
def transform_herbicide(herbicide, other_herbicide_locations)
filtered_results_herbicide = herbicide&.filter { |k| k != 'notsure' }
herbicide_value = (values_present(filtered_results_herbicide) ||
values_present(other_herbicide_locations)) &&
(other_herbicide_locations.present? && other_herbicide_locations['description'].present?)) &&
!none_of_these(filtered_results_herbicide)

herbicide_service = Requests::HerbicideHazardService.new
Expand All @@ -420,7 +420,10 @@ def transform_herbicide(herbicide, other_herbicide_locations)
end

def transform_other_exposures(other_exposures, specify_other_exposures)
return nil if none_of_these(other_exposures) && !values_present(specify_other_exposures)
if none_of_these(other_exposures) &&
(specify_other_exposures.present? && specify_other_exposures['description'].blank?)
return nil
end

filtered_results_other_exposures = other_exposures&.filter { |k, v| k != 'notsure' && v }
additional_hazard_exposures_service = Requests::AdditionalHazardExposures.new
Expand All @@ -429,7 +432,9 @@ def transform_other_exposures(other_exposures, specify_other_exposures)
HAZARDS_LH_ENUM[k.to_sym]
end
end
other = HAZARDS_LH_ENUM[:other] if values_present(specify_other_exposures)
if specify_other_exposures.present? && specify_other_exposures['description'].present?
other = HAZARDS_LH_ENUM[:other]
end
additional_hazard_exposures_service.additional_exposures << other if other.present?
return nil if additional_hazard_exposures_service.additional_exposures == []

Expand Down Expand Up @@ -743,6 +748,7 @@ def convert_date_no_day(date)

# somehow, partial dates with the 'XX' (i.e. "2020-01-XX or 2020-XX-XX") are getting past FE validation
# fix here in the backend while a proper FE solution is found
return nil if year.downcase.include?('x')
return year if month.blank? || month.upcase == 'XX'
return "#{year}-#{month}" if day.blank? || day.upcase == 'XX'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,67 @@
end
end

describe 'specifyOtherExposure and otherHerbicideLocations' do
let(:submission) { create(:form526_submission, :with_everything_toxic_exposure) }
let(:data) { submission.form['form526'] }

context 'multiple exposures' do
it 'is processed if descriptions are present' do
# specifyOtherExposure and otherHerbicideLocations should be processed if descriptions are present
data['form526']['toxicExposure'] = {
'gulfWar2001Details' => {},
'gulfWar1990Details' => {},
'herbicide' => {},
'herbicideDetails' => {},
'otherExposureDetails' => {},
'specifyOtherExposures' => {
'description' => 'specifyOtherExposures',
'startDate' => '1992-01-01',
'endDate' => '1993-01-01'
},
'otherHerbicideLocations' => {
'description' => 'otherHerbicideLocations',
'startDate' => '1992-01-01',
'endDate' => '1993-01-01'
}
}
result = transformer.transform(data)

# "other" objects should have been processed for MultipleExposures because the descriptions are there
expect(result.toxic_exposure.multiple_exposures.length).to eq(2)
expect(result.toxic_exposure.multiple_exposures.first.exposure_location).to eq('otherHerbicideLocations')
expect(result.toxic_exposure.multiple_exposures.first.hazard_exposed_to).to eq(nil)
expect(result.toxic_exposure.multiple_exposures.last.exposure_location).to eq(nil)
expect(result.toxic_exposure.multiple_exposures.last.hazard_exposed_to).to eq('specifyOtherExposures')
end

it 'is not processed if missing descriptions' do
# specifyOtherExposure and otherHerbicideLocations should not be processed if missing descriptions
data['form526']['toxicExposure'] = {
'gulfWar2001Details' => {},
'gulfWar1990Details' => {},
'herbicide' => {},
'herbicideDetails' => {},
'otherExposureDetails' => {},
'specifyOtherExposures' => {
'description' => ' ',
'startDate' => '1992-01-01',
'endDate' => '1993-01-01'
},
'otherHerbicideLocations' => {
'description' => ' ',
'startDate' => '1992-01-01',
'endDate' => '1993-01-01'
}
}
result = transformer.transform(data)
# nothing should have been processed for MultipleExposures because
# all of the details are missing and the descriptions are missing in the "other" objects
expect(result.toxic_exposure.multiple_exposures).to eq([])
end
end
end

describe '#evss_claims_process_type' do
let(:submission) { create(:form526_submission, :with_everything) }
let(:data) { submission.form['form526'] }
Expand Down Expand Up @@ -534,6 +595,14 @@
date = '2024'
result = transformer.send(:convert_date_no_day, date)
expect(result).to eq('2024')

date = 'XXXX'
result = transformer.send(:convert_date_no_day, date)
expect(result).to eq(nil)

date = 'XX-XX-XX'
result = transformer.send(:convert_date_no_day, date)
expect(result).to eq(nil)
end

it 'set served_in_herbicide_hazard_locations correctly' do
Expand Down Expand Up @@ -606,6 +675,31 @@
result = transformer.send(:transform_herbicide, other_herbicide_locations_has_blank_fields['herbicide'],
other_herbicide_locations_has_blank_fields['otherHerbicideLocations'])
expect(result.served_in_herbicide_hazard_locations).to eq('NO')

# description must be in the otherHerbicideLocations object for it to be processed (blank string)
other_herbicide_locations_description_blank = data.merge({
'herbicide' => nil,
'otherHerbicideLocations' => {
'description' => '',
'startDate' => '1992-01-01',
'endDate' => '1992-01-01'
}
})
result = transformer.send(:transform_herbicide, other_herbicide_locations_description_blank['herbicide'],
other_herbicide_locations_description_blank['otherHerbicideLocations'])
expect(result.served_in_herbicide_hazard_locations).to eq('NO')

# description must be in the otherHerbicideLocations object for it to be processed (attribute missing)
other_herbicide_locations_description_missing = data.merge({
'herbicide' => nil,
'otherHerbicideLocations' => {
'startDate' => '1992-01-01',
'endDate' => '1992-01-01'
}
})
result = transformer.send(:transform_herbicide, other_herbicide_locations_description_missing['herbicide'],
other_herbicide_locations_description_missing['otherHerbicideLocations'])
expect(result.served_in_herbicide_hazard_locations).to eq('NO')
end

it 'set additional_hazard_exposures correctly' do
Expand Down Expand Up @@ -709,6 +803,32 @@
result = transformer.send(:transform_other_exposures, none_option_with_no_other['otherExposures'],
none_option_with_no_other['specifyOtherExposures'])
expect(result).to eq(nil)

# description must be in the specifyOtherExposures object for it to be processed (blank string)
no_option_with_no_other_blank_string = data.merge({
'otherExposures' => {},
'specifyOtherExposures' => {
'description' => '',
'startDate' => '1991-03-01',
'endDate' => '1992-01-01'
}
})
result = transformer.send(:transform_other_exposures, no_option_with_no_other_blank_string['otherExposures'],
no_option_with_no_other_blank_string['specifyOtherExposures'])
expect(result).to eq(nil)

# description must be in the specifyOtherExposures object for it to be processed (missing attribute)
no_option_with_no_other_missing = data.merge({
'otherExposures' => {},
'specifyOtherExposures' => {
'startDate' => '1991-03-01',
'endDate' => '1992-01-01'
}
})
result = transformer.send(:transform_other_exposures, no_option_with_no_other_missing['otherExposures'],
no_option_with_no_other_missing['specifyOtherExposures'])

expect(result).to eq(nil)
end

it 'filters unselected items from details objects correctly' do
Expand Down

0 comments on commit 3179069

Please sign in to comment.