-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SpecHelper to create S3 logs Created StuckJobReportService SC DTA Appeal Fix deleted old unused file
- Loading branch information
Showing
2 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
class ScDtaForAppealFixJob < CaseflowJob | ||
ERRORTEXT = "Can't create a SC DTA for appeal" | ||
|
||
def records_with_errors | ||
DecisionDocument.where("error ILIKE ?", "%#{ERRORTEXT}%") | ||
end | ||
|
||
def sc_dta_for_appeal_fix | ||
stuck_job_report_service = StuckJobReportService.new | ||
return if records_with_errors.blank? | ||
|
||
# count of records with errors before fix | ||
stuck_job_report_service.append_record_count(records_with_errors.count, ERRORTEXT) | ||
|
||
records_with_errors.each do |decision_doc| | ||
claimant = decision_doc.appeal.claimant | ||
|
||
return unless claimant.payee_code.nil? | ||
|
||
if claimant.type == "VeteranClaimant" | ||
claimant.update!(payee_code: "00") | ||
elsif claimant.type == "DependentClaimant" | ||
claimant.update!(payee_code: "10") | ||
end | ||
stuck_job_report_service.append_single_record(decision_doc.class.name, decision_doc.id) | ||
clear_error_on_record(decision_doc) | ||
end | ||
|
||
# record count with errors after fix | ||
stuck_job_report_service.append_record_count(records_with_errors.count, ERRORTEXT) | ||
stuck_job_report_service.write_log_report(ERRORTEXT) | ||
end | ||
|
||
def clear_error_on_record(decision_doc) | ||
ActiveRecord::Base.transaction do | ||
decision_doc.clear_error! | ||
rescue StandardError => error | ||
log_error(error) | ||
stuck_job_report_service.append_errors(decision_doc.class.name, decision_doc.id, error) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# frozen_string_literal: true | ||
|
||
describe ScDtaForAppealFixJob, :postgres do | ||
let(:sc_dta_for_appeal_error) { "Can't create a SC DTA for appeal" } | ||
let!(:veteran_file_number) { "111223333" } | ||
let!(:veteran_file_number_2) { "999999999" } | ||
|
||
# let!(:veteran) { create(:veteran, file_number: veteran_file_number) } | ||
let(:appeal) { create(:appeal, veteran_file_number: veteran_file_number) } | ||
let(:appeal_2) { create(:appeal, veteran_file_number: veteran_file_number_2) } | ||
let!(:decision_doc_with_error) do | ||
create( | ||
:decision_document, | ||
error: sc_dta_for_appeal_error, | ||
appeal: appeal | ||
) | ||
end | ||
|
||
let!(:decision_doc_with_error_2) do | ||
create( | ||
:decision_document, | ||
error: sc_dta_for_appeal_error, | ||
appeal: appeal_2 | ||
) | ||
end | ||
|
||
before do | ||
create_list(:decision_document, 5) | ||
end | ||
|
||
subject { described_class.new } | ||
|
||
context "#sc_dta_for_appeal_fix" do | ||
context "when payee_code is nil" do | ||
before do | ||
decision_doc_with_error.appeal.claimant.update(payee_code: nil) | ||
end | ||
# we need to manipulate the claimant.type for these describes | ||
describe "claimant.type is VeteranClaimant" do | ||
it "updates payee_code to 00" do | ||
decision_doc_with_error_2.appeal.claimant.update(payee_code: nil) | ||
|
||
subject.sc_dta_for_appeal_fix | ||
expect(decision_doc_with_error.appeal.claimant.payee_code).to eq("00") | ||
expect(decision_doc_with_error_2.appeal.claimant.payee_code).to eq("00") | ||
end | ||
|
||
it "clears error column" do | ||
subject.sc_dta_for_appeal_fix | ||
expect(decision_doc_with_error.reload.error).to be_nil | ||
end | ||
end | ||
|
||
describe "claimant.type is DependentClaimant" do | ||
it "updates payee_code to 10" do | ||
decision_doc_with_error.appeal.claimant.update(type: "DependentClaimant") | ||
subject.sc_dta_for_appeal_fix | ||
expect(decision_doc_with_error.appeal.claimant.payee_code).to eq("10") | ||
end | ||
|
||
it "clears error column" do | ||
decision_doc_with_error.appeal.claimant.update(type: "DependentClaimant") | ||
subject.sc_dta_for_appeal_fix | ||
expect(decision_doc_with_error.reload.error).to be_nil | ||
end | ||
end | ||
end | ||
|
||
context "when payee_code is populated" do | ||
it "does not update payee_code" do | ||
expect(decision_doc_with_error.appeal.claimant.payee_code).to eq("00") | ||
subject.sc_dta_for_appeal_fix | ||
expect(decision_doc_with_error.appeal.claimant.payee_code).to eq("00") | ||
end | ||
it "does not clear error field" do | ||
subject.sc_dta_for_appeal_fix | ||
expect(decision_doc_with_error.error).to eq(sc_dta_for_appeal_error) | ||
end | ||
end | ||
end | ||
end |