Skip to content

Commit

Permalink
dbex/96289-validate-incoming-disabilities: now do it the RIGHT way...
Browse files Browse the repository at this point in the history
  • Loading branch information
sethdarragile6 committed Nov 8, 2024
1 parent fa32c12 commit c010301
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
23 changes: 10 additions & 13 deletions app/controllers/v0/disability_compensation_forms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/requests/v0/disability_compensation_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c010301

Please sign in to comment.