From 82894d072b29ae49c8947f96b21fbcb0a0a7b383 Mon Sep 17 00:00:00 2001 From: Micah Frazier Date: Thu, 11 Apr 2024 11:13:42 -0600 Subject: [PATCH] Ndbex/80164 update success polling bug fix (#16279) * level set * level set with master * removing yarn.lock * Working json response * Refactor of burials controller * Added in test for Burial claim controller update * Added error checking * Refactoring because find_by! was causing all non BI claims to return RecordNotFound * Rubocop * The frontend always appears to be looking for a state json key even when an error occurs on the backend * Allow status of pending * pending actually is success as far as the frontend is concerned. I understood it correctly at first * Refactor of code per review team --- .../v0/burial_claims_controller.rb | 31 ++++++++++++------- .../v0/burial_claims_controller_spec.rb | 5 +++ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/app/controllers/v0/burial_claims_controller.rb b/app/controllers/v0/burial_claims_controller.rb index 620336c4f47..5ead02cc210 100644 --- a/app/controllers/v0/burial_claims_controller.rb +++ b/app/controllers/v0/burial_claims_controller.rb @@ -7,7 +7,19 @@ class BurialClaimsController < ClaimsBaseController service_tag 'burial-application' def show - render_burials_json + submission_attempt = determine_submission_attempt + if submission_attempt + state = submission_attempt.aasm_state == 'failure' ? 'failure' : 'success' + render(json: { data: { attributes: { state: } } }) + elsif central_mail_submission + render(json: central_mail_submission) + else + Rails.logger.error("ActiveRecord::RecordNotFound: Claim submission not found for claim_id: #{params[:id]}") + render(json: { data: { attributes: { state: 'not found' } } }, status: :not_found) + end + rescue => e + Rails.logger.error(e.to_s) + render(json: { data: { attributes: { state: 'error processing request' } } }, status: :unprocessable_entity) end def create @@ -44,19 +56,14 @@ def claim_class private - def render_burials_json - if (submission_attempt = determine_submission_attempt) - state = submission_attempt.aasm_state == 'failure' ? 'failure' : 'success' - render(json: { data: { attributes: { state: } } }) - else - render(json: CentralMailSubmission.joins(:central_mail_claim).find_by(saved_claims: { guid: params[:id] })) - end - end - def determine_submission_attempt - claim = claim_class.find_by!(guid: params[:id]) - form_submission = claim.form_submissions&.last + claim = claim_class.find_by(guid: params[:id]) + form_submission = claim&.form_submissions&.last form_submission&.form_submission_attempts&.last end + + def central_mail_submission + CentralMailSubmission.joins(:central_mail_claim).find_by(saved_claims: { guid: params[:id] }) + end end end diff --git a/spec/controllers/v0/burial_claims_controller_spec.rb b/spec/controllers/v0/burial_claims_controller_spec.rb index 2bfc11fbf18..a8e3393ad5c 100644 --- a/spec/controllers/v0/burial_claims_controller_spec.rb +++ b/spec/controllers/v0/burial_claims_controller_spec.rb @@ -45,5 +45,10 @@ def send_create expect(JSON.parse(response.body)['data']['attributes']['state']).to eq('success') end + + it 'returns an error if the claim is not found' do + get(:show, params: { id: '12345' }) + expect(response).to have_http_status(:not_found) + end end end