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

[Work in Progress] 83846 disability benefits migrate 0781 to lighthouse #18625

Closed
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 @@ -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
11 changes: 10 additions & 1 deletion config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,16 @@ features:
description: Provide a temporary killswitch for using the ApiProviderFactory to select an API for uploading BDD instructions
disability_compensation_lighthouse_upload_bdd_instructions:
actor_type: user
description: If enabled the ApiProviderFactory will select the Lighthouse Benefits Documents API to submit BDD instructions for Form 526 documents
description: If enabled the ApiProviderFactory will select the Lighthouse Benefits Documents API to submit Form 0781 for Form 526
disability_compensation_use_api_provider_for_0781:
actor_type: user
description: Provide a temporary killswitch for using the ApiProviderFactory to select an API for uploading Form 0781
disability_compensation_lighthouse_upload_0781:
actor_type: user
description: If enabled the ApiProviderFactory will select the Lighthouse Benefits Documents API to submit Form 0781 for Form 526 documents
disablity_benefits_browser_monitoring_enabled:
actor_type: user
description: Datadog RUM monitoring for disability benefits applications
virtual_agent_fetch_jwt_token:
actor_type: user
description: Enable the fetching of a JWT token to access MAP environment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class UndefinedFactoryTypeError < StandardError; end
FEATURE_TOGGLE_GENERATE_PDF = 'disability_compensation_lighthouse_generate_pdf'

FEATURE_TOGGLE_UPLOAD_BDD_INSTRUCTIONS = 'disability_compensation_lighthouse_upload_bdd_instructions'
FEATURE_TOGGLE_UPLOAD_0781 = 'disability_compensation_lighthouse_upload_0781'

attr_reader :type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,27 @@ def provider
end
end

context 'for 0781 uploads' do
def provider
ApiProviderFactory.call(
type: ApiProviderFactory::FACTORIES[:supplemental_document_upload],
options: {
form526_submission: submission
},
current_user:,
feature_toggle: ApiProviderFactory::FEATURE_TOGGLE_UPLOAD_0781
)
end

it 'provides a SupplementalDocumentUploadProvider based on a Flipper' do
Flipper.enable(ApiProviderFactory::FEATURE_TOGGLE_UPLOAD_0781)
expect(provider.class).to equal(LighthouseSupplementalDocumentUploadProvider)

Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_UPLOAD_0781)
expect(provider.class).to equal(EVSSSupplementalDocumentUploadProvider)
end
end

it 'throw error if provider unknown' do
expect do
provider(:random)
Expand Down
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,107 @@
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) }
let(:generated_pdf_file_name) {/.+\.pdf\z/}

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 0781A(doc_type L229), which calls generate_upload_document once for each doc_type
expect_any_instance_of(LighthouseSupplementalDocumentUploadProvider).to receive(:generate_upload_document)
.with(
generated_pdf_file_name,
'L228')
.and_return(lighthouse_document_0781)

expect_any_instance_of(LighthouseSupplementalDocumentUploadProvider).to receive(:generate_upload_document)
.with(
generated_pdf_file_name,
'L229')
.and_return(lighthouse_document_0781a)

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

expect_any_instance_of(LighthouseSupplementalDocumentUploadProvider).to receive(:submit_upload_document)
.with(
lighthouse_document_0781a,
anything #arg for generated pdf 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 generated file_body
)

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

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

context 'catastrophic failure state' do
Expand Down