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

Reenable-privacy-mail-notifications #21859

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 17 additions & 12 deletions app/models/prepend/va_notify/privacy_act_pending.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,13 @@ def create_privacy_act_task
super_return_value
end

# for foia/privacy act mail tasks
# original method defined in app/models/mail_task.rb
def create_twin_of_type(params)
super_return_value = super
if params[:type] == "PrivacyActRequestMailTask" || params[:type] == "FoiaRequestMailTask"
AppellantNotification.notify_appellant(appeal, Constants.EVENT_TYPE_FILTERS.privacy_act_request_pending)
end
super_return_value
end

# for HearingAdminFoiaPrivacyRequestTask/PrivacyActTask
# original method defined in app/models/task.rb
def create_child_task(parent, current_user, params)
super_return_value = super
if (params[:type] == "PrivacyActTask" && params[:assigned_to_type].include?("Organization")) ||
(params[:type] == "HearingAdminActionFoiaPrivacyRequestTask" && parent.type == "ScheduleHearingTask")
if organization_assigned_privacy_task?(params) ||
privacy_act_mail_task?(params) ||
valid_hearing_admin_foia_privacy_request?(params, parent)
AppellantNotification.notify_appellant(parent.appeal,
Constants.EVENT_TYPE_FILTERS.privacy_act_request_pending)
end
Expand All @@ -42,4 +33,18 @@ def update_appeal_state_when_privacy_act_created
appeal.appeal_state.privacy_act_pending_appeal_state_update_action!
end
end

private

def privacy_act_mail_task?(params)
params[:type] == "PrivacyActRequestMailTask" || params[:type] == "FoiaRequestMailTask"
end

def organization_assigned_privacy_task?(params)
params[:type] == "PrivacyActTask" && params[:assigned_to_type].include?("Organization")
end

def valid_hearing_admin_foia_privacy_request?(params, parent)
params[:type] == "HearingAdminActionFoiaPrivacyRequestTask" && parent.type == "ScheduleHearingTask"
end
end
42 changes: 29 additions & 13 deletions spec/models/appellant_notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -585,21 +585,37 @@
before do
priv_org.add_user(current_user)
end

context "PrivacyActRequestMailTask" do
let(:task_params) do
{
type: "PrivacyActRequestMailTask",
instructions: "fjdkfjwpie"
}
end
it "sends a notification when PrivacyActRequestMailTask is created" do
expect(AppellantNotification).to receive(:notify_appellant).with(appeal, template_pending)
mail_task.create_twin_of_type(task_params)
end
it "updates appeal state when PrivacyActRequestMailTask is created" do
expect_any_instance_of(AppealState).to receive(:privacy_act_pending_appeal_state_update_action!)
mail_task.create_twin_of_type(task_params)
context "being created" do
let(:appeal) { create(:appeal) }
let(:root_task) { RootTask.create!(appeal: appeal) }
let!(:distribution_task) { DistributionTask.create!(appeal: appeal, parent: root_task) }
let(:current_user) do
create(:user).tap do |user|
MailTeam.singleton.add_user(user)
end
end

let(:task_params) do
{
type: "PrivacyActRequestMailTask",
instructions: "fjdkfjwpie",
parent_id: root_task.id
}
end

it "sends a notification when PrivacyActRequestMailTask is created" do
expect(AppellantNotification).to receive(:notify_appellant).with(appeal, template_pending)
PrivacyActRequestMailTask.create_from_params(task_params, current_user)
end

it "updates appeal state when PrivacyActRequestMailTask is created" do
expect_any_instance_of(AppealState).to receive(:privacy_act_pending_appeal_state_update_action!)
PrivacyActRequestMailTask.create_from_params(task_params, current_user)
end
end

it "sends a notification when PrivacyActRequestMailTask is completed" do
expect(AppellantNotification).to receive(:notify_appellant).with(appeal, template_closed)
foia_child.update!(status: "completed")
Expand Down
Loading