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

98361: Update DR engine controllers to use engine jobs #19920

Merged
merged 7 commits into from
Dec 20, 2024
Merged
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
9 changes: 5 additions & 4 deletions app/models/appeal_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand All @@ -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

Expand Down
6 changes: 6 additions & 0 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lib/decision_review_v1/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
16 changes: 16 additions & 0 deletions modules/decision_reviews/lib/decision_reviews/v1/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading