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

APPEALS-57351 Inactive Appeal Errors present when outcoding an appeal #22721

Merged
merged 8 commits into from
Sep 11, 2024
8 changes: 5 additions & 3 deletions app/models/prepend/va_notify/appellant_notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ def status

class NoAppealError < StandardError; end

def self.handle_errors(appeal)
def self.handle_errors(appeal, template_name)
fail NoAppealError if appeal.nil?
fail InactiveAppealError, appeal.external_id if !appeal.active?
if template_name == Constants.EVENT_TYPE_FILTERS.quarterly_notification && !appeal.active?
fail InactiveAppealError, appeal.external_id
end

message_attributes = {}
message_attributes[:appeal_type] = appeal.class.to_s
Expand Down Expand Up @@ -79,7 +81,7 @@ def self.notify_appellant(
end

def self.create_payload(appeal, template_name, appeal_status = nil)
message_attributes = AppellantNotification.handle_errors(appeal)
message_attributes = AppellantNotification.handle_errors(appeal, template_name)
VANotifySendMessageTemplate.new(message_attributes, template_name, appeal_status)
end

Expand Down
32 changes: 32 additions & 0 deletions spec/controllers/idt/api/v2/appeals_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,38 @@
expect(JSON.parse(response.body)["message"]).to eq("Successful dispatch!")
end

context "when notifications are enabled" do
include ActiveJob::TestHelper
let(:contested_issue) { create(:request_issue, :nonrating)}
let(:veteran) { create(:veteran) }
let(:contested_appeal) do
create(
:legacy_appeal,
vacols_case: create(:case, bfcorlid: veteran.file_number),
vbms_id: "#{veteran.file_number}S"
)
end
before do
FeatureToggle.enable!(:va_notify_sms)
FeatureToggle.enable!(:va_notify_email)
Seeds::NotificationEvents.new.seed! unless NotificationEvent.count > 0
end

it "should send the appeal decision mailed non contested claim notification" do
perform_enqueued_jobs { post :outcode, params: params, as: :json }

expect(Notification.last.event_type).to eq("Appeal decision mailed (Non-contested claims)")
end

it "should send the appeal decision mailed contested claim notification" do
appeal = VACOLS::Representative.create!(repkey: contested_appeal.vacols_id, reptype: "C")
ThorntonMatthew marked this conversation as resolved.
Show resolved Hide resolved
params[:appeal_id] = contested_appeal.vacols_id

perform_enqueued_jobs { post :outcode, params: params, as: :json }
expect(Notification.last.event_type).to eq("Appeal decision mailed (Contested claims)")
end
end

context "when dispatch is associated with a mail request" do
include ActiveJob::TestHelper

Expand Down
16 changes: 9 additions & 7 deletions spec/models/appellant_notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
describe AppellantNotification do
describe "class methods" do
describe "self.handle_errors" do
let(:template_name) { "Quarterly Notification" }
let(:appeal) { create(:appeal, :active, number_of_claimants: 1) }
let(:current_user) { User.system_user }
context "if appeal is nil" do
let(:empty_appeal) {}
it "reports the error" do
expect { AppellantNotification.handle_errors(empty_appeal) }.to raise_error(
expect { AppellantNotification.handle_errors(empty_appeal, template_name) }.to raise_error(
AppellantNotification::NoAppealError
)
end
Expand All @@ -17,7 +18,7 @@
context "with no claimant listed" do
let(:appeal) { create(:appeal, :active, number_of_claimants: 0) }
it "returns error message" do
expect(AppellantNotification.handle_errors(appeal)[:status]).to eq(
expect(AppellantNotification.handle_errors(appeal, template_name)[:status]).to eq(
AppellantNotification::NoClaimantError.new(appeal.id).status
)
end
Expand All @@ -30,7 +31,7 @@
appeal.claimants = [claimant]
end
it "returns error message" do
expect(AppellantNotification.handle_errors(appeal)[:status]).to eq(
expect(AppellantNotification.handle_errors(appeal, template_name)[:status]).to eq(
AppellantNotification::NoParticipantIdError.new(appeal.id).status
)
end
Expand All @@ -40,34 +41,35 @@
let(:appeal) { create(:appeal, :active, number_of_claimants: 1) }
it "returns error message" do
appeal.root_task.completed!
expect { AppellantNotification.handle_errors(appeal) }.to raise_error(
expect { AppellantNotification.handle_errors(appeal, template_name) }.to raise_error(
AppellantNotification::InactiveAppealError
)
end
end

context "with no errors" do
it "doesn't raise" do
expect(AppellantNotification.handle_errors(appeal)[:status]).to eq "Success"
expect(AppellantNotification.handle_errors(appeal, template_name)[:status]).to eq "Success"
end
end
end

describe "veteran is deceased" do
let(:appeal) { create(:appeal, :active, number_of_claimants: 1) }
let(:substitute_appellant) { create(:appellant_substitution) }
let(:template_name) { "test" }

it "with no substitute appellant" do
appeal.veteran.update!(date_of_death: Time.zone.today)
expect(AppellantNotification.handle_errors(appeal)[:status]).to eq "Failure Due to Deceased"
expect(AppellantNotification.handle_errors(appeal, template_name)[:status]).to eq "Failure Due to Deceased"
end

it "with substitute appellant" do
appeal.veteran.update!(date_of_death: Time.zone.today)
substitute_appellant.update!(source_appeal_id: appeal.id)
substitute_appellant.send(:establish_substitution_on_same_appeal)
appeal.update!(veteran_is_not_claimant: true)
expect(AppellantNotification.handle_errors(appeal)[:status]).to eq "Success"
expect(AppellantNotification.handle_errors(appeal, template_name)[:status]).to eq "Success"
end
end

Expand Down
Loading