From 4b83439da72b440616fa51d345db16dbc8f9fdea Mon Sep 17 00:00:00 2001 From: Matthew Thornton Date: Sun, 9 Jun 2024 23:53:38 -0400 Subject: [PATCH 1/4] Add conditional for FOIA and Privacy Act mail task to receives 'Privacy Act Pending' notifications --- .../prepend/va_notify/privacy_act_pending.rb | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/app/models/prepend/va_notify/privacy_act_pending.rb b/app/models/prepend/va_notify/privacy_act_pending.rb index 23835c7504c..db851a62b82 100644 --- a/app/models/prepend/va_notify/privacy_act_pending.rb +++ b/app/models/prepend/va_notify/privacy_act_pending.rb @@ -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) AppellantNotification.notify_appellant(parent.appeal, Constants.EVENT_TYPE_FILTERS.privacy_act_request_pending) end @@ -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) + params[:type] == "HearingAdminActionFoiaPrivacyRequestTask" && parent.type == "ScheduleHearingTask" + end end From b0f87069a7de212a2b5795e98ad5e7e5c14a9972 Mon Sep 17 00:00:00 2001 From: Matthew Thornton Date: Mon, 10 Jun 2024 00:10:27 -0400 Subject: [PATCH 2/4] Update spec --- spec/models/appellant_notification_spec.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spec/models/appellant_notification_spec.rb b/spec/models/appellant_notification_spec.rb index 013460469a3..74d9623f49d 100644 --- a/spec/models/appellant_notification_spec.rb +++ b/spec/models/appellant_notification_spec.rb @@ -589,16 +589,17 @@ let(:task_params) do { type: "PrivacyActRequestMailTask", - instructions: "fjdkfjwpie" + instructions: "fjdkfjwpie", + parent_id: appeal.root_task.id } 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) + 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!) - mail_task.create_twin_of_type(task_params) + PrivacyActRequestMailTask.create_from_params(task_params, current_user) end it "sends a notification when PrivacyActRequestMailTask is completed" do expect(AppellantNotification).to receive(:notify_appellant).with(appeal, template_closed) From 0e2db5b70efa67269a2ca9bed1689d76d7c5f1ce Mon Sep 17 00:00:00 2001 From: Matthew Thornton Date: Mon, 10 Jun 2024 00:47:20 -0400 Subject: [PATCH 3/4] Adjust some specs --- spec/models/appellant_notification_spec.rb | 43 +++++++++++++++------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/spec/models/appellant_notification_spec.rb b/spec/models/appellant_notification_spec.rb index 74d9623f49d..a0438ec0ced 100644 --- a/spec/models/appellant_notification_spec.rb +++ b/spec/models/appellant_notification_spec.rb @@ -585,22 +585,37 @@ before do priv_org.add_user(current_user) end + context "PrivacyActRequestMailTask" do - let(:task_params) do - { - type: "PrivacyActRequestMailTask", - instructions: "fjdkfjwpie", - parent_id: appeal.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) + 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") From 5afa907d732290c93f50c1f9641ddabe374c79a9 Mon Sep 17 00:00:00 2001 From: Matthew Thornton Date: Mon, 10 Jun 2024 01:22:02 -0400 Subject: [PATCH 4/4] Add missing param --- app/models/prepend/va_notify/privacy_act_pending.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/prepend/va_notify/privacy_act_pending.rb b/app/models/prepend/va_notify/privacy_act_pending.rb index db851a62b82..81e95cdf55f 100644 --- a/app/models/prepend/va_notify/privacy_act_pending.rb +++ b/app/models/prepend/va_notify/privacy_act_pending.rb @@ -21,7 +21,7 @@ def create_child_task(parent, current_user, params) super_return_value = super if organization_assigned_privacy_task?(params) || privacy_act_mail_task?(params) || - valid_hearing_admin_foia_privacy_request?(params) + valid_hearing_admin_foia_privacy_request?(params, parent) AppellantNotification.notify_appellant(parent.appeal, Constants.EVENT_TYPE_FILTERS.privacy_act_request_pending) end @@ -44,7 +44,7 @@ def organization_assigned_privacy_task?(params) params[:type] == "PrivacyActTask" && params[:assigned_to_type].include?("Organization") end - def valid_hearing_admin_foia_privacy_request?(params) + def valid_hearing_admin_foia_privacy_request?(params, parent) params[:type] == "HearingAdminActionFoiaPrivacyRequestTask" && parent.type == "ScheduleHearingTask" end end