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

Resolve MethodLength Rubocop Disables - Part SubmitForm526Job #18317

Merged
merged 2 commits into from
Sep 6, 2024
Merged
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
114 changes: 59 additions & 55 deletions app/sidekiq/evss/disability_compensation_form/submit_form526.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,11 @@ class SubmitForm526 < Job
#
# @param submission_id [Integer] The {Form526Submission} id
#
def perform(submission_id) # rubocop:disable Metrics/MethodLength
send_notifications = true
@submission_id = submission_id

def perform(submission_id)
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
Sentry.set_tags(source: '526EZ-all-claims')
super(submission_id)

if Flipper.enabled?(:disability_compensation_fail_submission,
OpenStruct.new({ flipper_id: submission.user_uuid }))
with_tracking('Form526 Submission', submission.saved_claim_id, submission.id, submission.bdd?) do
Rails.logger.info("disability_compensation_fail_submission enabled for submission #{submission.id}")
throw StandardError
rescue => e
handle_errors(submission, e)
return
end
end
return if fail_submission_feature_enabled?(submission)

# This instantiates the service as defined by the inheriting object
# TODO: this meaningless variable assignment is required for the specs to pass, which
Expand All @@ -103,62 +91,73 @@ def perform(submission_id) # rubocop:disable Metrics/MethodLength
with_tracking('Form526 Submission', submission.saved_claim_id, submission.id, submission.bdd?) do
submission.mark_birls_id_as_tried!

begin
submission.prepare_for_evss!
rescue => e
handle_errors(submission, e)
return
end

user_account = UserAccount.find_by(id: submission.user_account_id) ||
Account.lookup_by_user_uuid(submission.user_uuid)
return unless successfully_prepare_submission_for_evss?(submission)

begin
# send submission data to either EVSS or Lighthouse (LH)
response = if submission.claims_api? # not needed once fully migrated to LH
# submit 526 through LH API
# 1. get user's ICN
icn = user_account.icn
# 2. transform submission data to LH format
transform_service = EVSS::DisabilityCompensationForm::Form526ToLighthouseTransform.new
body = transform_service.transform(submission.form['form526'])
# 3. send transformed submission data to LH endpoint
service = BenefitsClaims::Service.new(icn)
raw_response = service.submit526(body)
raw_response_body = if raw_response.body.is_a? String
JSON.parse(raw_response.body)
else
raw_response.body
end
# 4. convert LH raw response to a FormSubmitResponse for further processing (claim_id, status)
# parse claimId from LH response
submitted_claim_id = raw_response_body.dig('data', 'attributes', 'claimId').to_i
raw_response_struct = OpenStruct.new({
body: { claim_id: submitted_claim_id },
status: raw_response.status
})
EVSS::DisabilityCompensationForm::FormSubmitResponse
.new(raw_response_struct.status, raw_response_struct)
send_submission_data_to_lighthouse(submission, submission_account(submission).icn)
else
service.submit_form526(submission.form_to_json(Form526Submission::FORM_526))
end

response_handler(response)
send_post_evss_notifications(submission, true)
rescue => e
send_notifications = false
send_post_evss_notifications(submission, false)
handle_errors(submission, e)
end
end
end

if Flipper.enabled?(:disability_compensation_production_tester,
OpenStruct.new({ flipper_id: submission.user_uuid }))
Rails.logger.info("send_post_evss_notifications call skipped for submission #{submission.id}")
elsif send_notifications
send_post_evss_notifications(submission)
private

def fail_submission_feature_enabled?(submission)
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
if Flipper.enabled?(:disability_compensation_fail_submission,
OpenStruct.new({ flipper_id: submission.user_uuid }))
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
with_tracking('Form526 Submission', submission.saved_claim_id, submission.id, submission.bdd?) do
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
Rails.logger.info("disability_compensation_fail_submission enabled for submission #{submission.id}")
throw StandardError
rescue => e
handle_errors(submission, e)
true
end
end
end

private
def successfully_prepare_submission_for_evss?(submission)
submission.prepare_for_evss!
true
rescue => e
handle_errors(submission, e)
false
end

def submission_account(submission)
UserAccount.find_by(id: submission.user_account_id) || Account.lookup_by_user_uuid(submission.user_uuid)
end

def send_submission_data_to_lighthouse(submission, icn)
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
# 1. transform submission data to LH format
transform_service = EVSS::DisabilityCompensationForm::Form526ToLighthouseTransform.new
body = transform_service.transform(submission.form['form526'])
# 2. send transformed submission data to LH endpoint
benefits_claims_service = BenefitsClaims::Service.new(icn)
raw_response = benefits_claims_service.submit526(body)
raw_response_body = if raw_response.body.is_a? String
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
JSON.parse(raw_response.body)
else
raw_response.body
end
# 3. convert LH raw response to a FormSubmitResponse for further processing (claim_id, status)
# parse claimId from LH response
submitted_claim_id = raw_response_body.dig('data', 'attributes', 'claimId').to_i
raw_response_struct = OpenStruct.new({
body: { claim_id: submitted_claim_id },
status: raw_response.status
})
EVSS::DisabilityCompensationForm::FormSubmitResponse.new(raw_response_struct.status, raw_response_struct)
end

def submit_complete_form
service.submit_form526(submission.form_to_json(Form526Submission::FORM_526))
Expand All @@ -169,8 +168,13 @@ def response_handler(response)
submission.save
end

def send_post_evss_notifications(submission)
submission.send_post_evss_notifications!
def send_post_evss_notifications(submission, send_notifications)
actor = OpenStruct.new({ flipper_id: submission.user_uuid })
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
if Flipper.enabled?(:disability_compensation_production_tester, actor)
Rails.logger.info("send_post_evss_notifications call skipped for submission #{submission.id}")
elsif send_notifications
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
submission.send_post_evss_notifications!
end
rescue => e
handle_errors(submission, e)
end
Expand Down
Loading