Skip to content

Commit

Permalink
Appeals are able to determine if they are ready for Bva Dispatch to b…
Browse files Browse the repository at this point in the history
…egin (#15022)

Connects #14056 

### Description
Teaches Appeal (& LegacyAppeal) how to know if an appeal is ready for BVA Dispatch in preparation for allowing tasks to block bva dispatch

### Acceptance Criteria
- [ ] Tests pass
- [ ] AMA Appeals can correct state if a BvaDispatchTask should be opened
- [ ] Legacy Appeals should never be in a state to recieve a BvaDispatchTask

### Testing Plan
1. Review the test cases - double check any you are suspicious of? Run any additional tests? Am I missing any scenarios?

### User Facing Changes
None
  • Loading branch information
lomky committed Aug 24, 2020
1 parent 624fc05 commit d89afd6
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/models/appeal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,23 @@ def eligible_for_death_dismissal?(_user)
false
end

# We are ready for BVA dispatch if
# - the appeal is not at Quality Review
# - the appeal has not already completed BVA Dispatch
# - the appeal is not already at BVA Dispatch
# - the appeal is not at Judge Decision Review
# - the appeal has a finished Judge Decision Review
def ready_for_bva_dispatch?
return false if Task.open.where(appeal: self).where("type IN (?, ?, ?)",
JudgeDecisionReviewTask.name,
QualityReviewTask.name,
BvaDispatchTask.name).any?
return false if BvaDispatchTask.completed.find_by(appeal: self)
return true if JudgeDecisionReviewTask.completed.find_by(appeal: self)

false
end

private

def business_lines_needing_assignment
Expand Down
5 changes: 5 additions & 0 deletions app/models/legacy_appeal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,11 @@ def location_history
VACOLS::Priorloc.where(lockey: vacols_id).order(:locdout)
end

# Only AMA Appeals go to BVA Dispatch in Caseflow
def ready_for_bva_dispatch?
false
end

private

def soc_eligible_for_opt_in?(receipt_date:, covid_flag: false)
Expand Down
110 changes: 110 additions & 0 deletions spec/models/appeal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,116 @@
end
end

shared_examples "existing BvaDispatchTask" do |status, result|
let(:user) { create(:user) }

before do
BvaDispatch.singleton.add_user(user)
dispatch_task = BvaDispatchTask.create_from_root_task(appeal.root_task)
dispatch_task.descendants.each { |task| task.update_column(:status, status) }
end

it "should return #{result}" do
expect(subject).to eq(result)
end
end

shared_examples "depends on existing BvaDispatchTask" do
context "no existing BvaDispatchTask" do
it "should return true" do
expect(subject).to eq(true)
end
end

context "existing open BvaDispatchTask" do
include_examples "existing BvaDispatchTask",
Constants.TASK_STATUSES.in_progress,
false
end

context "existing complete BvaDispatchTask" do
include_examples "existing BvaDispatchTask",
Constants.TASK_STATUSES.completed,
false
end

context "existing cancelled BvaDispatchTask" do
include_examples "existing BvaDispatchTask",
Constants.TASK_STATUSES.cancelled,
true

context "and existing open BvaDispatchTask" do
include_examples "existing BvaDispatchTask",
Constants.TASK_STATUSES.assigned,
false
end

context "and existing completed BvaDispatchTask" do
include_examples "existing BvaDispatchTask",
Constants.TASK_STATUSES.completed,
false
end
end
end

describe ".ready_for_bva_dispatch?" do
subject { appeal.ready_for_bva_dispatch? }

context "no complete JudgeDecisionReviewTask" do
it "should return false" do
expect(subject).to eq(false)
end
end

context "has complete JudgeDecisionReviewTask" do
let(:appeal) do
create(:appeal,
:at_judge_review,
docket_type: Constants.AMA_DOCKETS.direct_review)
end
before do
JudgeDecisionReviewTask.find_by(appeal: appeal)
.update_column(:status, Constants.TASK_STATUSES.completed)
end

context "and an open JudgeDecisionReviewTask" do
before do
JudgeDecisionReviewTask.create!(appeal: appeal, assigned_to: create(:user), parent: appeal.root_task)
end

it "should return false" do
expect(subject).to eq(false)
end
end

context "no QualityReviewTask" do
include_examples "depends on existing BvaDispatchTask"
end

context "existing open QualityReviewTask" do
let(:user) { create(:user) }
before do
BvaDispatch.singleton.add_user(user)
QualityReviewTask.create_from_root_task(appeal.root_task)
end

it "should return false" do
expect(subject).to eq(false)
end
end

context "existing closed QualityReviewTask" do
let(:user) { create(:user) }
before do
qr_task = QualityReviewTask.create_from_root_task(appeal.root_task)
qr_task.descendants.each { |task| task.update_column(:status, Constants.TASK_STATUSES.completed) }
end

include_examples "depends on existing BvaDispatchTask"
end
end
end

describe ".ready_for_distribution?" do
let(:appeal) { create(:appeal) }
let(:distribution_task) { create(:distribution_task, appeal: appeal, assigned_to: Bva.singleton) }
Expand Down
12 changes: 12 additions & 0 deletions spec/models/legacy_appeal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2836,4 +2836,16 @@
end
end
end

describe ".ready_for_bva_dispatch?" do
let(:appeal) { create(:legacy_appeal, vacols_case: create(:case)) }

subject { appeal.ready_for_bva_dispatch? }

context "Legacy appeals do not go to BVA Dispatch via Caseflow" do
it "should return false" do
expect(subject).to eq(false)
end
end
end
end

0 comments on commit d89afd6

Please sign in to comment.