Skip to content

Commit

Permalink
Allow SCM team members to move AMA cases (#13786)
Browse files Browse the repository at this point in the history
Bumps #12424

### Description
This PR addresses all of the AMA AC from #12424 except for Request Cases on behalf of the Judge which is addressed by #13727. Allows SCM users to perform all assigning and reassigning judges can on AMA cases.

### Acceptance Criteria
 - [x] Reassign ama case at judge assign to another judge by acting on a JudgeAssignTask assigned to a judge  
 - [x] Assign ama tasks to an attorney by acting on a JudgeAssignTask assigned to a judge
 - [x] Reassign ama tasks to an attorney by acting on an AttorneyTask assigned to an attorney
 - [x] Cancel an ama AttorneyTask to send it back to the judge
 - [x] Reassign ama case at judge review to another judge by acting on a JudgeDecisionReviewTask assigned to a judge

### Testing Plan

#### AMA at judge assign
1. Sign in as BVARDUNKLE and go to /queue/3/assign (BVAAAAABSHIRE's assign queue)
2. Pick an AMA assign task and go to the case details screen
3. Check the starting task tree
```ruby
Appeal.find_by(uuid: "52eaece1-0f6a-403a-844d-8882f7adfe3b").treee
                                         ┌────────────────────────────────────────────────────────────────────┐
Appeal 338 (evidence_submission) ─────── │ ID   │ STATUS    │ ASGN_BY │ ASGN_TO     │ UPDATED_AT              │
└── RootTask                             │ 1581 │ on_hold   │         │ Bva         │ 2020-03-17 20:50:11 UTC │
    ├── DistributionTask                 │ 1582 │ completed │         │ Bva         │ 2020-03-17 20:50:53 UTC │
    │   └── EvidenceSubmissionWindowTask │ 1583 │ assigned  │         │ MailTeam    │ 2020-03-17 20:50:11 UTC │
    └── JudgeAssignTask                  │ 1584 │ assigned  │         │ BVAAABSHIRE │ 2020-03-17 20:50:53 UTC │
                                         └────────────────────────────────────────────────────────────────────┘
```
4. Select "Re-assign to a judge" and reassign to "JudgeHasAttorneys_Cases"
5. Task tree shows cancelled original assign task, new task is assigned to BVARERDMAN and assigned by BVARDUNKLE
```ruby
                                         ┌───────────────────────────────────────────────────────────────────────┐
Appeal 338 (evidence_submission) ─────── │ ID   │ STATUS    │ ASGN_BY    │ ASGN_TO     │ UPDATED_AT              │
└── RootTask                             │ 1581 │ on_hold   │            │ Bva         │ 2020-03-17 20:50:11 UTC │
    ├── DistributionTask                 │ 1582 │ completed │            │ Bva         │ 2020-03-17 20:50:53 UTC │
    │   └── EvidenceSubmissionWindowTask │ 1583 │ assigned  │            │ MailTeam    │ 2020-03-17 20:50:11 UTC │
    ├── JudgeAssignTask                  │ 1584 │ cancelled │            │ BVAAABSHIRE │ 2020-03-23 16:03:58 UTC │
    └── JudgeAssignTask                  │ 1604 │ assigned  │ BVARDUNKLE │ BVARERDMAN  │ 2020-03-23 16:03:58 UTC │
                                         └───────────────────────────────────────────────────────────────────────┘
```
6. Go back to the case details of this case, assigned to and assigned by are updated
7. Select "Assign to attorney" and assign to "Steve Casper"
8. Task tree shows  complete Assign task, new decision review task is assigned to BVARERDMAN, assigned by BVARDUNKLE, and a new attorney task assigned to BVASCASPER1, assigned by BVARDUNKLE
```ruby
                                         ┌───────────────────────────────────────────────────────────────────────┐
Appeal 338 (evidence_submission) ─────── │ ID   │ STATUS    │ ASGN_BY    │ ASGN_TO     │ UPDATED_AT              │
└── RootTask                             │ 1581 │ on_hold   │            │ Bva         │ 2020-03-17 20:50:11 UTC │
    ├── DistributionTask                 │ 1582 │ completed │            │ Bva         │ 2020-03-17 20:50:53 UTC │
    │   └── EvidenceSubmissionWindowTask │ 1583 │ assigned  │            │ MailTeam    │ 2020-03-17 20:50:11 UTC │
    ├── JudgeAssignTask                  │ 1584 │ cancelled │            │ BVAAABSHIRE │ 2020-03-23 16:03:58 UTC │
    ├── JudgeAssignTask                  │ 1604 │ completed │ BVARDUNKLE │ BVARERDMAN  │ 2020-03-23 16:07:14 UTC │
    └── JudgeDecisionReviewTask          │ 1605 │ on_hold   │ BVARDUNKLE │ BVARERDMAN  │ 2020-03-23 16:07:15 UTC │
        └── AttorneyTask                 │ 1606 │ assigned  │ BVARDUNKLE │ BVASCASPER1 │ 2020-03-23 16:07:15 UTC │
                                         └───────────────────────────────────────────────────────────────────────┘
```
9. Go back to the case details of this case, assigned to and assigned by are updated
10. Select "Assign to attorney" and assign to "Lexi Brown"
11. Task tree shows the updated assignee of BVALBROWN
```ruby
                                         ┌───────────────────────────────────────────────────────────────────────┐
Appeal 338 (evidence_submission) ─────── │ ID   │ STATUS    │ ASGN_BY    │ ASGN_TO     │ UPDATED_AT              │
└── RootTask                             │ 1581 │ on_hold   │            │ Bva         │ 2020-03-17 20:50:11 UTC │
    ├── DistributionTask                 │ 1582 │ completed │            │ Bva         │ 2020-03-17 20:50:53 UTC │
    │   └── EvidenceSubmissionWindowTask │ 1583 │ assigned  │            │ MailTeam    │ 2020-03-17 20:50:11 UTC │
    ├── JudgeAssignTask                  │ 1584 │ cancelled │            │ BVAAABSHIRE │ 2020-03-23 16:03:58 UTC │
    ├── JudgeAssignTask                  │ 1604 │ completed │ BVARDUNKLE │ BVARERDMAN  │ 2020-03-23 16:07:14 UTC │
    └── JudgeDecisionReviewTask          │ 1605 │ on_hold   │ BVARDUNKLE │ BVARERDMAN  │ 2020-03-23 16:07:15 UTC │
        └── AttorneyTask                 │ 1606 │ assigned  │ BVARDUNKLE │ BVALBROWN   │ 2020-03-23 16:09:47 UTC │
                                         └───────────────────────────────────────────────────────────────────────┘
```
12. Go back to the case details of this case, assigned to is updated
13. Select "Cancel task"
14. Task tree shows cancelled attorney and judge decision review task, new. judge assign task assigned to BVAAABSHIRE
```ruby
                                         ┌───────────────────────────────────────────────────────────────────────┐
Appeal 338 (evidence_submission) ─────── │ ID   │ STATUS    │ ASGN_BY    │ ASGN_TO     │ UPDATED_AT              │
└── RootTask                             │ 1581 │ on_hold   │            │ Bva         │ 2020-03-17 20:50:11 UTC │
    ├── DistributionTask                 │ 1582 │ completed │            │ Bva         │ 2020-03-17 20:50:53 UTC │
    │   └── EvidenceSubmissionWindowTask │ 1583 │ assigned  │            │ MailTeam    │ 2020-03-17 20:50:11 UTC │
    ├── JudgeAssignTask                  │ 1584 │ cancelled │            │ BVAAABSHIRE │ 2020-03-23 16:03:58 UTC │
    ├── JudgeAssignTask                  │ 1604 │ completed │ BVARDUNKLE │ BVARERDMAN  │ 2020-03-23 16:07:14 UTC │
    ├── JudgeDecisionReviewTask          │ 1605 │ cancelled │ BVARDUNKLE │ BVARERDMAN  │ 2020-03-23 16:12:20 UTC │
    │   └── AttorneyTask                 │ 1606 │ cancelled │ BVARDUNKLE │ BVALBROWN   │ 2020-03-23 16:12:20 UTC │
    └── JudgeAssignTask                  │ 1614 │ assigned  │            │ BVAAABSHIRE │ 2020-03-23 16:15:38 UTC │
                                         └───────────────────────────────────────────────────────────────────────┘
```
 - [x] Reassign ama case at judge assign to another judge by acting on a JudgeAssignTask assigned to a judge  
 - [x] Assign ama tasks to an attorney by acting on a JudgeAssignTask assigned to a judge
 - [x] Reassign ama tasks to an attorney by acting on an AttorneyTask assigned to an attorney
 - [ ] Cancel an ama AttorneyTask to send it back to the judge

#### AMA at judge decision review
1. Pick a judge decision review task assigned to BVAAABSHIRE
```ruby
uuid = JudgeDecisionReviewTask.open.where(assigned_to: User.find(3)).first.appeal.uuid
=> "92d5c3a6-32b4-4e9e-8a74-e1bfab94f17a"
Appeal.find_by(uuid: uuid).treee
                                ┌───────────────────────────────────────────────────────────────────────┐
Appeal 52 (direct_review) ───── │ ID  │ STATUS    │ ASGN_BY     │ ASGN_TO     │ UPDATED_AT              │
└── RootTask                    │ 585 │ on_hold   │             │ Bva         │ 2020-03-05 17:16:52 UTC │
    └── JudgeDecisionReviewTask │ 586 │ assigned  │ CSS_ID103   │ BVAAABSHIRE │ 2020-03-05 17:16:52 UTC │
        └── AttorneyTask        │ 587 │ completed │ BVAAABSHIRE │ BVASCASPER1 │ 2020-03-05 17:16:52 UTC │
                                └───────────────────────────────────────────────────────────────────────┘
```
2.  Go to the case details page for this case (/queue/appeals/92d5c3a6-32b4-4e9e-8a74-e1bfab94f17a)
3. Select "Re-assign to a judge" and reassign to "JudgeHasAttorneys_Cases"
4. Task tree shows cancelled original assigne task, new task is assigned to BVARERDMAN and assigned by BVARDUNKLE, keeps the completed attorney child task
```ruby
                                ┌────────────────────────────────────────────────────────────────────────┐
Appeal 52 (direct_review) ───── │ ID   │ STATUS    │ ASGN_BY     │ ASGN_TO     │ UPDATED_AT              │
└── RootTask                    │ 585  │ on_hold   │             │ Bva         │ 2020-03-05 17:16:52 UTC │
    ├── JudgeDecisionReviewTask │ 586  │ cancelled │ CSS_ID103   │ BVAAABSHIRE │ 2020-03-23 16:22:57 UTC │
    └── JudgeDecisionReviewTask │ 1615 │ assigned  │ BVARDUNKLE  │ BVARERDMAN  │ 2020-03-23 16:22:57 UTC │
        └── AttorneyTask        │ 587  │ completed │ BVAAABSHIRE │ BVASCASPER1 │ 2020-03-23 16:22:57 UTC │
                                └────────────────────────────────────────────────────────────────────────┘
```
5. Go back to the case details of this case, assigned to and assigned by are updated
 - [x] Reassign ama case at judge review to another judge by acting on a JudgeDecisionReviewTask assigned to a judge
  • Loading branch information
hschallhorn authored Mar 30, 2020
1 parent cac8071 commit a167f15
Show file tree
Hide file tree
Showing 18 changed files with 275 additions and 107 deletions.
1 change: 1 addition & 0 deletions .reek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ detectors:
- TaskSorter#sort_requires_case_norm?
- VBMSCaseflowLogger#log
- Veteran
- JudgeDecisionReviewTask#additional_available_actions
UncommunicativeVariableName:
exclude:
- Address
Expand Down
17 changes: 13 additions & 4 deletions app/models/tasks/attorney_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class AttorneyTask < Task
after_update :send_back_to_judge_assign, if: :attorney_task_just_cancelled?

def available_actions(user)
# Both the judge who assigned this task and the judge who is assigned the parent review task get these actions
if parent.is_a?(JudgeTask) && (parent.assigned_to == user || assigned_by == user)
if can_be_moved_by_user?(user)
return [
Constants.TASK_ACTIONS.ASSIGN_TO_ATTORNEY.to_h,
Constants.TASK_ACTIONS.CANCEL_TASK.to_h
Expand Down Expand Up @@ -54,6 +53,14 @@ def stays_with_reassigned_parent?

private

def can_be_moved_by_user?(user)
return false unless parent.is_a?(JudgeTask)

# The judge who is assigned the parent review task, the assigning judge, and SpecialCaseMovementTeam members can
# cancel or reassign this task
parent.assigned_to == user || assigned_by == user || user&.can_act_on_behalf_of_judges?
end

def child_attorney_tasks_are_completed
if parent&.children_attorney_tasks&.open&.any?
errors.add(:parent, "has open child tasks")
Expand All @@ -65,7 +72,9 @@ def assigned_to_role_is_valid
end

def assigned_by_role_is_valid
errors.add(:assigned_by, "has to be a judge") if assigned_by && !assigned_by.judge_in_vacols?
if assigned_by && (!assigned_by.judge_in_vacols? && !assigned_by.can_act_on_behalf_of_judges?)
errors.add(:assigned_by, "has to be a judge or special case movement team member")
end
end

def attorney_task_just_cancelled?
Expand All @@ -84,6 +93,6 @@ def cancel_parent_judge_review
end

def open_judge_assign_task
JudgeAssignTask.create!(appeal: appeal, parent: appeal.root_task, assigned_to: assigned_by)
JudgeAssignTask.create!(appeal: appeal, parent: appeal.root_task, assigned_to: parent.assigned_to)
end
end
4 changes: 3 additions & 1 deletion app/models/tasks/judge_decision_review_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
class JudgeDecisionReviewTask < JudgeTask
before_create :verify_user_task_unique

def additional_available_actions(_user)
def additional_available_actions(user)
return [] unless assigned_to == user

judge_checkout_label = if ama?
Constants.TASK_ACTIONS.JUDGE_AMA_CHECKOUT.to_h
else
Expand Down
5 changes: 5 additions & 0 deletions app/models/tasks/judge_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ def available_actions(user)
Constants.TASK_ACTIONS.REASSIGN_TO_JUDGE.to_h,
additional_available_actions(user)
].flatten
elsif user&.can_act_on_behalf_of_judges?
[
Constants.TASK_ACTIONS.REASSIGN_TO_JUDGE.to_h,
additional_available_actions(user)
].flatten
else
[]
end
Expand Down
19 changes: 10 additions & 9 deletions app/repositories/task_action_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ def mail_assign_to_organization_data(task, _user = nil)
end

def cancel_task_data(task, _user = nil)
assigner_name = task.assigned_by&.full_name || "the assigner"
return_to_name = task.is_a?(AttorneyTask) ? task.parent.assigned_to.full_name : task_assigner_name(task)
{
modal_title: COPY::CANCEL_TASK_MODAL_TITLE,
modal_body: format(COPY::CANCEL_TASK_MODAL_DETAIL, assigner_name),
modal_body: format(COPY::CANCEL_TASK_MODAL_DETAIL, return_to_name),
message_title: format(COPY::CANCEL_TASK_CONFIRMATION, task.appeal.veteran_full_name),
message_detail: format(COPY::MARK_TASK_COMPLETE_CONFIRMATION_DETAIL, assigner_name)
message_detail: format(COPY::MARK_TASK_COMPLETE_CONFIRMATION_DETAIL, return_to_name)
}
end

Expand All @@ -47,10 +47,7 @@ def cancel_foreign_veterans_case_data(task, _user = nil)
modal_title: COPY::CANCEL_FOREIGN_VETERANS_CASE_TASK_MODAL_TITLE,
modal_body: COPY::CANCEL_FOREIGN_VETERANS_CASE_TASK_MODAL_DETAIL,
message_title: format(COPY::CANCEL_TASK_CONFIRMATION, task.appeal.veteran_full_name),
message_detail: format(
COPY::MARK_TASK_COMPLETE_CONFIRMATION_DETAIL,
task.assigned_by&.full_name || "the assigner"
)
message_detail: format(COPY::MARK_TASK_COMPLETE_CONFIRMATION_DETAIL, task_assigner_name(task))
}
end

Expand Down Expand Up @@ -118,10 +115,10 @@ def judge_dispatch_return_to_attorney_data(task, _user = nil)
}
end

def assign_to_attorney_data(task, _user = nil)
def assign_to_attorney_data(task, user)
{
selected: nil,
options: nil,
options: user.can_act_on_behalf_of_judges? ? users_to_options(Attorney.list_all) : nil,
type: task.is_a?(LegacyTask) ? AttorneyLegacyTask.name : AttorneyTask.name
}
end
Expand Down Expand Up @@ -333,6 +330,10 @@ def review_decision_draft(task, user)

private

def task_assigner_name(task)
task.assigned_by&.full_name || "the assigner"
end

def users_to_options(users)
users.map do |user|
{
Expand Down
4 changes: 3 additions & 1 deletion app/workflows/attorney_task_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ def call
attr_reader :judge_assign_task, :task_params

def tasks
judge_review_task = JudgeDecisionReviewTask.create!(judge_assign_task.slice(:appeal, :assigned_to, :parent))
judge_review_task = JudgeDecisionReviewTask.create!(
judge_assign_task.slice(:appeal, :assigned_to, :parent).merge(assigned_by: task_params[:assigned_by])
)
judge_assign_task.update!(status: Constants.TASK_STATUSES.completed)
attorney_task = AttorneyTask.create!(task_params.merge(parent: judge_review_task))
[attorney_task, judge_review_task, judge_assign_task]
Expand Down
20 changes: 17 additions & 3 deletions client/app/queue/AssignToAttorneyModalView.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import PropTypes from 'prop-types';

import { AssignWidgetModal } from './components/AssignWidget';

import COPY from '../../COPY.json';
import COPY from '../../COPY';

import {
taskById
Expand Down Expand Up @@ -37,7 +38,7 @@ class AssignToAttorneyModalView extends React.PureComponent {
}

render = () => {
const { task, userId } = this.props;
const { task, userId, match } = this.props;
const previousAssigneeId = task ? task.assignedTo.id.toString() : null;

if (!previousAssigneeId) {
Expand All @@ -46,16 +47,29 @@ class AssignToAttorneyModalView extends React.PureComponent {

return <AssignWidgetModal
isModal
match={match}
userId={userId}
onTaskAssignment={this.handleAssignment}
previousAssigneeId={previousAssigneeId}
selectedTasks={[task]} />;
}
}

AssignToAttorneyModalView.propTypes = {
task: PropTypes.shape({
assignedTo: PropTypes.shape({
id: PropTypes.number
})
}),
userId: PropTypes.string,
match: PropTypes.object,
initialAssignTasksToUser: PropTypes.func,
reassignTasksToUser: PropTypes.func
};

const mapStateToProps = (state, ownProps) => {
return {
task: taskById(state, { taskId: ownProps.taskId })
task: taskById(state, { taskId: ownProps.match.params.taskId })
};
};

Expand Down
6 changes: 3 additions & 3 deletions client/app/queue/CaseDetailsLoadingScreen.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import PropTypes from 'prop-types';

import { onReceiveAppealDetails, onReceiveTasks, setAttorneysOfJudge, fetchAllAttorneys } from './QueueActions';

class CaseDetailLoadingScreen extends React.PureComponent {
class CaseDetailsLoadingScreen extends React.PureComponent {
loadActiveAppealAndTask = () => {
const {
appealId,
Expand Down Expand Up @@ -113,7 +113,7 @@ const mapDispatchToProps = (dispatch) => bindActionCreators({
fetchAllAttorneys
}, dispatch);

CaseDetailLoadingScreen.propTypes = {
CaseDetailsLoadingScreen.propTypes = {
children: PropTypes.array,
appealId: PropTypes.string,
userId: PropTypes.number,
Expand All @@ -125,4 +125,4 @@ CaseDetailLoadingScreen.propTypes = {
fetchAllAttorneys: PropTypes.func
};

export default (connect(mapStateToProps, mapDispatchToProps)(CaseDetailLoadingScreen));
export default (connect(mapStateToProps, mapDispatchToProps)(CaseDetailsLoadingScreen));
2 changes: 1 addition & 1 deletion client/app/queue/QueueApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class QueueApp extends React.PureComponent {

routedAdvancedOnDocketMotion = (props) => <AdvancedOnDocketMotionView {...props.match.params} />;

routedAssignToAttorney = (props) => <AssignToAttorneyModalView userId={this.props.userId} {...props.match.params} />;
routedAssignToAttorney = (props) => <AssignToAttorneyModalView userId={this.props.userId} match={props.match} />;

routedAssignToSingleTeam = (props) => <AssignToView isTeamAssign assigneeAlreadySelected {...props.match.params} />;

Expand Down
18 changes: 14 additions & 4 deletions client/app/queue/components/AssignWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import pluralize from 'pluralize';
import COPY from '../../../COPY';
import { sprintf } from 'sprintf-js';
import { fullWidth } from '../constants';
import { taskActionData } from '../utils';

import QueueFlowModal from './QueueFlowModal';

const OTHER = 'OTHER';
Expand Down Expand Up @@ -131,14 +133,22 @@ class AssignWidget extends React.PureComponent {
let placeholderOther = COPY.ASSIGN_WIDGET_LOADING;
let selectedOptionOther = null;

if (attorneys.error) {
placeholderOther = COPY.ASSIGN_WIDGET_ERROR_LOADING_ATTORNEYS;
}

if (attorneys.data) {
optionsOther = attorneys.data.map(optionFromAttorney);
placeholderOther = COPY.ASSIGN_WIDGET_DROPDOWN_PLACEHOLDER;
selectedOptionOther = _.find(optionsOther, (option) => option.value === selectedAssigneeSecondary);
} else if (this.props.isModal) {
optionsOther = taskActionData({
...this.props,
task: selectedTasks[0]
})?.options;
}

if (attorneys.error) {
placeholderOther = COPY.ASSIGN_WIDGET_ERROR_LOADING_ATTORNEYS;
if (optionsOther?.length) {
placeholderOther = COPY.ASSIGN_WIDGET_DROPDOWN_PLACEHOLDER;
selectedOptionOther = _.find(optionsOther, (option) => option.value === selectedAssigneeSecondary);
}

const Widget = <React.Fragment>
Expand Down
68 changes: 43 additions & 25 deletions spec/controllers/judge_assign_tasks_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
describe "POST /judge_assign_tasks" do
let!(:attorney) { create(:user) }
let!(:judge) { create(:user) }
let!(:user) { judge }
let!(:second_judge) { create(:user) }
let!(:attorney_staff) { create(:staff, :attorney_role, sdomainid: attorney.css_id) }
let!(:judge_staff) { create(:staff, :judge_role, sdomainid: judge.css_id) }
Expand All @@ -21,41 +22,58 @@
end
end

before { User.authenticate!(user: judge) }
before { User.authenticate!(user: user) }

subject { post :create, params: { tasks: params } }

context "when cases will be assigned to an attorney" do
it "returns the newly created tasks along with their new parents and old parents" do
subject
shared_examples "attorney task assignment" do
it "returns the newly created tasks along with their new parents and old parents" do
subject

expect(response.status).to eq 200
response_body = JSON.parse(response.body)["tasks"]["data"]
expect(response_body.count).to eq 9
expect(response.status).to eq 200
response_body = JSON.parse(response.body)["tasks"]["data"]
expect(response_body.count).to eq 9

attorney_tasks = response_body.select { |task| task["attributes"]["type"].eql? AttorneyTask.name }
expect(attorney_tasks.count).to eq 3
attorney_tasks.each do |attorney_task|
expect(attorney_task["attributes"]["assigned_to"]["id"]).to eq attorney.id
expect(attorney_task["attributes"]["assigned_by"]["pg_id"]).to eq judge.id
expect(attorney_task["attributes"]["status"]).to eq Constants.TASK_STATUSES.assigned
expect(AttorneyTask.find(attorney_task["id"]).parent.type).to eq JudgeDecisionReviewTask.name
attorney_tasks = response_body.select { |task| task["attributes"]["type"].eql? AttorneyTask.name }
expect(attorney_tasks.count).to eq 3
attorney_tasks.each do |attorney_task|
expect(attorney_task["attributes"]["assigned_to"]["id"]).to eq attorney.id
expect(attorney_task["attributes"]["assigned_by"]["pg_id"]).to eq user.id
expect(attorney_task["attributes"]["status"]).to eq Constants.TASK_STATUSES.assigned
expect(AttorneyTask.find(attorney_task["id"]).parent.type).to eq JudgeDecisionReviewTask.name
end

review_tasks = response_body.select { |task| task["attributes"]["type"].eql? JudgeDecisionReviewTask.name }
expect(review_tasks.count).to eq 3
review_tasks.each do |review_task|
judge_review_task = JudgeDecisionReviewTask.find(review_task["id"])
expect(review_task["attributes"]["assigned_to"]["id"]).to eq judge.id
expect(review_task["attributes"]["assigned_by"]["pg_id"]).to eq user.id
expect(judge_review_task.children.first.type).to eq AttorneyTask.name
expect(judge_review_task.reload.status).to eq Constants.TASK_STATUSES.on_hold
end

assign_tasks = response_body.select { |task| task["attributes"]["type"].eql? JudgeAssignTask.name }
expect(assign_tasks.count).to eq 3
expect(assign_tasks.all? do |assign_task|
assign_task["attributes"]["status"].eql? Constants.TASK_STATUSES.completed
end).to eq true
end
end

it_behaves_like "attorney task assignment"

context "when the assigner is a member of the scm team" do
let(:user) { create(:user) }

review_tasks = response_body.select { |task| task["attributes"]["type"].eql? JudgeDecisionReviewTask.name }
expect(review_tasks.count).to eq 3
review_tasks.each do |review_task|
judge_review_task = JudgeDecisionReviewTask.find(review_task["id"])
expect(review_task["attributes"]["assigned_to"]["id"]).to eq judge.id
expect(judge_review_task.children.first.type).to eq AttorneyTask.name
expect(judge_review_task.reload.status).to eq Constants.TASK_STATUSES.on_hold
before do
SpecialCaseMovementTeam.singleton.add_user(user)
FeatureToggle.enable!(:scm_view_judge_assign_queue)
end
after { FeatureToggle.disable!(:scm_view_judge_assign_queue) }

assign_tasks = response_body.select { |task| task["attributes"]["type"].eql? JudgeAssignTask.name }
expect(assign_tasks.count).to eq 3
expect(assign_tasks.all? do |assign_task|
assign_task["attributes"]["status"].eql? Constants.TASK_STATUSES.completed
end).to eq true
it_behaves_like "attorney task assignment"
end
end

Expand Down
5 changes: 4 additions & 1 deletion spec/controllers/post_decision_motions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@

body = JSON.parse(response.body)
expect(body["errors"]).to match_array(
[{ "detail" => "Assigned by has to be a judge, Assigned to has to be an attorney" }]
[{
"detail" =>
"Assigned by has to be a judge or special case movement team member, Assigned to has to be an attorney"
}]
)
end
end
Expand Down
Loading

0 comments on commit a167f15

Please sign in to comment.