From c010301a7ec83759d65ed0ffd3a7c078c5b8bed5 Mon Sep 17 00:00:00 2001 From: Seth Darr <92405130+sethdarragile6@users.noreply.github.com> Date: Fri, 8 Nov 2024 11:00:01 -0800 Subject: [PATCH] dbex/96289-validate-incoming-disabilities: now do it the RIGHT way... --- ...isability_compensation_forms_controller.rb | 23 ++++++++----------- .../v0/disability_compensation_form_spec.rb | 1 + 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/app/controllers/v0/disability_compensation_forms_controller.rb b/app/controllers/v0/disability_compensation_forms_controller.rb index f97c77f5c80..09c0814e4e2 100644 --- a/app/controllers/v0/disability_compensation_forms_controller.rb +++ b/app/controllers/v0/disability_compensation_forms_controller.rb @@ -53,14 +53,6 @@ def suggested_conditions def submit_all_claim saved_claim = SavedClaim::DisabilityCompensation::Form526AllClaim.from_hash(form_content) - - if missing_new_and_increase_disabilities?(saved_claim) - raise Common::Exceptions::UnprocessableEntity.new( - detail: 'no new or increased disabilities were submitted', - source: 'DisabilityCompensationFormsController' - ) - end - saved_claim.save ? log_success(saved_claim) : log_failure(saved_claim) submission = create_submission(saved_claim) # if jid = 0 then the submission was prevented from going any further in the process @@ -119,9 +111,7 @@ def lighthouse? end def create_submission(saved_claim) - Rails.logger.info( - 'Creating 526 submission', user_uuid: @current_user&.uuid, saved_claim_id: saved_claim&.id - ) + Rails.logger.info('Creating 526 submission', user_uuid: @current_user&.uuid, saved_claim_id: saved_claim&.id) submission = Form526Submission.new( user_uuid: @current_user.uuid, user_account: @current_user.user_account, @@ -130,6 +120,13 @@ def create_submission(saved_claim) form_json: saved_claim.to_submission_data(@current_user), submit_endpoint: includes_toxic_exposure? ? 'claims_api' : 'evss' ) { |sub| sub.add_birls_ids @current_user.birls_id } + + if missing_disabilities?(submission) + raise Common::Exceptions::UnprocessableEntity.new( + detail: 'no new or increased disabilities were submitted', source: 'DisabilityCompensationFormsController' + ) + end + submission.save! && submission rescue PG::NotNullViolation => e Rails.logger.error( @@ -165,8 +162,8 @@ def includes_toxic_exposure? form_content['form526']['startedFormVersion'] end - def missing_new_and_increase_disabilities?(saved_claim) - if saved_claim.form['updatedRatedDisabilities'].blank? && saved_claim.form['newPrimaryDisabilities'].blank? + def missing_disabilities?(submission) + if submission.form['form526']['form526']['disabilities'].none? StatsD.increment("#{stats_key}.failure") Rails.logger.error( 'Creating 526 submission: no new or increased disabilities were submitted', user_uuid: @current_user&.uuid diff --git a/spec/requests/v0/disability_compensation_form_spec.rb b/spec/requests/v0/disability_compensation_form_spec.rb index 72b93a32b60..4da1e24bc80 100644 --- a/spec/requests/v0/disability_compensation_form_spec.rb +++ b/spec/requests/v0/disability_compensation_form_spec.rb @@ -308,6 +308,7 @@ def test_error(cassette_path, status, headers) all_claims_form = File.read 'spec/support/disability_compensation_form/all_claims_fe_submission.json' json_object = JSON.parse(all_claims_form) json_object['form526'].delete('newPrimaryDisabilities') + json_object['form526'].delete('newSecondaryDisabilities') updated_form = JSON.generate(json_object) post('/v0/disability_compensation_form/submit_all_claim', params: updated_form, headers:) expect(response).to have_http_status(:unprocessable_entity)