diff --git a/app/models/appeal_submission.rb b/app/models/appeal_submission.rb index 0acfb04a2ae..0a57ec03742 100644 --- a/app/models/appeal_submission.rb +++ b/app/models/appeal_submission.rb @@ -40,7 +40,8 @@ class AppealSubmission < ApplicationRecord scope :failure_not_sent, -> { where(failure_notification_sent_at: nil).order(id: :asc) } - def self.submit_nod(request_body_hash:, current_user:, decision_review_service: nil) + def self.submit_nod(request_body_hash:, current_user:, decision_review_service: nil, + submit_upload_job: DecisionReview::SubmitUpload) ActiveRecord::Base.transaction do raise 'Must pass in a version of the DecisionReview Service' if decision_review_service.nil? @@ -65,16 +66,16 @@ def self.submit_nod(request_body_hash:, current_user:, decision_review_service: # Clear in-progress form if submit was successful InProgressForm.form_for_user('10182', current_user)&.destroy! - appeal_submission.enqueue_uploads(uploads_arr, current_user) + appeal_submission.enqueue_uploads(uploads_arr, current_user, submit_upload_job) nod_response_body end end - def enqueue_uploads(uploads_arr, _user) + def enqueue_uploads(uploads_arr, _user, submit_upload_job) uploads_arr.each do |upload_attrs| asu = AppealSubmissionUpload.create!(decision_review_evidence_attachment_guid: upload_attrs['confirmationCode'], appeal_submission_id: id) - DecisionReview::SubmitUpload.perform_async(asu.id) + submit_upload_job.perform_async(asu.id) end end diff --git a/config/features.yml b/config/features.yml index ef8e771bc7d..45f1bead314 100644 --- a/config/features.yml +++ b/config/features.yml @@ -507,6 +507,12 @@ features: decision_review_sc_new_api: actor_type: user description: Enable to switch to new Supplemental Claim modularized Decision Review endpoint + decision_review_new_engine_4142_job: + actor_type: user + description: Enable to switch to new modularized Decision Review Form4142Submit job + decision_review_new_engine_submit_upload_job: + actor_type: user + description: Enable to switch to new modularized Decision Review SubmitUpload job dependency_verification: actor_type: user description: Feature gates the dependency verification modal for updating the diaries service. diff --git a/lib/decision_review_v1/appeals/supplemental_claim_services.rb b/lib/decision_review_v1/appeals/supplemental_claim_services.rb index 4f0197c48cb..a97a77cc1d5 100644 --- a/lib/decision_review_v1/appeals/supplemental_claim_services.rb +++ b/lib/decision_review_v1/appeals/supplemental_claim_services.rb @@ -251,7 +251,7 @@ def queue_submit_evidence_uploads(sc_evidences, appeal_submission_id) asu = AppealSubmissionUpload.create!(decision_review_evidence_attachment_guid: upload['confirmationCode'], appeal_submission_id:) - DecisionReview::SubmitUpload.perform_async(asu.id) + submit_upload_job.perform_async(asu.id) end end @@ -265,7 +265,7 @@ def queue_submit_evidence_uploads(sc_evidences, appeal_submission_id) # @return String # def queue_form4142(appeal_submission_id:, rejiggered_payload:, submitted_appeal_uuid:) - DecisionReview::Form4142Submit.perform_async( + form4142_submit_job.perform_async( appeal_submission_id, payload_encrypted_string(rejiggered_payload), submitted_appeal_uuid diff --git a/lib/decision_review_v1/service.rb b/lib/decision_review_v1/service.rb index caf070de305..0776aaa68ad 100644 --- a/lib/decision_review_v1/service.rb +++ b/lib/decision_review_v1/service.rb @@ -328,6 +328,14 @@ def construct_tmpfile_name(appeal_submission_upload_id, original_filename) private + def submit_upload_job + DecisionReview::SubmitUpload + end + + def form4142_submit_job + DecisionReview::Form4142Submit + end + def create_higher_level_review_headers(user) headers = { 'X-VA-SSN' => user.ssn.to_s.strip.presence, diff --git a/modules/decision_reviews/app/controllers/decision_reviews/v1/notice_of_disagreements_controller.rb b/modules/decision_reviews/app/controllers/decision_reviews/v1/notice_of_disagreements_controller.rb index 54e15439b39..1d0abee5864 100644 --- a/modules/decision_reviews/app/controllers/decision_reviews/v1/notice_of_disagreements_controller.rb +++ b/modules/decision_reviews/app/controllers/decision_reviews/v1/notice_of_disagreements_controller.rb @@ -18,7 +18,8 @@ def create nod_response_body = AppealSubmission.submit_nod( current_user: @current_user, request_body_hash:, - decision_review_service: + decision_review_service:, + submit_upload_job: ) render json: nod_response_body @@ -48,6 +49,14 @@ def handle_personal_info_error(e) ) raise end + + def submit_upload_job + if Flipper.enabled? :decision_review_new_engine_submit_upload_job + DecisionReviews::SubmitUpload + else + DecisionReview::SubmitUpload + end + end end end end diff --git a/modules/decision_reviews/lib/decision_reviews/v1/service.rb b/modules/decision_reviews/lib/decision_reviews/v1/service.rb index 0a85f75a79d..c616939cbb0 100644 --- a/modules/decision_reviews/lib/decision_reviews/v1/service.rb +++ b/modules/decision_reviews/lib/decision_reviews/v1/service.rb @@ -334,6 +334,22 @@ def construct_tmpfile_name(appeal_submission_upload_id, original_filename) private + def submit_upload_job + if Flipper.enabled? :decision_review_new_engine_submit_upload_job + DecisionReviews::SubmitUpload + else + DecisionReview::SubmitUpload + end + end + + def form4142_submit_job + if Flipper.enabled? :decision_review_new_engine_4142_job + DecisionReviews::Form4142Submit + else + DecisionReview::Form4142Submit + end + end + def create_higher_level_review_headers(user) headers = { 'X-VA-SSN' => user.ssn.to_s.strip.presence, diff --git a/modules/decision_reviews/spec/requests/v1/notice_of_disagreements_spec.rb b/modules/decision_reviews/spec/requests/v1/notice_of_disagreements_spec.rb index fc2f60a49fa..5ec32afec67 100644 --- a/modules/decision_reviews/spec/requests/v1/notice_of_disagreements_spec.rb +++ b/modules/decision_reviews/spec/requests/v1/notice_of_disagreements_spec.rb @@ -64,46 +64,68 @@ def personal_information_logs 'valid_NOD_create_request.json').read end - it 'creates an NOD and logs to StatsD and logger' do - VCR.use_cassette('decision_review/NOD-CREATE-RESPONSE-200_V1') do - allow(Rails.logger).to receive(:info) - expect(Rails.logger).to receive(:info).with({ - message: 'Overall claim submission success!', - user_uuid: user.uuid, - action: 'Overall claim submission', - form_id: '10182', - upstream_system: nil, - downstream_system: 'Lighthouse', - is_success: true, - http: { - status_code: 200, - body: '[Redacted]' - } - }) - allow(StatsD).to receive(:increment) - expect(StatsD).to receive(:increment).with('decision_review.form_10182.overall_claim_submission.success') - previous_appeal_submission_ids = AppealSubmission.all.pluck :submitted_appeal_uuid - # Create an InProgressForm - in_progress_form = create(:in_progress_form, user_uuid: user.uuid, form_id: '10182') - expect(in_progress_form).not_to be_nil - subject - expect(response).to be_successful - parsed_response = JSON.parse(response.body) - id = parsed_response['data']['id'] - expect(previous_appeal_submission_ids).not_to include id - appeal_submission = AppealSubmission.find_by(submitted_appeal_uuid: id) - expect(appeal_submission.type_of_appeal).to eq('NOD') - # AppealSubmissionUpload should be created for each form attachment - appeal_submission_uploads = AppealSubmissionUpload.where(appeal_submission:) - expect(appeal_submission_uploads.count).to eq 1 - # Evidence upload job should have been enqueued - expect(DecisionReview::SubmitUpload).to have_enqueued_sidekiq_job(appeal_submission_uploads.first.id) - # InProgressForm should be destroyed after successful submission - in_progress_form = InProgressForm.find_by(user_uuid: user.uuid, form_id: '10182') - expect(in_progress_form).to be_nil - # SavedClaim should be created with request data - saved_claim = SavedClaim::NoticeOfDisagreement.find_by(guid: id) - expect(JSON.parse(saved_claim.form)).to eq(test_request_body) + context 'when valid data is submitted' do + shared_examples 'successful NOD' do |upload_job_to_use, upload_job_not_to_use| + it 'creates an NOD and logs to StatsD and logger' do + VCR.use_cassette('decision_review/NOD-CREATE-RESPONSE-200_V1') do + allow(Rails.logger).to receive(:info) + expect(Rails.logger).to receive(:info).with({ + message: 'Overall claim submission success!', + user_uuid: user.uuid, + action: 'Overall claim submission', + form_id: '10182', + upstream_system: nil, + downstream_system: 'Lighthouse', + is_success: true, + http: { + status_code: 200, + body: '[Redacted]' + } + }) + + allow(StatsD).to receive(:increment) + expect(StatsD).to receive(:increment).with('decision_review.form_10182.overall_claim_submission.success') + previous_appeal_submission_ids = AppealSubmission.all.pluck :submitted_appeal_uuid + # Create an InProgressForm + in_progress_form = create(:in_progress_form, user_uuid: user.uuid, form_id: '10182') + expect(in_progress_form).not_to be_nil + subject + expect(response).to be_successful + parsed_response = JSON.parse(response.body) + id = parsed_response['data']['id'] + expect(previous_appeal_submission_ids).not_to include id + appeal_submission = AppealSubmission.find_by(submitted_appeal_uuid: id) + expect(appeal_submission.type_of_appeal).to eq('NOD') + # AppealSubmissionUpload should be created for each form attachment + appeal_submission_uploads = AppealSubmissionUpload.where(appeal_submission:) + expect(appeal_submission_uploads.count).to eq 1 + # Evidence upload job is enqueued with non-engine job + expect(upload_job_to_use).to have_enqueued_sidekiq_job(appeal_submission_uploads.first.id) + expect(upload_job_not_to_use).not_to have_enqueued_sidekiq_job(anything) + # InProgressForm should be destroyed after successful submission + in_progress_form = InProgressForm.find_by(user_uuid: user.uuid, form_id: '10182') + expect(in_progress_form).to be_nil + # SavedClaim should be created with request data + saved_claim = SavedClaim::NoticeOfDisagreement.find_by(guid: id) + expect(JSON.parse(saved_claim.form)).to eq(test_request_body) + end + end + end + + context 'and engine job flag is disabled' do + before do + Flipper.disable :decision_review_new_engine_submit_upload_job + end + + it_behaves_like 'successful NOD', DecisionReview::SubmitUpload, DecisionReviews::SubmitUpload + end + + context 'and engine job flag is enabled' do + before do + Flipper.enable :decision_review_new_engine_submit_upload_job + end + + it_behaves_like 'successful NOD', DecisionReviews::SubmitUpload, DecisionReview::SubmitUpload end end diff --git a/modules/decision_reviews/spec/requests/v1/supplemental_claims_spec.rb b/modules/decision_reviews/spec/requests/v1/supplemental_claims_spec.rb index d82c6116dea..750ffc3a44e 100644 --- a/modules/decision_reviews/spec/requests/v1/supplemental_claims_spec.rb +++ b/modules/decision_reviews/spec/requests/v1/supplemental_claims_spec.rb @@ -128,6 +128,10 @@ def personal_information_logs 'DecisionReviews::V1::SupplementalClaimsController#create exception % (SC_V1)' end + before do + Flipper.disable(:decision_review_new_engine_4142_job) + end + context 'when tracking 4142 is enabled' do subject do post '/decision_reviews/v1/supplemental_claims', @@ -241,6 +245,39 @@ def personal_information_logs end end end + + context 'when 4142 engine job is enabled' do + before do + Flipper.disable(:decision_review_track_4142_submissions) + Flipper.enable(:decision_review_new_engine_4142_job) + end + + it 'creates a supplemental claim and queues a 4142 form when 4142 info is provided' do + VCR.use_cassette('decision_review/SC-CREATE-RESPONSE-WITH-4142-200_V1') do + VCR.use_cassette('lighthouse/benefits_intake/200_lighthouse_intake_upload_location') do + VCR.use_cassette('lighthouse/benefits_intake/200_lighthouse_intake_upload') do + previous_appeal_submission_ids = AppealSubmission.all.pluck :submitted_appeal_uuid + expect do + post '/decision_reviews/v1/supplemental_claims', + params: VetsJsonSchema::EXAMPLES.fetch('SC-CREATE-REQUEST-BODY-FOR-VA-GOV').to_json, + headers: + end.to change(DecisionReviews::Form4142Submit.jobs, :size).by(1) + expect(DecisionReview::SubmitUpload).not_to have_enqueued_sidekiq_job(anything) + expect(response).to be_successful + parsed_response = JSON.parse(response.body) + id = parsed_response['data']['id'] + expect(previous_appeal_submission_ids).not_to include id + + appeal_submission = AppealSubmission.find_by(submitted_appeal_uuid: id) + expect(appeal_submission.type_of_appeal).to eq('SC') + expect do + DecisionReviews::Form4142Submit.drain + end.to change(DecisionReviews::Form4142Submit.jobs, :size).by(-1) + end + end + end + end + end end describe '#create with uploads' do @@ -259,21 +296,42 @@ def personal_information_logs 'DecisionReviews::V1::SupplementalClaimsController#create exception % (SC_V1)' end - it 'creates a supplemental claim and queues evidence jobs when additionalDocuments info is provided' do - VCR.use_cassette('decision_review/SC-CREATE-RESPONSE-WITH-UPLOADS-200_V1') do - VCR.use_cassette('lighthouse/benefits_intake/200_lighthouse_intake_upload_location') do - VCR.use_cassette('lighthouse/benefits_intake/200_lighthouse_intake_upload') do - VCR.use_cassette('decision_review/SC-GET-UPLOAD-URL-200_V1') do - expect { subject }.to change(DecisionReview::SubmitUpload.jobs, :size).by(2) - expect(response).to be_successful - parsed_response = JSON.parse(response.body) - id = parsed_response['data']['id'] - appeal_submission = AppealSubmission.find_by(submitted_appeal_uuid: id) - expect(appeal_submission.type_of_appeal).to eq('SC') + context 'when valid data is submitted' do + shared_examples 'successful SC' do |upload_job_to_use, upload_job_not_to_use| + it 'creates a supplemental claim and queues evidence jobs when additionalDocuments info is provided' do + VCR.use_cassette('decision_review/SC-CREATE-RESPONSE-WITH-UPLOADS-200_V1') do + VCR.use_cassette('lighthouse/benefits_intake/200_lighthouse_intake_upload_location') do + VCR.use_cassette('lighthouse/benefits_intake/200_lighthouse_intake_upload') do + VCR.use_cassette('decision_review/SC-GET-UPLOAD-URL-200_V1') do + expect { subject }.to change(upload_job_to_use.jobs, :size).by(2) + expect(upload_job_not_to_use).not_to have_enqueued_sidekiq_job(anything) + expect(response).to be_successful + parsed_response = JSON.parse(response.body) + id = parsed_response['data']['id'] + appeal_submission = AppealSubmission.find_by(submitted_appeal_uuid: id) + expect(appeal_submission.type_of_appeal).to eq('SC') + end + end end end end end + + context 'and engine job flag is disabled' do + before do + Flipper.disable :decision_review_new_engine_submit_upload_job + end + + it_behaves_like 'successful SC', DecisionReview::SubmitUpload, DecisionReviews::SubmitUpload + end + + context 'and engine job flag is enabled' do + before do + Flipper.enable :decision_review_new_engine_submit_upload_job + end + + it_behaves_like 'successful SC', DecisionReviews::SubmitUpload, DecisionReview::SubmitUpload + end end context 'when an error occurs in the transaction' do