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

msteele96/APPEALS-25001 #19088

Merged
merged 11 commits into from
Aug 7, 2023
6 changes: 6 additions & 0 deletions app/models/tasks/mail_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ class MailTask < Task
def verify_org_task_unique; end
prepend PrivacyActPending

# This constant is more efficient than iterating through all mail tasks
# and filtering out almost all of them since only HPR and HWR are approved for now
LEGACY_MAIL_TASKS = [
{ label: "Hearing postponement request", value: "HearingPostponementRequestMailTask" }
].freeze

class << self
def blocking?
# Some open mail tasks should block distribution of an appeal to judges.
Expand Down
3 changes: 2 additions & 1 deletion app/models/tasks/root_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ def hide_from_task_snapshot
true
end

# :reek:UtilityFunction
def available_actions(user)
msteele96 marked this conversation as resolved.
Show resolved Hide resolved
return [Constants.TASK_ACTIONS.CREATE_MAIL_TASK.to_h] if RootTask.user_can_create_mail_task?(user) && ama?
return [Constants.TASK_ACTIONS.CREATE_MAIL_TASK.to_h] if RootTask.user_can_create_mail_task?(user)

[]
end
Expand Down
9 changes: 7 additions & 2 deletions app/repositories/task_action_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ def assign_to_organization_data(task, _user = nil)
end

def mail_assign_to_organization_data(task, user = nil)
options = MailTask.descendant_routing_options(user: user, appeal: task.appeal)
valid_options = task.appeal.outcoded? ? options : options.reject { |opt| opt[:value] == "VacateMotionMailTask" }
if task.appeal.is_a? Appeal
options = MailTask.descendant_routing_options(user: user, appeal: task.appeal)
valid_options = task.appeal.outcoded? ? options : options.reject { |opt| opt[:value] == "VacateMotionMailTask" }
elsif task.appeal.is_a? LegacyAppeal
valid_options = MailTask::LEGACY_MAIL_TASKS
end

{ options: valid_options }
end

Expand Down
8 changes: 8 additions & 0 deletions spec/models/tasks/root_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
expect(subject).to eq([])
end
end

context "when the appeal is a legacy appeal" do
it "mail team members still have the option to add mail tasks" do
allow(user).to receive(:organizations).and_return([MailTeam.singleton])

expect(subject).to eq([root_task.build_action_hash(Constants.TASK_ACTIONS.CREATE_MAIL_TASK.to_h, user)])
end
end
end

describe ".update_children_status_after_closed" do
Expand Down
30 changes: 30 additions & 0 deletions spec/repositories/task_action_repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,36 @@
end
end

describe "#mail_assign_to_organization_data" do
context "outcoded Appeal" do
let(:appeal) { create(:appeal, :outcoded) }
subject { TaskActionRepository.mail_assign_to_organization_data(appeal.root_task) }

it "returns all of the options when outcoded" do
expect(subject[:options]).to eq(MailTask.descendant_routing_options)
end
end

context "active Appeal" do
let(:appeal) { create(:appeal, :active) }
subject { TaskActionRepository.mail_assign_to_organization_data(appeal.root_task) }

it "returns all of the options except VacateMotionMailTask when not outcoded" do
expect(subject[:options]).to eq(MailTask.descendant_routing_options.reject do |opt|
opt[:value] == "VacateMotionMailTask"
end)
end
end

context "LegacyAppeal" do
let(:appeal) { create(:legacy_appeal, :with_root_task) }
subject { TaskActionRepository.mail_assign_to_organization_data(appeal.root_task) }
it "returns only the HPR and HWR options" do
expect(subject[:options]).to eq(MailTask::LEGACY_MAIL_TASKS)
end
end
end

describe "#vha caregiver support task actions" do
describe "#vha_caregiver_support_return_to_board_intake" do
let(:user) { create(:user) }
Expand Down
Loading