Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API-44052] Update statuses for pdf generation #20331

Draft
wants to merge 3 commits into
base: tdc/add-process-model
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ class PoaFormBuilderJob < ClaimsApi::ServiceBase
# it queues a job to update the POA code in BGS, as well.
#
# @param power_of_attorney_id [String] Unique identifier of the submitted POA
def perform(power_of_attorney_id, form_number, rep_id, action)
def perform(power_of_attorney_id, form_number, rep_id, action) # rubocop:disable Metrics/MethodLength
power_of_attorney = ClaimsApi::PowerOfAttorney.find(power_of_attorney_id)

process = ClaimsApi::Process.find_or_create_by(processable: power_of_attorney,
step_type: 'PDF_SUBMISSION')
process.update!(step_status: 'IN_PROGRESS')

rep = ::Veteran::Service::Representative.where(representative_id: rep_id).order(created_at: :desc).first

output_path = pdf_constructor(form_number).construct(data(power_of_attorney, form_number, rep),
Expand All @@ -36,10 +41,13 @@ def perform(power_of_attorney_id, form_number, rep_id, action)
else
ClaimsApi::PoaUpdater.perform_async(power_of_attorney.id, rep_id)
end
process.update!(step_status: 'SUCCESS')
rescue VBMS::Unknown
rescue_vbms_error(power_of_attorney)
process.update!(step_status: 'FAILED')
rescue Errno::ENOENT
rescue_file_not_found(power_of_attorney)
process.update!(step_status: 'FAILED')
end

private
Expand Down
40 changes: 40 additions & 0 deletions modules/claims_api/spec/sidekiq/v2/poa_form_builder_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,46 @@
end
end

describe 'updating process' do
let(:pdf_path) { 'modules/claims_api/spec/fixtures/21-22/signed_filled_final.pdf' }

before do
allow_any_instance_of(Flipper).to receive(:enabled?).with(:lighthouse_claims_api_poa_use_bd).and_return true
allow_any_instance_of(Flipper).to receive(:enabled?).with(:claims_api_poa_uploads_bd_refactor).and_return true
pdf_constructor_double = instance_double(ClaimsApi::V2::PoaPdfConstructor::Organization)
allow_any_instance_of(ClaimsApi::V2::PoaFormBuilderJob).to receive(:pdf_constructor)
.and_return(pdf_constructor_double)
allow(pdf_constructor_double).to receive(:construct).and_return(pdf_path)
allow_any_instance_of(ClaimsApi::V2::PoaFormBuilderJob).to receive(:data).and_return({})
end

context 'when the pdf is successfully uploaded' do
before do
allow_any_instance_of(ClaimsApi::PoaDocumentService).to receive(:create_upload)
.with(poa: power_of_attorney, pdf_path:, doc_type: 'L190', action: 'post').and_return(nil)
end

it 'updates the process for the power of attorney with the success status' do
subject.new.perform(power_of_attorney.id, '2122', rep.id, 'post')
expect(ClaimsApi::Process.find_by(processable: power_of_attorney,
step_type: 'PDF_SUBMISSION').step_status).to eq('SUCCESS')
end
end

context 'when the pdf is not successfully uploaded' do
before do
allow_any_instance_of(ClaimsApi::PoaDocumentService).to receive(:create_upload)
.with(poa: power_of_attorney, pdf_path:, doc_type: 'L190', action: 'post').and_raise(Errno::ENOENT, 'error')
end

it 'updates the process for the power of attorney with the failed status' do
subject.new.perform(power_of_attorney.id, '2122', rep.id, 'post')
expect(ClaimsApi::Process.find_by(processable: power_of_attorney,
step_type: 'PDF_SUBMISSION').step_status).to eq('FAILED')
end
end
end

context 'when an errored job has exhausted its retries' do
it 'logs to the ClaimsApi Logger' do
error_msg = 'An error occurred for the POA Form Builder Job'
Expand Down
Loading