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
6 changes: 3 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,9 @@ 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?
fail InactiveAppealError, appeal.external_id if template_name == "Quarterly Notification" && !appeal.active?
msteele96 marked this conversation as resolved.
Show resolved Hide resolved

message_attributes = {}
message_attributes[:appeal_type] = appeal.class.to_s
Expand Down Expand Up @@ -79,7 +79,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
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