diff --git a/app/models/decision_issue.rb b/app/models/decision_issue.rb index 20274a37d36..4547094bace 100644 --- a/app/models/decision_issue.rb +++ b/app/models/decision_issue.rb @@ -169,10 +169,9 @@ def associated_request_issue request_issues.first end - def create_contesting_request_issue! - vacate_appeal_stream = Appeal.find_by(stream_type: "vacate", stream_docket_number: decision_review.docket_number) + def create_contesting_request_issue!(appeal) RequestIssue.find_or_create_by!( - decision_review: vacate_appeal_stream, + decision_review: appeal, decision_review_type: decision_review_type, contested_decision_issue_id: id, contested_rating_issue_diagnostic_code: diagnostic_code, diff --git a/app/models/post_decision_motion.rb b/app/models/post_decision_motion.rb index 622b3f1408f..95849f3d1e3 100644 --- a/app/models/post_decision_motion.rb +++ b/app/models/post_decision_motion.rb @@ -33,7 +33,7 @@ def request_issues_for_vacatur end def create_request_issues_for_vacatur - decision_issues_for_vacatur.map(&:create_contesting_request_issue!) + decision_issues_for_vacatur.map { |di| di.create_contesting_request_issue!(appeal) } end def vacated_decision_issues diff --git a/app/models/tasks/bva_dispatch_task.rb b/app/models/tasks/bva_dispatch_task.rb index a71102e47b5..779518cdd1d 100644 --- a/app/models/tasks/bva_dispatch_task.rb +++ b/app/models/tasks/bva_dispatch_task.rb @@ -28,6 +28,11 @@ def create_from_root_task(root_task) def outcode(appeal, params, user) if appeal.is_a?(Appeal) + if appeal.vacate? && appeal.vacate_type == "vacate_and_de_novo" + appeal.create_stream(:de_novo).tap do |de_novo_stream| + appeal.decision_issues.map { |di| di.create_contesting_request_issue!(de_novo_stream) } + end + end AmaAppealDispatch.new(appeal: appeal, user: user, params: params).call elsif appeal.is_a?(LegacyAppeal) LegacyAppealDispatch.new(appeal: appeal, params: params).call diff --git a/spec/factories/post_decision_motions.rb b/spec/factories/post_decision_motions.rb index af6a4c79732..57bce599e5c 100644 --- a/spec/factories/post_decision_motions.rb +++ b/spec/factories/post_decision_motions.rb @@ -2,24 +2,8 @@ FactoryBot.define do factory :post_decision_motion do - appeal { create(:appeal) } + appeal { create(:appeal, stream_type: "vacate") } disposition { "granted" } vacate_type { "straight_vacate" } - - before(:create) do |post_decision_motion| - appeal = post_decision_motion.appeal - next unless appeal.reload.decision_issues.empty? - - 3.times do |idx| - create( - :decision_issue, - :rating, - decision_review: appeal, - disposition: "denied", - description: "Decision issue description #{idx}", - decision_text: "decision issue" - ) - end - end end end diff --git a/spec/models/appeal_spec.rb b/spec/models/appeal_spec.rb index 91e2c8aac84..1faa04015fc 100644 --- a/spec/models/appeal_spec.rb +++ b/spec/models/appeal_spec.rb @@ -26,6 +26,23 @@ ) expect(subject.reload.claimant.participant_id).to eq(appeal.claimant.participant_id) end + + context "for de_novo appeal stream" do + let(:stream_type) { "de_novo" } + + it "creates a de_novo appeal stream with data from the original appeal" do + expect(subject).to have_attributes( + receipt_date: appeal.receipt_date, + veteran_file_number: appeal.veteran_file_number, + legacy_opt_in_approved: appeal.legacy_opt_in_approved, + veteran_is_not_claimant: appeal.veteran_is_not_claimant, + stream_docket_number: appeal.docket_number, + stream_type: stream_type + ) + expect(Appeal.de_novo.find_by(stream_docket_number: appeal.docket_number)).to_not be_nil + expect(subject.reload.claimant.participant_id).to eq(appeal.claimant.participant_id) + end + end end context "includes PrintsTaskTree concern" do diff --git a/spec/models/post_decision_motion_spec.rb b/spec/models/post_decision_motion_spec.rb index cc8a070ffc9..201b6b209cf 100644 --- a/spec/models/post_decision_motion_spec.rb +++ b/spec/models/post_decision_motion_spec.rb @@ -32,7 +32,7 @@ let(:post_decision_motion) do create( :post_decision_motion, - appeal: appeal, + appeal: vacate_stream, task: task, disposition: disposition, vacate_type: vacate_type, diff --git a/spec/models/tasks/bva_dispatch_task_spec.rb b/spec/models/tasks/bva_dispatch_task_spec.rb index 2f335fa8cf2..e87c8d1f9c7 100644 --- a/spec/models/tasks/bva_dispatch_task_spec.rb +++ b/spec/models/tasks/bva_dispatch_task_spec.rb @@ -44,7 +44,9 @@ describe ".outcode" do let(:user) { create(:user) } - let(:root_task) { create(:root_task) } + let(:root_task) { create(:root_task, appeal: appeal) } + let(:appeal) { create(:appeal, stream_type: stream_type) } + let(:stream_type) { "original" } let(:the_case) { create(:case) } let!(:legacy_appeal) { create(:legacy_appeal, vacols_case: the_case) } let(:citation_number) { "A18123456" } @@ -71,7 +73,6 @@ allow(ProcessDecisionDocumentJob).to receive(:perform_later) BvaDispatchTask.outcode(root_task.appeal.reload, params, user) - tasks = BvaDispatchTask.where(appeal: root_task.appeal, assigned_to: user) expect(tasks.length).to eq(1) task = tasks[0] @@ -123,6 +124,29 @@ end end + context "when de_novo appeal stream" do + let(:stream_type) { "vacate" } + let!(:post_decision_motion) do + create(:post_decision_motion, + appeal: appeal, vacate_type: "vacate_and_de_novo", + task: create(:task)) + end + + it "should create de_novo appeal stream" do + allow(ProcessDecisionDocumentJob).to receive(:perform_later) + + BvaDispatchTask.outcode(root_task.appeal, params, user) + tasks = BvaDispatchTask.where(appeal: appeal, assigned_to: user) + expect(tasks.length).to eq(1) + + de_novo_stream = Appeal.find_by(stream_docket_number: appeal.docket_number, stream_type: "de_novo") + + expect(de_novo_stream).to_not be_nil + request_issues = de_novo_stream.request_issues + expect(request_issues.size).to eq(appeal.decision_issues.size) + end + end + context "when decision_date is in the future" do let(:decision_date) { 1.day.from_now }