Skip to content

Commit

Permalink
Intake | Bug | Use saved withdrawn issue IDs when processing asynchro…
Browse files Browse the repository at this point in the history
…nously (#14116)

connects #13483

### Description
This adds the ability for request issue withdrawals to fetch withdrawn issues from their IDs saved in the database on the request issues update. This is needed if they are being accessed asynchronously outside of the original update that was submitted which may happen if the VBMS `remove_contention` call fails on the first attempt.

There is a related [manual data fix GitHub issue](#13399) to look for more instances of this and re-attempt processing for them.
  • Loading branch information
leikkisa committed May 13, 2020
1 parent 621d23b commit db34a99
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/models/request_issues_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def process_withdrawn_issues!
def withdrawal
@withdrawal ||= RequestIssueWithdrawal.new(
user: user,
review: review,
request_issues_update: self,
request_issues_data: @request_issues_data
)
end
Expand Down
13 changes: 9 additions & 4 deletions app/workflows/request_issue_withdrawal.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

class RequestIssueWithdrawal
def initialize(user:, review:, request_issues_data:)
def initialize(user:, request_issues_update:, request_issues_data:)
@user = user
@review = review
@request_issues_update = request_issues_update
@request_issues_data = request_issues_data
end

Expand All @@ -15,12 +15,17 @@ def call
end

def withdrawn_issues
@withdrawn_issues ||= calculate_withdrawn_issues
@withdrawn_issues ||= withdrawn_request_issue_ids ? fetch_withdrawn_issues : calculate_withdrawn_issues
end

private

attr_reader :user, :review, :request_issues_data
attr_reader :user, :request_issues_update, :request_issues_data
delegate :review, :withdrawn_request_issue_ids, to: :request_issues_update

def fetch_withdrawn_issues
RequestIssue.where(id: withdrawn_request_issue_ids)
end

def calculate_withdrawn_issues
withdrawn_issue_data.map do |issue_data|
Expand Down
47 changes: 34 additions & 13 deletions spec/models/request_issues_update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ def allow_update_contention
expect(rating_end_product_establishment.reload.synced_status).to eq(nil)
end

context "when an issue is withdrawn" do
context "when an issue is withdrawn and there are active tasks" do
let(:request_issues_data) do
[{ request_issue_id: existing_legacy_opt_in_request_issue.id, withdrawal_date: Time.zone.now }]
end
Expand Down Expand Up @@ -595,28 +595,45 @@ def allow_update_contention
end
end
end
end

context "when create_contentions raises VBMS service error" do
let(:request_issues_data) { request_issues_data_with_new_issue }
context "when remove_contention raises VBMS service error and is re-tried" do
let(:request_issues_data) do
[{ request_issue_id: existing_legacy_opt_in_request_issue.id, withdrawal_date: Time.zone.now }]
end

it "saves error message and logs error" do
capture_raven_log
raise_error_on_create_contentions
it "saves error message, logs error and removes contention on re-attempt" do
capture_raven_log
raise_error_on_remove_contention

subject
subject

expect(request_issues_update.error).to eq(vbms_error.inspect)
expect(@raven_called).to eq(true)
expect(request_issues_update.error).to eq(vbms_error.inspect)
expect(@raven_called).to eq(true)

withdrawn_issue = request_issues_update.withdrawn_issues.first

expect(withdrawn_issue).to_not be_nil
expect(withdrawn_issue).to have_attributes(
closed_status: "withdrawn",
closed_at: Time.zone.now,
contention_removed_at: nil
)

allow_remove_contention
DecisionReviewProcessJob.perform_now(request_issues_update)

expect(request_issues_update.processed_at).to eq Time.zone.now
expect(withdrawn_issue.reload.contention_removed_at).to eq Time.zone.now
end
end
end

context "when remove_contention raises VBMS service error" do
let(:request_issues_data) { [{ request_issue_id: existing_request_issue.id }] }
context "when create_contentions raises VBMS service error" do
let(:request_issues_data) { request_issues_data_with_new_issue }

it "saves error message and logs error" do
capture_raven_log
raise_error_on_remove_contention
raise_error_on_create_contentions

subject

Expand Down Expand Up @@ -681,6 +698,10 @@ def allow_create_contentions
def raise_error_on_remove_contention
allow(Fakes::VBMSService).to receive(:remove_contention!).and_raise(vbms_error)
end

def allow_remove_contention
allow(Fakes::VBMSService).to receive(:remove_contention!).and_call_original
end
end
end

Expand Down

0 comments on commit db34a99

Please sign in to comment.