From baae791c650106e9b62c2a4fdd8650a76c052763 Mon Sep 17 00:00:00 2001 From: Craig Reese <109101548+craigrva@users.noreply.github.com> Date: Wed, 22 May 2024 07:46:24 -0500 Subject: [PATCH] APPEALS-43851: Add test to validate CAVC+AOD behavior on hearing docket 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 --- app/models/vacols/case_docket.rb | 18 +++---- .../dockets/hearing_request_docket_spec.rb | 51 +++++++++++++++---- spec/models/vacols/case_docket_spec.rb | 26 ++++++++-- 3 files changed, 68 insertions(+), 27 deletions(-) diff --git a/app/models/vacols/case_docket.rb b/app/models/vacols/case_docket.rb index f55307d65dc..1bf222daad0 100644 --- a/app/models/vacols/case_docket.rb +++ b/app/models/vacols/case_docket.rb @@ -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} ) " @@ -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} @@ -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} ) " @@ -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} diff --git a/spec/models/dockets/hearing_request_docket_spec.rb b/spec/models/dockets/hearing_request_docket_spec.rb index cc42870ae21..33feb362d7e 100644 --- a/spec/models/dockets/hearing_request_docket_spec.rb +++ b/spec/models/dockets/hearing_request_docket_spec.rb @@ -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 @@ -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") @@ -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, @@ -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 @@ -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( diff --git a/spec/models/vacols/case_docket_spec.rb b/spec/models/vacols/case_docket_spec.rb index 5b6929e9a6e..7ec250ed32e 100644 --- a/spec/models/vacols/case_docket_spec.rb +++ b/spec/models/vacols/case_docket_spec.rb @@ -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 @@ -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 @@ -55,7 +56,7 @@ 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 @@ -63,7 +64,7 @@ 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", @@ -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) } @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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) @@ -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