From f0a25a592986e4b25642c172f35c32b4f48f73de Mon Sep 17 00:00:00 2001 From: rockwellwindsor-va Date: Mon, 23 Sep 2024 16:01:40 -0500 Subject: [PATCH] API-40256-set-5103-status-errored-if-errored * Sets errored status if an error occurs. * Handles setting status back to pending after the upload succeeds * Adds tests modified: modules/claims_api/app/sidekiq/claims_api/evidence_waiver_builder_job.rb modified: modules/claims_api/app/sidekiq/claims_api/service_base.rb modified: modules/claims_api/spec/sidekiq/service_base_spec.rb --- .../claims_api/evidence_waiver_builder_job.rb | 12 ++++++++++ .../app/sidekiq/claims_api/service_base.rb | 5 ++++ .../spec/sidekiq/service_base_spec.rb | 23 +++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/modules/claims_api/app/sidekiq/claims_api/evidence_waiver_builder_job.rb b/modules/claims_api/app/sidekiq/claims_api/evidence_waiver_builder_job.rb index c56c86c1a1d..bd06d354324 100644 --- a/modules/claims_api/app/sidekiq/claims_api/evidence_waiver_builder_job.rb +++ b/modules/claims_api/app/sidekiq/claims_api/evidence_waiver_builder_job.rb @@ -20,9 +20,15 @@ def perform(evidence_waiver_id) # upload to BD benefits_doc_api.upload(claim: lighthouse_claim, pdf_path: output_path, doc_type: 'L705', pctpnt_vet_id: auth_headers['target_veteran_folder_id']) + + # with a successful upload we can set this back to pending if it errored previously + update_status_for_submssion(lighthouse_claim) + ClaimsApi::EwsUpdater.perform_async(evidence_waiver_id) ::Common::FileHelpers.delete_file_if_exists(output_path) rescue => e + set_state_for_submission(lighthouse_claim, ClaimsApi::EvidenceWaiverSubmission::ERRORED) + ClaimsApi::Logger.log('EWS_builder', retry: true, detail: 'failed to upload to BD') raise e end @@ -30,5 +36,11 @@ def perform(evidence_waiver_id) def benefits_doc_api ClaimsApi::BD.new end + + def update_status_for_submission(lighthouse_claim) + pending_state = ClaimsApi::EvidenceWaiverSubmission::PENDING + + set_state_for_submission(lighthouse_claim, pending_state) if lighthouse_claim.status != pending_state + end end end diff --git a/modules/claims_api/app/sidekiq/claims_api/service_base.rb b/modules/claims_api/app/sidekiq/claims_api/service_base.rb index 89b136e3d93..f6eb593bead 100644 --- a/modules/claims_api/app/sidekiq/claims_api/service_base.rb +++ b/modules/claims_api/app/sidekiq/claims_api/service_base.rb @@ -40,6 +40,11 @@ def retry_limits_for_notification protected + def set_state_for_submission(submission, state) + submission.status = state + submission.save! + end + def preserve_original_form_data(form_data) form_data.deep_dup.freeze end diff --git a/modules/claims_api/spec/sidekiq/service_base_spec.rb b/modules/claims_api/spec/sidekiq/service_base_spec.rb index be0206239f0..8ed2f10cfb8 100644 --- a/modules/claims_api/spec/sidekiq/service_base_spec.rb +++ b/modules/claims_api/spec/sidekiq/service_base_spec.rb @@ -13,6 +13,9 @@ let(:claim_date) { (Time.zone.today - 1.day).to_s } let(:anticipated_separation_date) { 2.days.from_now.strftime('%m-%d-%Y') } + let(:ews) { create(:claims_api_evidence_waiver_submission, :with_full_headers_tamara) } + let(:errored_ews) { create(:claims_api_evidence_waiver_submission, :with_full_headers_tamara, status: 'errored') } + let(:form_data) do temp = Rails.root.join('modules', 'claims_api', 'spec', 'fixtures', 'v2', 'veterans', 'disability_compensation', 'form_526_json_api.json').read @@ -52,6 +55,26 @@ end end + describe '#set_state_for_submission' do + it 'updates claim status as ERRORED' do + @service.send(:set_state_for_submission, claim, 'errored') + claim.reload + expect(claim.status).to eq('errored') + end + + it 'updates EWS status as ERRORED' do + @service.send(:set_state_for_submission, ews, 'errored') + ews.reload + expect(ews.status).to eq('errored') + end + + it 'updates EWS status as PENDING' do + @service.send(:set_state_for_submission, errored_ews, 'pending') + errored_ews.reload + expect(errored_ews.status).to eq('pending') + end + end + describe '#preserve_original_form_data' do it 'preserves the form data as expected' do preserved_form_data = @service.send(:preserve_original_form_data, claim.form_data)