Skip to content

Commit

Permalink
Ndbex/80164 update success polling (#16252)
Browse files Browse the repository at this point in the history
* level set

* level set with master

* removing yarn.lock

* Working json response

* Refactor of burials controller

* Added in test for Burial claim controller update
  • Loading branch information
micahaspyr authored Apr 9, 2024
1 parent e79e70d commit f1b17ac
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
21 changes: 21 additions & 0 deletions app/controllers/v0/burial_claims_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
10 changes: 9 additions & 1 deletion spec/controllers/v0/burial_claims_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f1b17ac

Please sign in to comment.