From 99f4d080fcfa78f6327670246546117baed17364 Mon Sep 17 00:00:00 2001 From: Jennica Stiehl <25069483+stiehlrod@users.noreply.github.com> Date: Wed, 6 Nov 2024 14:08:19 -0700 Subject: [PATCH 1/4] Add transform method to v1 526 validations to change unitName to be an empty string if it is blank or empty. Adds test for nil and blank unitName. --- .../disability_compensation_validations.rb | 8 ++++ .../spec/requests/v1/forms/526_spec.rb | 38 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/modules/claims_api/app/controllers/concerns/claims_api/disability_compensation_validations.rb b/modules/claims_api/app/controllers/concerns/claims_api/disability_compensation_validations.rb index fee9f042177..0f790ba675b 100644 --- a/modules/claims_api/app/controllers/concerns/claims_api/disability_compensation_validations.rb +++ b/modules/claims_api/app/controllers/concerns/claims_api/disability_compensation_validations.rb @@ -25,6 +25,8 @@ def validate_form_526_submission_values! validate_service_after_13th_birthday! # ensure 'militaryRetiredPay.receiving' and 'militaryRetiredPay.willReceiveInFuture' are not same non-null values validate_form_526_service_pay! + # ensure an error is avoided if the unit name is not provided + transform_form_526_unit_name! # ensure 'title10ActivationDate' if provided, is after the earliest servicePeriod.activeDutyBeginDate and on or before the current date # rubocop:disable Layout/LineLength validate_form_526_title10_activation_date! # ensure 'title10Activation.anticipatedSeparationDate' is in the future @@ -140,6 +142,12 @@ def validate_form_526_title10_anticipated_separation_date! ) end + def transform_form_526_unit_name! + unit_name = form_attributes&.dig('serviceInformation', 'reservesNationalGuardService', 'unitName') + unit_name = ' ' if unit_name&.blank? || unit_name&.empty? + form_attributes['serviceInformation']['reservesNationalGuardService']['unitName'] = unit_name + end + def validate_form_526_submission_claim_date! return if form_attributes['claimDate'].blank? return if DateTime.parse(form_attributes['claimDate']) <= Time.zone.now diff --git a/modules/claims_api/spec/requests/v1/forms/526_spec.rb b/modules/claims_api/spec/requests/v1/forms/526_spec.rb index 9c1a10d5671..a741a5386fe 100644 --- a/modules/claims_api/spec/requests/v1/forms/526_spec.rb +++ b/modules/claims_api/spec/requests/v1/forms/526_spec.rb @@ -872,6 +872,44 @@ end end end + + context "when 'unitName' is empty" do + let(:unit_name) { '' } + + it 'returns a successful response' do + mock_acg(scopes) do |auth_header| + VCR.use_cassette('claims_api/bgs/claims/claims') do + VCR.use_cassette('claims_api/brd/countries') do + par = json_data + par['data']['attributes']['serviceInformation']['reservesNationalGuardService']['unitName'] = + unit_name + + post path, params: par.to_json, headers: headers.merge(auth_header) + expect(response).to have_http_status(:ok) + end + end + end + end + end + + context "when 'unitName' is nil" do + let(:unit_name) { nil } + + it 'returns a successful response' do + mock_acg(scopes) do |auth_header| + VCR.use_cassette('claims_api/bgs/claims/claims') do + VCR.use_cassette('claims_api/brd/countries') do + par = json_data + par['data']['attributes']['serviceInformation']['reservesNationalGuardService']['unitName'] = + unit_name + + post path, params: par.to_json, headers: headers.merge(auth_header) + expect(response).to have_http_status(:unprocessable_entity) + end + end + end + end + end end end From 44b90e877569eaa80c9217c306cc616963285229 Mon Sep 17 00:00:00 2001 From: Jennica Stiehl <25069483+stiehlrod@users.noreply.github.com> Date: Wed, 6 Nov 2024 14:16:26 -0700 Subject: [PATCH 2/4] Adds return in case the reservesNationalGuardService is not provided. --- .../concerns/claims_api/disability_compensation_validations.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/claims_api/app/controllers/concerns/claims_api/disability_compensation_validations.rb b/modules/claims_api/app/controllers/concerns/claims_api/disability_compensation_validations.rb index 0f790ba675b..a571b4bdfec 100644 --- a/modules/claims_api/app/controllers/concerns/claims_api/disability_compensation_validations.rb +++ b/modules/claims_api/app/controllers/concerns/claims_api/disability_compensation_validations.rb @@ -143,6 +143,8 @@ def validate_form_526_title10_anticipated_separation_date! end def transform_form_526_unit_name! + return if form_attributes&.dig('serviceInformation', 'reservesNationalGuardService').nil? + unit_name = form_attributes&.dig('serviceInformation', 'reservesNationalGuardService', 'unitName') unit_name = ' ' if unit_name&.blank? || unit_name&.empty? form_attributes['serviceInformation']['reservesNationalGuardService']['unitName'] = unit_name From 0b4c76ac7bcbfbe1d34e1e6620959ba86e233988 Mon Sep 17 00:00:00 2001 From: Jennica Stiehl <25069483+stiehlrod@users.noreply.github.com> Date: Thu, 7 Nov 2024 08:12:07 -0700 Subject: [PATCH 3/4] Refactors transform_form_526_unit_name. Adds test case. --- .../disability_compensation_validations.rb | 9 +++++---- .../spec/requests/v1/forms/526_spec.rb | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/modules/claims_api/app/controllers/concerns/claims_api/disability_compensation_validations.rb b/modules/claims_api/app/controllers/concerns/claims_api/disability_compensation_validations.rb index a571b4bdfec..5e6db5d8804 100644 --- a/modules/claims_api/app/controllers/concerns/claims_api/disability_compensation_validations.rb +++ b/modules/claims_api/app/controllers/concerns/claims_api/disability_compensation_validations.rb @@ -143,11 +143,12 @@ def validate_form_526_title10_anticipated_separation_date! end def transform_form_526_unit_name! - return if form_attributes&.dig('serviceInformation', 'reservesNationalGuardService').nil? + reserves = form_attributes&.dig('serviceInformation', 'reservesNationalGuardService') + return if reserves.nil? - unit_name = form_attributes&.dig('serviceInformation', 'reservesNationalGuardService', 'unitName') - unit_name = ' ' if unit_name&.blank? || unit_name&.empty? - form_attributes['serviceInformation']['reservesNationalGuardService']['unitName'] = unit_name + unit_name = reserves['unitName'] + unit_name = unit_name.presence || ' ' + reserves['unit_name'] = unit_name end def validate_form_526_submission_claim_date! diff --git a/modules/claims_api/spec/requests/v1/forms/526_spec.rb b/modules/claims_api/spec/requests/v1/forms/526_spec.rb index a741a5386fe..6cceeb23872 100644 --- a/modules/claims_api/spec/requests/v1/forms/526_spec.rb +++ b/modules/claims_api/spec/requests/v1/forms/526_spec.rb @@ -910,6 +910,22 @@ end end end + + context "when 'unitName' is not present" do + it 'returns a successful response' do + mock_acg(scopes) do |auth_header| + VCR.use_cassette('claims_api/bgs/claims/claims') do + VCR.use_cassette('claims_api/brd/countries') do + par = json_data + par['data']['attributes']['serviceInformation']['reservesNationalGuardService'].delete('unitName') + + post path, params: par.to_json, headers: headers.merge(auth_header) + expect(response).to have_http_status(:unprocessable_entity) + end + end + end + end + end end end From cfa71478f8e63a5359b934594b978dfb7be9efb5 Mon Sep 17 00:00:00 2001 From: Jennica Stiehl <25069483+stiehlrod@users.noreply.github.com> Date: Fri, 8 Nov 2024 13:05:18 -0700 Subject: [PATCH 4/4] Moves transform method to aut_est_claim. Adds test. Tests for unitName transformation. --- .../disability_compensation_validations.rb | 11 ----------- .../models/claims_api/auto_established_claim.rb | 10 ++++++++++ .../spec/models/auto_establish_claim_spec.rb | 15 +++++++++++++++ .../claims_api/spec/requests/v1/forms/526_spec.rb | 9 +++++++-- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/modules/claims_api/app/controllers/concerns/claims_api/disability_compensation_validations.rb b/modules/claims_api/app/controllers/concerns/claims_api/disability_compensation_validations.rb index 5e6db5d8804..fee9f042177 100644 --- a/modules/claims_api/app/controllers/concerns/claims_api/disability_compensation_validations.rb +++ b/modules/claims_api/app/controllers/concerns/claims_api/disability_compensation_validations.rb @@ -25,8 +25,6 @@ def validate_form_526_submission_values! validate_service_after_13th_birthday! # ensure 'militaryRetiredPay.receiving' and 'militaryRetiredPay.willReceiveInFuture' are not same non-null values validate_form_526_service_pay! - # ensure an error is avoided if the unit name is not provided - transform_form_526_unit_name! # ensure 'title10ActivationDate' if provided, is after the earliest servicePeriod.activeDutyBeginDate and on or before the current date # rubocop:disable Layout/LineLength validate_form_526_title10_activation_date! # ensure 'title10Activation.anticipatedSeparationDate' is in the future @@ -142,15 +140,6 @@ def validate_form_526_title10_anticipated_separation_date! ) end - def transform_form_526_unit_name! - reserves = form_attributes&.dig('serviceInformation', 'reservesNationalGuardService') - return if reserves.nil? - - unit_name = reserves['unitName'] - unit_name = unit_name.presence || ' ' - reserves['unit_name'] = unit_name - end - def validate_form_526_submission_claim_date! return if form_attributes['claimDate'].blank? return if DateTime.parse(form_attributes['claimDate']) <= Time.zone.now diff --git a/modules/claims_api/app/models/claims_api/auto_established_claim.rb b/modules/claims_api/app/models/claims_api/auto_established_claim.rb index da0eea02c3d..9e3f9dfe1b2 100644 --- a/modules/claims_api/app/models/claims_api/auto_established_claim.rb +++ b/modules/claims_api/app/models/claims_api/auto_established_claim.rb @@ -81,6 +81,7 @@ def to_internal # rubocop:disable Metrics/MethodLength resolve_homelessness_risk_situation_type_mappings! transform_homelessness_point_of_contact_primary_phone! transform_address_lines_length! + transform_empty_unit_name! { form526: form_data @@ -510,5 +511,14 @@ def transform_address_lines_length! form_data['veteran']['currentMailingAddress'] = addr end + + def transform_empty_unit_name! + reserves = form_data&.dig('serviceInformation', 'reservesNationalGuardService') + return if reserves.nil? + + unit_name = reserves['unitName'] + unit_name = unit_name.presence || ' ' + reserves['unitName'] = unit_name + end end end diff --git a/modules/claims_api/spec/models/auto_establish_claim_spec.rb b/modules/claims_api/spec/models/auto_establish_claim_spec.rb index 35de560af2d..abde8f74612 100644 --- a/modules/claims_api/spec/models/auto_establish_claim_spec.rb +++ b/modules/claims_api/spec/models/auto_establish_claim_spec.rb @@ -532,6 +532,21 @@ end end + describe '#transform_empty_unit_name!' do + let(:unit_name) { '' } + + it 'trasforms an empty unit name to a space' do + temp_form_data = pending_record.form_data + temp_form_data['serviceInformation']['reservesNationalGuardService']['unitName'] = unit_name + + pending_record.form_data = temp_form_data + payload = JSON.parse(pending_record.to_internal) + name = payload['form526']['serviceInformation']['reservesNationalGuardService']['unitName'] + + expect(name).to eq(' ') + end + end + describe 'evss_id_by_token' do context 'with a record' do let(:evss_record) { create(:auto_established_claim, evss_id: 123_456) } diff --git a/modules/claims_api/spec/requests/v1/forms/526_spec.rb b/modules/claims_api/spec/requests/v1/forms/526_spec.rb index 6cceeb23872..179eb872f5d 100644 --- a/modules/claims_api/spec/requests/v1/forms/526_spec.rb +++ b/modules/claims_api/spec/requests/v1/forms/526_spec.rb @@ -886,6 +886,11 @@ post path, params: par.to_json, headers: headers.merge(auth_header) expect(response).to have_http_status(:ok) + response_body = JSON.parse(response.body) + claim_id = response_body['data']['id'] + claim = ClaimsApi::AutoEstablishedClaim.find(claim_id) + claim.to_internal + expect(claim.form_data['serviceInformation']['reservesNationalGuardService']['unitName']).to eq(' ') end end end @@ -895,7 +900,7 @@ context "when 'unitName' is nil" do let(:unit_name) { nil } - it 'returns a successful response' do + it 'returns a unsuccessful response' do mock_acg(scopes) do |auth_header| VCR.use_cassette('claims_api/bgs/claims/claims') do VCR.use_cassette('claims_api/brd/countries') do @@ -912,7 +917,7 @@ end context "when 'unitName' is not present" do - it 'returns a successful response' do + it 'returns a unsuccessful response' do mock_acg(scopes) do |auth_header| VCR.use_cassette('claims_api/bgs/claims/claims') do VCR.use_cassette('claims_api/brd/countries') do