Skip to content

Commit

Permalink
[Automated] Merged master into target k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
va-vsp-bot authored Apr 11, 2024
2 parents a3d5a92 + 82894d0 commit fb70c57
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
31 changes: 19 additions & 12 deletions app/controllers/v0/burial_claims_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
5 changes: 5 additions & 0 deletions spec/controllers/v0/burial_claims_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit fb70c57

Please sign in to comment.