From f1b17acf6bd85d282d2f2e98c538e0fe87cd1812 Mon Sep 17 00:00:00 2001 From: Micah Frazier Date: Tue, 9 Apr 2024 15:27:31 -0600 Subject: [PATCH] Ndbex/80164 update success polling (#16252) * level set * level set with master * removing yarn.lock * Working json response * Refactor of burials controller * Added in test for Burial claim controller update --- .../v0/burial_claims_controller.rb | 21 +++++++++++++++++++ .../v0/burial_claims_controller_spec.rb | 10 ++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/controllers/v0/burial_claims_controller.rb b/app/controllers/v0/burial_claims_controller.rb index 77d398fb6b5..620336c4f47 100644 --- a/app/controllers/v0/burial_claims_controller.rb +++ b/app/controllers/v0/burial_claims_controller.rb @@ -6,6 +6,10 @@ module V0 class BurialClaimsController < ClaimsBaseController service_tag 'burial-application' + def show + render_burials_json + end + def create PensionBurial::TagSentry.tag_sentry @@ -37,5 +41,22 @@ def short_name def claim_class SavedClaim::Burial end + + 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 + form_submission&.form_submission_attempts&.last + end end end diff --git a/spec/controllers/v0/burial_claims_controller_spec.rb b/spec/controllers/v0/burial_claims_controller_spec.rb index a3e1a6e74b2..2bfc11fbf18 100644 --- a/spec/controllers/v0/burial_claims_controller_spec.rb +++ b/spec/controllers/v0/burial_claims_controller_spec.rb @@ -30,12 +30,20 @@ def send_create end describe '#show' do - it 'returns the submission status' do + it 'returns the submission status when the claim uses central mail' do claim = create(:burial_claim) claim.central_mail_submission.update!(state: 'success') get(:show, params: { id: claim.guid }) expect(JSON.parse(response.body)['data']['attributes']['state']).to eq('success') end + + it 'returns the submission status when the claim uses benefits intake' do + claim = create(:burial_claim) + claim.form_submissions << create(:form_submission, :pending, form_type: '21P-530') + get(:show, params: { id: claim.guid }) + + expect(JSON.parse(response.body)['data']['attributes']['state']).to eq('success') + end end end