Skip to content

Commit

Permalink
APPEALS-43851: Add test to validate CAVC+AOD behavior on hearing dock…
Browse files Browse the repository at this point in the history
…et appeals affinities (#21678)

* add test to validate cavc+aod on hearing docket appeals

* lint, test case_docket_spec fix

* modify case_docket_spec again

* more test fix testing

* attempt to fix test again

* test removing prev appeals from nonpriority queries

* more test tests

* feature toggle change in test

* reorder new portions of query

* remove unused portions of queries in case_docket

* revert unneeded change to query order

* revert unneeded change to query order
  • Loading branch information
craigrva authored May 22, 2024
1 parent 6579ea9 commit baae791
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 27 deletions.
18 changes: 6 additions & 12 deletions app/models/vacols/case_docket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,20 @@ class DocketNumberCentennialLoop < StandardError; end
) PREV_APPEAL
on PREV_APPEAL.PREV_BFKEY != BRIEFF.BFKEY and PREV_APPEAL.PREV_BFCORLID = BRIEFF.BFCORLID
and PREV_APPEAL.PREV_TINUM = BRIEFF.TINUM and PREV_APPEAL.PREV_TITRNUM = BRIEFF.TITRNUM
and PREV_APPEAL.PREV_BFDDEC = BRIEFF.BFDPDCN"
and PREV_APPEAL.PREV_BFDDEC = BRIEFF.BFDPDCN
"

SELECT_PRIORITY_APPEALS = "
select BFKEY, BFDLOOUT, VLJ, PREV_TYPE_ACTION, PREV_DECIDING_JUDGE
select BFKEY, BFDLOOUT, VLJ
from (
select BFKEY, BFDLOOUT,
case when BFHINES is null or BFHINES <> 'GP' then VLJ_HEARINGS.VLJ end VLJ,
PREV_APPEAL.PREV_TYPE_ACTION PREV_TYPE_ACTION,
PREV_APPEAL.PREV_DECIDING_JUDGE PREV_DECIDING_JUDGE
case when BFHINES is null or BFHINES <> 'GP' then VLJ_HEARINGS.VLJ end VLJ
from (
#{SELECT_READY_APPEALS}
and (BFAC = '7' or AOD = '1')
order by BFDLOOUT
) BRIEFF
#{JOIN_ASSOCIATED_VLJS_BY_HEARINGS}
#{JOIN_PREVIOUS_APPEALS}
)
"

Expand All @@ -147,7 +145,6 @@ class DocketNumberCentennialLoop < StandardError; end
from (
#{SELECT_READY_APPEALS}
and (BFAC = '7' or AOD = '1')
order by BFDLOOUT
) BRIEFF
#{JOIN_ASSOCIATED_VLJS_BY_HEARINGS}
#{JOIN_PREVIOUS_APPEALS}
Expand All @@ -156,18 +153,16 @@ class DocketNumberCentennialLoop < StandardError; end
"

SELECT_NONPRIORITY_APPEALS = "
select BFKEY, BFDLOOUT, VLJ, DOCKET_INDEX, PREV_TYPE_ACTION, PREV_DECIDING_JUDGE
select BFKEY, BFDLOOUT, VLJ, DOCKET_INDEX
from (
select BFKEY, BFDLOOUT, rownum DOCKET_INDEX,
case when BFHINES is null or BFHINES <> 'GP' then VLJ_HEARINGS.VLJ end VLJ,
PREV_APPEAL.PREV_TYPE_ACTION PREV_TYPE_ACTION, PREV_APPEAL.PREV_DECIDING_JUDGE PREV_DECIDING_JUDGE
case when BFHINES is null or BFHINES <> 'GP' then VLJ_HEARINGS.VLJ end VLJ
from (
#{SELECT_READY_APPEALS}
and BFAC <> '7' and AOD = '0'
order by case when substr(TINUM, 1, 2) between '00' and '29' then 1 else 0 end, TINUM
) BRIEFF
#{JOIN_ASSOCIATED_VLJS_BY_HEARINGS}
#{JOIN_PREVIOUS_APPEALS}
)
"

Expand All @@ -181,7 +176,6 @@ class DocketNumberCentennialLoop < StandardError; end
from (
#{SELECT_READY_APPEALS}
and BFAC <> '7' and AOD = '0'
order by case when substr(TINUM, 1, 2) between '00' and '29' then 1 else 0 end, TINUM
) BRIEFF
#{JOIN_ASSOCIATED_VLJS_BY_HEARINGS}
#{JOIN_PREVIOUS_APPEALS}
Expand Down
51 changes: 41 additions & 10 deletions spec/models/dockets/hearing_request_docket_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -589,16 +589,30 @@
context "with multiple levers enabled and appeals meeting each criteria" do
# ready non-aod appeals
let!(:ready_cavc_appeal_tied_to_requesting_judge_in_window) do
create_ready_cavc_appeal(tied_judge: requesting_judge_no_attorneys, created_date: 7.days.ago)
create_ready_cavc_appeal(tied_judge: requesting_judge_no_attorneys, created_date: 15.days.ago)
end
let!(:ready_cavc_appeal_tied_to_requesting_judge_out_of_window_21_days) do
create_ready_cavc_appeal(tied_judge: requesting_judge_no_attorneys, created_date: 21.days.ago)
let!(:ready_cavc_appeal_tied_to_requesting_judge_out_of_window_22_days) do
create_ready_cavc_appeal(tied_judge: requesting_judge_no_attorneys, created_date: 22.days.ago)
end
let!(:ready_cavc_appeal_tied_to_other_judge_in_window) do
create_ready_cavc_appeal(tied_judge: other_judge, created_date: 7.days.ago)
create_ready_cavc_appeal(tied_judge: other_judge, created_date: 15.days.ago)
end
let!(:ready_cavc_appeal_tied_to_other_judge_out_of_window_21_days) do
create_ready_cavc_appeal(tied_judge: other_judge, created_date: 21.days.ago)
let!(:ready_cavc_appeal_tied_to_other_judge_out_of_window_22_days) do
create_ready_cavc_appeal(tied_judge: other_judge, created_date: 22.days.ago)
end

# ready aod + cavc appeals to verify that distribution uses the lowest lever value to distribute
let!(:ready_cavc_aod_appeal_tied_to_requesting_judge_in_window) do
create_ready_cavc_appeal(tied_judge: requesting_judge_no_attorneys, created_date: 5.days.ago, aod: true)
end
let!(:ready_cavc_aod_appeal_tied_to_requesting_judge_out_of_window_10_days) do
create_ready_cavc_appeal(tied_judge: requesting_judge_no_attorneys, created_date: 10.days.ago, aod: true)
end
let!(:ready_cavc_aod_appeal_tied_to_other_judge_in_window) do
create_ready_cavc_appeal(tied_judge: other_judge, created_date: 5.days.ago, aod: true)
end
let!(:ready_cavc_aod_appeal_tied_to_other_judge_out_of_window_10_days) do
create_ready_cavc_appeal(tied_judge: other_judge, created_date: 10.days.ago, aod: true)
end

# ready aod appeals
Expand Down Expand Up @@ -627,7 +641,8 @@
before do
FeatureToggle.enable!(:specialty_case_team_distribution)
CaseDistributionLever.find_by_item(Constants.DISTRIBUTION.ama_hearing_case_affinity_days).update!(value: "30")
CaseDistributionLever.find_by_item(Constants.DISTRIBUTION.cavc_affinity_days).update!(value: "14")
CaseDistributionLever.find_by_item(Constants.DISTRIBUTION.cavc_affinity_days).update!(value: "21")
CaseDistributionLever.find_by_item(Constants.DISTRIBUTION.cavc_aod_affinity_days).update!(value: "7")
CaseDistributionLever
.find_by_item(Constants.DISTRIBUTION.ama_hearing_case_aod_affinity_days)
.update!(value: "15")
Expand All @@ -639,8 +654,11 @@
it "distributes appeals as expected" do
expect(subject.map(&:case_id)).to match_array(
[ready_cavc_appeal_tied_to_requesting_judge_in_window.uuid,
ready_cavc_appeal_tied_to_requesting_judge_out_of_window_21_days.uuid,
ready_cavc_appeal_tied_to_other_judge_out_of_window_21_days.uuid,
ready_cavc_appeal_tied_to_requesting_judge_out_of_window_22_days.uuid,
ready_cavc_appeal_tied_to_other_judge_out_of_window_22_days.uuid,
ready_cavc_aod_appeal_tied_to_requesting_judge_in_window.uuid,
ready_cavc_aod_appeal_tied_to_requesting_judge_out_of_window_10_days.uuid,
ready_cavc_aod_appeal_tied_to_other_judge_out_of_window_10_days.uuid,
ready_aod_tied_to_requesting_judge_in_window.uuid,
ready_aod_tied_to_requesting_judge_out_of_window_20_days.uuid,
ready_aod_tied_to_other_judge_out_of_window_20_days.uuid,
Expand All @@ -667,7 +685,7 @@ def create_ready_aod_appeal(tied_judge: nil, created_date: 1.year.ago)
appeal
end

def create_ready_cavc_appeal(tied_judge: nil, created_date: 1.year.ago)
def create_ready_cavc_appeal(tied_judge: nil, created_date: 1.year.ago, aod: false)
Timecop.travel(created_date - 6.months)
if tied_judge
judge = tied_judge
Expand Down Expand Up @@ -699,9 +717,22 @@ def create_ready_cavc_appeal(tied_judge: nil, created_date: 1.year.ago)
(distribution_tasks.flat_map(&:descendants) - distribution_tasks).each(&:completed!)
Timecop.return

create_aod_motion(remand_appeal, remand_appeal.claimant.person) if aod

remand_appeal
end

def create_aod_motion(appeal, person)
create(
:advance_on_docket_motion,
appeal: appeal,
granted: true,
person: person,
reason: Constants.AOD_REASONS.financial_distress,
user_id: User.system_user.id
)
end

def create_ready_nonpriority_appeal(tied_judge: nil, created_date: 1.year.ago)
Timecop.travel(created_date)
appeal = create(
Expand Down
26 changes: 21 additions & 5 deletions spec/models/vacols/case_docket_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
before do
FeatureToggle.enable!(:test_facols)
FeatureToggle.enable!(:acd_disable_legacy_lock_ready_appeals)
FeatureToggle.enable!(:acd_distribute_by_docket_date)
end

after do
Expand All @@ -29,7 +30,7 @@
bfac: "3",
bfmpro: "ACT",
bfcurloc: "81",
bfdloout: 1.day.ago,
bfdloout: 3.days.ago,
bfbox: nonpriority_ready_case_bfbox,
folder: build(:folder, tinum: nonpriority_ready_case_docket_number, titrnum: "123456789S"))
end
Expand All @@ -55,15 +56,15 @@
bfac: "1",
bfmpro: "ACT",
bfcurloc: "83",
bfdloout: 1.day.ago,
bfdloout: 2.days.ago,
folder: build(:folder, tinum: another_nonpriority_ready_case_docket_number, titrnum: "123456789S")
).tap { |vacols_case| create(:mail, :blocking, :completed, mlfolder: vacols_case.bfkey) }
end

let(:third_nonpriority_ready_case_docket_number) { "1801005" }
let(:third_nonpriority_ready_case) do
create(:case,
bfd19: 1.year.ago,
bfd19: 10.months.ago,
bfac: "3",
bfmpro: "ACT",
bfcurloc: "83",
Expand Down Expand Up @@ -327,8 +328,10 @@
let(:bust_backlog) { false }

before do
FeatureToggle.enabled?(:acd_cases_tied_to_judges_no_longer_with_board)
third_nonpriority_ready_case
FeatureToggle.enable!(:acd_cases_tied_to_judges_no_longer_with_board)
nonpriority_ready_case.reload
another_nonpriority_ready_case.reload
third_nonpriority_ready_case.reload
end

subject { VACOLS::CaseDocket.distribute_nonpriority_appeals(judge, genpop, range, limit, bust_backlog) }
Expand All @@ -350,6 +353,7 @@
let(:limit) { 1 }
it "only distributes cases to the limit" do
expect(subject.count).to eq(1)
expect(subject.first["bfkey"]).to eq nonpriority_ready_case.bfkey
expect(nonpriority_ready_case.reload.bfcurloc).to eq(judge.vacols_uniq_id)
expect(another_nonpriority_ready_case.reload.bfcurloc).to eq("83")
expect(third_nonpriority_ready_case.reload.bfcurloc).to eq("83")
Expand All @@ -358,8 +362,13 @@

context "when range is specified" do
let(:range) { 1 }

# We do not provide a range if this feature toggle is enabled
before { FeatureToggle.disable!(:acd_distribute_by_docket_date) }

it "only distributes cases within the range" do
expect(subject.count).to eq(1)
expect(subject.first["bfkey"]).to eq nonpriority_ready_case.bfkey
expect(nonpriority_ready_case.reload.bfcurloc).to eq(judge.vacols_uniq_id)
expect(another_nonpriority_ready_case.reload.bfcurloc).to eq("83")
expect(third_nonpriority_ready_case.reload.bfcurloc).to eq("83")
Expand All @@ -369,6 +378,7 @@
let(:another_nonpriority_ready_case_docket_number) { "9901002" }
it "correctly orders the docket" do
expect(subject.count).to eq(1)
expect(subject.first["bfkey"]).to eq another_nonpriority_ready_case.bfkey
expect(nonpriority_ready_case.reload.bfcurloc).to eq("81")
expect(another_nonpriority_ready_case.reload.bfcurloc).to eq(judge.vacols_uniq_id)
expect(third_nonpriority_ready_case.reload.bfcurloc).to eq("83")
Expand Down Expand Up @@ -399,6 +409,7 @@
let(:genpop) { "not_genpop" }
it "distributes the case" do
expect(subject.count).to eq(1)
expect(subject.first["bfkey"]).to eq nonpriority_ready_case.bfkey
expect(nonpriority_ready_case.reload.bfcurloc).to eq(judge.vacols_uniq_id)
expect(another_nonpriority_ready_case.reload.bfcurloc).to eq("83")
expect(third_nonpriority_ready_case.reload.bfcurloc).to eq("83")
Expand All @@ -418,6 +429,7 @@
let(:genpop) { "only_genpop" }
it "does distribute the case only tied to inactive judge" do
expect(subject.count).to eq(1)
expect(subject.first["bfkey"]).to eq third_nonpriority_ready_case.bfkey
expect(third_nonpriority_ready_case.reload.bfcurloc).to eq(judge.vacols_uniq_id)
expect(nonpriority_ready_case.reload.bfcurloc).to eq("81")
expect(another_nonpriority_ready_case.reload.bfcurloc).to eq("83")
Expand Down Expand Up @@ -445,6 +457,9 @@
let(:bust_backlog) { true }
let(:another_hearing_judge) { judge.vacols_attorney_id }

# We don't use bust backlog if this feature toggle is enabled
before { FeatureToggle.disable!(:acd_distribute_by_docket_date) }

context "when the judge does not have 30 cases in their backlog" do
it "does not distribute any appeals" do
expect(subject.count).to eq(0)
Expand All @@ -463,6 +478,7 @@

it "only distributes the one case to get back down to 30" do
expect(subject.count).to eq(number_of_cases_over_backlog)
expect(subject.first["bfkey"]).to eq nonpriority_ready_case.bfkey
expect(nonpriority_ready_case.reload.bfcurloc).to eq(judge.vacols_uniq_id)
expect(another_nonpriority_ready_case.reload.bfcurloc).to eq("83")
end
Expand Down

0 comments on commit baae791

Please sign in to comment.