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

Sync decided appeals with states table #22434

Merged
merged 5 commits into from
Aug 9, 2024
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
30 changes: 30 additions & 0 deletions app/jobs/nightly_syncs_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def perform
sync_vacols_users
sync_decision_review_tasks
sync_bgs_attorneys
sync_decided_appeals

slack_service.send_notification(@slack_report.join("\n"), self.class.name) if @slack_report.any?
end
Expand Down Expand Up @@ -84,6 +85,33 @@ def sync_bgs_attorneys
@slack_report << "*Fatal error in sync_bgs_attorneys:* #{error}"
msteele96 marked this conversation as resolved.
Show resolved Hide resolved
end

# Syncs the decision_mailed status of Legacy Appeals with a decision made
def sync_decided_appeals
AppealState.legacy.where(decision_mailed: false).each do |appeal_state|
# If there is a decision date on the VACOLS record,
# update the decision_mailed status on the AppealState to true
if get_decision_date(appeal_state.appeal_id).present?
appeal_state.decision_mailed_appeal_state_update_action!
end
end
rescue StandardError => error
@slack_report << "*Fatal error in sync_decided_appeals* #{error}"
end

def get_decision_date(appeals_id)
begin
legacy_appeal = LegacyAppeal.find(appeals_id)

# Find the VACOLS record associated with the LegacyAppeal
vacols_record = VACOLS::Case.find_by_bfkey!(legacy_appeal[:vacols_id])

# Return the decision date
vacols_record[:bfddec]
rescue ActiveRecord::RecordNotFound
nil
end
end

def dangling_legacy_appeals
reporter = LegacyAppealsWithNoVacolsCase.new
reporter.call
Expand All @@ -105,5 +133,7 @@ def sync_hearing_states
state.scheduled_in_error_appeal_state_update_action!
end
end
rescue StandardError => error
ThorntonMatthew marked this conversation as resolved.
Show resolved Hide resolved
@slack_report << "*Fatal error in sync_hearing_states* #{error}"
end
end
70 changes: 70 additions & 0 deletions spec/jobs/nightly_syncs_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,23 @@ class FakeTask < Dispatch::Task
expect(held_hearing_appeal_state.reload.hearing_scheduled).to eq false
end

it "catches standard errors" do
expect([pending_hearing_appeal_state,
postponed_hearing_appeal_state,
withdrawn_hearing_appeal_state,
scheduled_in_error_hearing_appeal_state,
held_hearing_appeal_state].all?(&:hearing_scheduled)).to eq true

allow(AppealState).to receive(:where).and_raise(StandardError)
slack_msg = ""
slack_msg_error_text = "Fatal error in sync_hearing_states"
allow_any_instance_of(SlackService).to receive(:send_notification) { |_, first_arg| slack_msg = first_arg }

subject

expect(slack_msg.include?(slack_msg_error_text)).to be true
end

# Hearing scheduled will be set to true to simulate Caseflow missing a
# disposition update.
def create_appeal_state_with_case_record_and_hearing(desired_disposition)
Expand All @@ -213,6 +230,59 @@ def create_appeal_state_with_case_record_and_hearing(desired_disposition)
end
end

context "#sync_decided_appeals" do
let(:decided_appeal_state) do
create_decided_appeal_state_with_case_record_and_hearing(true, true)
end

let(:undecided_appeal_state) do
create_decided_appeal_state_with_case_record_and_hearing(false, true)
end

let(:missing_vacols_case_appeal_state) do
create_decided_appeal_state_with_case_record_and_hearing(true, false)
end

it "Job syncs decided appeals decision_mailed status" do
expect([decided_appeal_state,
undecided_appeal_state,
missing_vacols_case_appeal_state].all?(&:decision_mailed)).to eq false

subject

expect(decided_appeal_state.reload.decision_mailed).to eq true
expect(undecided_appeal_state.reload.decision_mailed).to eq false
expect(missing_vacols_case_appeal_state.reload.decision_mailed).to eq false
end

it "catches standard errors" do
expect([decided_appeal_state,
undecided_appeal_state,
missing_vacols_case_appeal_state].all?(&:decision_mailed)).to eq false

allow(AppealState).to receive(:legacy).and_raise(StandardError)
slack_msg = ""
slack_msg_error_text = "Fatal error in sync_decided_appeals"
allow_any_instance_of(SlackService).to receive(:send_notification) { |_, first_arg| slack_msg = first_arg }

subject

expect(slack_msg.include?(slack_msg_error_text)).to be true
end

# VACOLS record's decision date will be set to simulate a decided appeal
# decision_mailed will be set to false for the AppealState to verify the method
# functionality
def create_decided_appeal_state_with_case_record_and_hearing(decided_appeal, create_case)
case_hearing = create(:case_hearing)
decision_date = decided_appeal ? Time.current : nil
vacols_case = create_case ? create(:case, case_hearings: [case_hearing], bfddec: decision_date) : nil
appeal = create(:legacy_appeal, vacols_case: vacols_case)

appeal.appeal_state.tap { _1.update!(decision_mailed: false) }
end
end

context "when errors occur" do
context "in the sync_vacols_cases step" do
context "due to existing FK associations" do
Expand Down
Loading