Skip to content

Commit

Permalink
Add LH upload provider to 0781 worker
Browse files Browse the repository at this point in the history
  • Loading branch information
ajones446 committed Sep 25, 2024
1 parent f8569bf commit 65aed67
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 9 deletions.
50 changes: 42 additions & 8 deletions app/sidekiq/evss/disability_compensation_form/submit_form0781.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ class SubmitForm0781 < Job

StatsD.increment("#{STATSD_KEY_PREFIX}.exhausted")

#AJ TODO - add logging if Flipper.enabled?(:disability_compensation_use_api_provider_for_0781)

if Flipper.enabled?(:form526_send_0781_failure_notification)
EVSS::DisabilityCompensationForm::Form0781DocumentUploadFailureEmail.perform_async(form526_submission_id)
end

::Rails.logger.warn(
'Submit Form 0781 Retries exhausted',
{ job_id:, error_class:, error_message:, timestamp:, form526_submission_id: }
Expand Down Expand Up @@ -117,6 +123,25 @@ def parsed_forms
@parsed_forms ||= JSON.parse(submission.form_to_json(Form526Submission::FORM_0781))
end

# # Returns the correct SupplementalDocumentUploadProvider based on the state of the
# # ApiProviderFactory::FEATURE_TOGGLE_UPLOAD_0781 feature flag for the current user
# #
# @return [EVSSSupplementalDocumentUploadProvider or LighthouseSupplementalDocumentUploadProvider]
def self.api_upload_provider(submission)
user = User.find(submission.user_uuid)

ApiProviderFactory.call(
type: ApiProviderFactory::FACTORIES[:supplemental_document_upload],
options: {
form526_submission: submission,
uploading_class: self,
statsd_metric_prefix: STATSD_KEY_PREFIX
},
current_user: user,
feature_toggle: ApiProviderFactory::FEATURE_TOGGLE_UPLOAD_0781
)
end

# Performs an asynchronous job for generating and submitting 0781 + 0781A PDF documents to VBMS
#
# @param submission_id [Integer] The {Form526Submission} id
Expand Down Expand Up @@ -193,7 +218,6 @@ def upload_to_vbms(pdf_path, form_id)
document_data = create_document_data(evss_claim_id, upload_data)

raise Common::Exceptions::ValidationErrors, document_data unless document_data.valid?

# thin wrapper to isolate upload for logging
file_body = File.open(pdf_path).read
perform_client_upload(file_body, document_data)
Expand All @@ -203,16 +227,26 @@ def upload_to_vbms(pdf_path, form_id)
end

def perform_client_upload(file_body, document_data)
client.upload(file_body, document_data)
if Flipper.enabled?(:disability_compensation_use_api_provider_for_0781)
upload_via_api_provider(file_body, document_data)
else
EVSS::DocumentsService.new(submission.auth_headers).upload(file_body, document_data)
end
end

def upload_via_api_provider(file_body, document_data)
document = upload_provider.generate_upload_document(
document_data.file_name,
document_data.document_type
)

upload_provider.submit_upload_document(document, file_body)
end

def client
@client ||= if Flipper.enabled?(:disability_compensation_lighthouse_document_service_provider)
# TODO: create client from lighthouse document service
else
EVSS::DocumentsService.new(submission.auth_headers)
end
def upload_provider
@upload_provider ||= EVSS::DisabilityCompensationForm::SubmitForm0781.api_upload_provider(submission)
end

end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

before do
Sidekiq::Job.clear_all
Flipper.disable(:disability_compensation_lighthouse_document_service_provider)
Flipper.disable(:disability_compensation_use_api_provider_for_0781)
end

let(:user) { FactoryBot.create(:user, :loa3) }
Expand Down Expand Up @@ -79,6 +79,106 @@
expect { described_class.drain }.to raise_error(StandardError)
end
end

context 'when the disability_compensation_use_api_provider_for_0781 flipper is enabled' do
before do
Flipper.enable(:disability_compensation_use_api_provider_for_0781)
end

context 'when the ApiProviderFactory::FEATURE_TOGGLE_UPLOAD_0781 feature flag is enabled' do
let(:faraday_response) { instance_double(Faraday::Response) }
let(:lighthouse_request_id) { Faker::Number.number(digits: 8) }

before do
Flipper.enable(ApiProviderFactory::FEATURE_TOGGLE_UPLOAD_0781)

allow_any_instance_of(LighthouseSupplementalDocumentUploadProvider).to receive(:submit_upload_document)
.and_return(faraday_response)

allow(faraday_response).to receive(:body).and_return(
{
'data' => {
'success' => true,
'requestId' => lighthouse_request_id
}
}
)
end

it 'uploads the document via the LighthouseSupplementalDocumentUploadProvider' do
lighthouse_document_0781 = instance_double(LighthouseDocument, document_type: 'L228')

lighthouse_document_0781a = instance_double(LighthouseDocument, document_type: 'L229')

# The test submission includes 0781(doc_type L228) and 0781(doc_type L229), which is why generate upload is called twice
expect_any_instance_of(LighthouseSupplementalDocumentUploadProvider).to receive(:generate_upload_document)
.with(
anything, #arg from generated_stamp_pdf
'L228')
.and_return(lighthouse_document_0781)

expect_any_instance_of(LighthouseSupplementalDocumentUploadProvider).to receive(:generate_upload_document)
.with(
anything, #arg from generated_stamp_pdf
'L229')
.and_return(lighthouse_document_0781a)

expect_any_instance_of(LighthouseSupplementalDocumentUploadProvider).to receive(:submit_upload_document)
.with(
lighthouse_document_0781,
anything #arg for file_body
)

expect_any_instance_of(LighthouseSupplementalDocumentUploadProvider).to receive(:submit_upload_document)
.with(
lighthouse_document_0781a,
anything #arg for file_body
)

subject.perform_async(submission.id)
described_class.drain
end
end

context 'when the ApiProviderFactory::FEATURE_TOGGLE_UPLOAD_0781 feature flag is disabled' do
before do
Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_UPLOAD_0781)
end

it 'uploads the document via the EVSSSupplementalDocumentUploadProvider' do
evss_document_0781 = instance_double(EVSSClaimDocument, document_type: 'L228')

evss_document_0781a = instance_double(EVSSClaimDocument, document_type: 'L229')

expect_any_instance_of(EVSSSupplementalDocumentUploadProvider).to receive(:generate_upload_document)
.with(
anything, #arg from generated_stamp_pdf
'L228')
.and_return(evss_document_0781)

expect_any_instance_of(EVSSSupplementalDocumentUploadProvider).to receive(:generate_upload_document)
.with(
anything, #arg from generated_stamp_pdf
'L229')
.and_return(evss_document_0781a)

expect_any_instance_of(EVSSSupplementalDocumentUploadProvider).to receive(:submit_upload_document)
.with(
evss_document_0781,
anything #arg for file_body
)

expect_any_instance_of(EVSSSupplementalDocumentUploadProvider).to receive(:submit_upload_document)
.with(
evss_document_0781a,
anything #arg for file_body
)

subject.perform_async(submission.id)
described_class.drain
end
end
end
end

context 'catastrophic failure state' do
Expand Down

0 comments on commit 65aed67

Please sign in to comment.