Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Vacated Decision Issues from Request Issues #13173

Merged
merged 41 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
38b1d58
added basic support for creating request issues from selected MTV dec…
Dec 18, 2019
8d5c8f3
only create request issues if disposition is grant type
Dec 18, 2019
83d41bc
Merge branch 'master' into jc/12373-mtv-create-request-issues
Dec 20, 2019
1f4cea5
moved creation of request issues to PostDecisionMotion model;
Dec 20, 2019
a9470c4
Merge branch 'master' into jc/12373-mtv-create-request-issues
Dec 20, 2019
29af3f7
adjustments to post_decision_motion_updater_spec to allow tests re in…
Dec 20, 2019
63ba17f
linting
Dec 20, 2019
c3a5296
we now save all MTV issue IDs for "granted" disposition
Dec 23, 2019
c4488d2
Merge branch 'master' into jc/12373-mtv-create-request-issues
Dec 23, 2019
80cf6b8
we now add all decision issue IDs for full grant in PostDecisionMotio…
Dec 24, 2019
b55570f
added test for PostDecisionMotionUpdater adding all vacated_decision_…
Dec 24, 2019
84e4cac
linting
Dec 24, 2019
18451dc
updated schema to indicate addtl usage of vacated_decision_issue_ids …
Jan 2, 2020
84140b9
better logic for populating vacated_decision_issue_ids field in PostD…
Jan 2, 2020
4707bfc
fixed wrong naming in disposition check in PostDecisionMotionUpdater
Jan 2, 2020
9d6fce1
Merge branch 'master' into jc/12373-mtv-create-request-issues
Jan 4, 2020
504fc81
removed superfluous commented line
Jan 4, 2020
c0b14b8
moved logic for creating request issue from decision issue to Decisio…
Jan 6, 2020
ae016df
began adding new_decision_issue_from! method to RequestIssue
Jan 8, 2020
99fcccb
Merge branch 'master' into jc/13069-mtv-create-decision-issues
Jan 14, 2020
dc869f3
updated method name in RequestIssue to "create_vacated_decision_issue!"
Jan 16, 2020
9c4536f
added code & tests for generating vacated decision issues from PostDe…
Jan 16, 2020
425cdf9
adjustments per codeclimate
Jan 16, 2020
b98d0c5
Merge branch 'master' into jc/13069-mtv-create-decision-issues
Jan 18, 2020
fb34f9d
Merge branch 'master' into jc/13069-mtv-create-decision-issues
Jan 18, 2020
f684246
updated various items in DecisionIssue, RequestIssue, & PostDecisionM…
Jan 21, 2020
a26e0c9
Merge branch 'master' into jc/13069-mtv-create-decision-issues
Jan 21, 2020
ea02577
fixed error in MTV test
Jan 21, 2020
74679be
Merge branch 'master' into jc/13069-mtv-create-decision-issues
Jan 21, 2020
7d01a8b
began adding PostDecisionMotionController.create_issues endpoint & tests
Jan 21, 2020
1e2baaa
added "create_issues" endpoint on PostDecisionMotionsController:
Jan 22, 2020
8e78862
linting
Jan 22, 2020
cb160e0
removed mistaken commit of modified capybara.rb
jcq Jan 22, 2020
be25dff
DecisionIssue.create_contesting_request_issue now adds new request is…
Feb 5, 2020
ae0395c
Merge branch 'master' into jc/13069-mtv-create-decision-issues
Feb 7, 2020
b9ee9a6
moved calls to create new request & decision issues to PostDecisionMo…
Feb 7, 2020
c376303
removed create_issues & related from PostDecisionMotionsController
Feb 7, 2020
ba135f4
updated tests in post_decision_motion_spec
Feb 7, 2020
5d84d90
removed tests for PostDecisionMotionsController.create_tasks
Feb 7, 2020
583d3de
removed unsed route for create_issues off of PostDecisionMotionsContr…
Feb 7, 2020
0d24049
Merge branch 'master' into jc/13069-mtv-create-decision-issues
Feb 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion app/controllers/post_decision_motions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class PostDecisionMotionsController < ApplicationController
before_action :verify_task_access
before_action :verify_task_access, only: [:create, :return_to_lit_support]

def create
motion_updater = PostDecisionMotionUpdater.new(task, motion_params)
Expand All @@ -25,6 +25,17 @@ def return_to_lit_support
render json: { tasks: ::WorkQueue::TaskSerializer.new(appeal_tasks, is_collection: true) }
end

def create_issues
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to move creating issues to the PostDecisionMotionUpdater, when the new appeal stream is getting created

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, if their creation is automatic we don't need an endpoint for it.

Methinks it makes sense to wait until your PR (#13325) lands and then incorporate upon new stream creation.

new_request_issues = post_decision_motion.create_request_issues_for_vacatur

new_decision_issues = post_decision_motion.create_vacated_decision_issues

render json: {
request_issues: Intake::RequestIssueSerializer.new(new_request_issues, is_collection: true),
decision_issues: Intake::DecisionIssueSerializer.new(new_decision_issues, is_collection: true)
}
end

private

def verify_task_access
Expand All @@ -40,4 +51,16 @@ def task
def motion_params
params.permit(:disposition, :task_id, :vacate_type, :instructions, :assigned_to_id, vacated_decision_issue_ids: [])
end

def create_issues_params
params.permit(:id)
end

def motion_id
create_issues_params[:id]
end

def post_decision_motion
PostDecisionMotion.find(motion_id)
end
end
2 changes: 1 addition & 1 deletion app/models/decision_issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def associated_request_issue
end

def create_contesting_request_issue!
RequestIssue.create!(
RequestIssue.find_or_create_by!(
decision_review: decision_review,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are now going to be added onto the new appeal stream instead of the original appeal

decision_review_type: decision_review_type,
contested_decision_issue_id: id,
Expand Down
18 changes: 15 additions & 3 deletions app/models/post_decision_motion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,26 @@ class PostDecisionMotion < ApplicationRecord
vacate_and_de_novo: "vacate_and_de_novo"
}

def vacated_issues
def decision_issues_for_vacatur
return [] unless vacated_decision_issue_ids

DecisionIssue.find(vacated_decision_issue_ids)
end

def create_request_issues_for_vacature
vacated_issues.map(&:create_contesting_request_issue!)
def request_issues_for_vacatur
@request_issues_for_vacatur ||= RequestIssue.where(contested_decision_issue_id: vacated_decision_issue_ids)
end

def create_request_issues_for_vacatur
decision_issues_for_vacatur.map(&:create_contesting_request_issue!)
end

def vacated_decision_issues
@vacated_decision_issues ||= request_issues_for_vacatur.map { |ri| ri.decision_issues.first }
end

def create_vacated_decision_issues
request_issues_for_vacatur.map(&:create_vacated_decision_issue!)
end

private
Expand Down
12 changes: 12 additions & 0 deletions app/models/request_issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,18 @@ def create_decision_issue_from_params(decision_issue_param)
)
end

def create_vacated_decision_issue!
decision_issues.find_or_create_by!(
decision_review: decision_review,
jcq marked this conversation as resolved.
Show resolved Hide resolved
decision_review_type: decision_review_type,
disposition: "vacated",
description: "The decision: #{description} has been vacated.",
caseflow_decision_date: Time.zone.today,
benefit_type: benefit_type,
participant_id: decision_review.veteran.participant_id
)
end

jcq marked this conversation as resolved.
Show resolved Hide resolved
def requires_record_request_task?
eligible? && !is_unidentified && !benefit_type_requires_payee_code?
end
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
end

post "post_decision_motions/return", to: "post_decision_motions#return_to_lit_support"
post "post_decision_motions/:id/create_issues", to: "post_decision_motions#create_issues"
jcq marked this conversation as resolved.
Show resolved Hide resolved
post "post_decision_motions", to: "post_decision_motions#create"

# :nocov:
Expand Down
47 changes: 47 additions & 0 deletions spec/controllers/post_decision_motions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
let(:judge) { create(:user) }
let(:judge_team) { JudgeTeam.create_for_judge(judge) }

let(:post_decision_motion) { create(:post_decision_motion) }

before do
User.authenticate!(roles: ["System Admin"])
User.stub = judge
Expand Down Expand Up @@ -73,6 +75,51 @@
end
end

describe "#create_issues" do
jcq marked this conversation as resolved.
Show resolved Hide resolved
context "with a valid PostDecisionMotion id" do
it "returns a 200 response and creates issues" do
allow(controller).to receive(:verify_authentication).and_return(true)

create_task_without_unnecessary_models
judge_team.add_user(user)

appeal = post_decision_motion.task.appeal.reload

expect(appeal.decision_issues.size).to eq(3)

post :create_issues, params: { id: post_decision_motion.id }

appeal.reload

expect(response).to be_success
expect(appeal.request_issues.size).to eq(3)
expect(appeal.decision_issues.size).to eq(6)
end
end

context "with an invalid PostDecisionMotion id" do
it "returns a 404 response and doesn't create issues" do
allow(controller).to receive(:verify_authentication).and_return(true)

create_task_without_unnecessary_models
judge_team.add_user(user)

appeal = post_decision_motion.task.appeal.reload

expect(appeal.decision_issues.size).to eq(3)
expect(appeal.request_issues.size).to eq(3)

post :create_issues, params: { id: 9999 }

appeal.reload

expect(response.status).to eq 404
expect(appeal.request_issues.size).to eq(3)
expect(appeal.decision_issues.size).to eq(3)
end
end
end

def create_task_without_unnecessary_models
appeal = create(:appeal)
assigned_by = create(:user)
Expand Down
21 changes: 19 additions & 2 deletions spec/factories/post_decision_motions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,24 @@

FactoryBot.define do
factory :post_decision_motion do
disposition { "MyString" }
task { nil }
task { create(:judge_address_motion_to_vacate_task) }
disposition { "granted" }
vacate_type { "straight_vacate" }

before(:create) do |post_decision_motion|
appeal = post_decision_motion.task.appeal
return 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
2 changes: 1 addition & 1 deletion spec/feature/queue/motion_to_vacate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@
motion = PostDecisionMotion.find_by(task: judge_address_motion_to_vacate_task)
expect(motion).to_not be_nil
expect(motion.disposition).to eq("partially_granted")
expect(motion.vacated_issues.length).to eq(issues_to_select.length)
expect(motion.decision_issues_for_vacatur.length).to eq(issues_to_select.length)

# Verify new task creation
instructions = format_judge_instructions(
Expand Down
29 changes: 23 additions & 6 deletions spec/models/post_decision_motion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
let(:motions_atty) { create(:user, full_name: "Motions attorney") }
let(:appeal) { create(:appeal) }
let(:orig_decision_issues) do
Array.new(3) do
Array.new(3) do |index|
create(
:decision_issue,
decision_review: appeal,
disposition: "denied"
disposition: "denied",
description: "issue #{index}",
participant_id: appeal.veteran.participant_id
)
end
end
Expand All @@ -41,15 +43,30 @@
lit_support_team.add_user(motions_atty)
end

context "handles creation of request issues" do
context "#create_request_issues_for_vacatur" do
let(:disposition) { "granted" }
let(:vacate_type) { "vacate_and_readjudication" }
subject { post_decision_motion.create_request_issues_for_vacatur }

it "creates a request issue for every selected decision issue" do
expect(appeal.request_issues.length).to eq 0
post_decision_motion.create_request_issues_for_vacature
expect(appeal.request_issues.size).to eq 0
subject
appeal.reload
expect(appeal.request_issues.length).to eq 3
expect(appeal.request_issues.size).to eq 3
end
end

context "#create_vacated_decision_issues" do
let(:disposition) { "granted" }
let(:vacate_type) { "vacate_and_readjudication" }
subject { post_decision_motion.create_vacated_decision_issues }

it "creates a vacated decision issue for every selected decision issue" do
expect(post_decision_motion.decision_issues_for_vacatur.size).to eq 3
post_decision_motion.create_request_issues_for_vacatur
subject
appeal.reload
expect(appeal.decision_issues.size).to eq 6
end
end
end