From f8569bf16b30b9f4a411ab78f982efee87a7e3c7 Mon Sep 17 00:00:00 2001 From: Alison Jones Date: Wed, 18 Sep 2024 17:39:02 -0500 Subject: [PATCH 1/2] Add 0781 LH migration feature flippers --- config/features.yml | 11 +++++++++- .../factories/api_provider_factory.rb | 1 + .../factories/api_provider_factory_spec.rb | 21 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/config/features.yml b/config/features.yml index 94aed732eeb..0d4e03e8200 100644 --- a/config/features.yml +++ b/config/features.yml @@ -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 diff --git a/lib/disability_compensation/factories/api_provider_factory.rb b/lib/disability_compensation/factories/api_provider_factory.rb index 19df9e458b8..84dc82b1870 100644 --- a/lib/disability_compensation/factories/api_provider_factory.rb +++ b/lib/disability_compensation/factories/api_provider_factory.rb @@ -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 diff --git a/spec/lib/disability_compensation/factories/api_provider_factory_spec.rb b/spec/lib/disability_compensation/factories/api_provider_factory_spec.rb index 176ced9ca76..10f61d1d2c2 100644 --- a/spec/lib/disability_compensation/factories/api_provider_factory_spec.rb +++ b/spec/lib/disability_compensation/factories/api_provider_factory_spec.rb @@ -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) From c104b9c6b363d9a889903d902e3d02d3c0923669 Mon Sep 17 00:00:00 2001 From: Alison Jones Date: Thu, 26 Sep 2024 17:00:20 -0500 Subject: [PATCH 2/2] Add lighthouse upload provider to 0781 worker --- .../submit_form0781.rb | 50 +++++++-- .../submit_form0781_spec.rb | 103 +++++++++++++++++- 2 files changed, 144 insertions(+), 9 deletions(-) diff --git a/app/sidekiq/evss/disability_compensation_form/submit_form0781.rb b/app/sidekiq/evss/disability_compensation_form/submit_form0781.rb index eac3530139f..d25ae3a064e 100644 --- a/app/sidekiq/evss/disability_compensation_form/submit_form0781.rb +++ b/app/sidekiq/evss/disability_compensation_form/submit_form0781.rb @@ -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: } @@ -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 @@ -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) @@ -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 diff --git a/spec/sidekiq/evss/disability_compensation_form/submit_form0781_spec.rb b/spec/sidekiq/evss/disability_compensation_form/submit_form0781_spec.rb index 65886c81c76..63affb08784 100644 --- a/spec/sidekiq/evss/disability_compensation_form/submit_form0781_spec.rb +++ b/spec/sidekiq/evss/disability_compensation_form/submit_form0781_spec.rb @@ -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) } @@ -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