Skip to content

Commit

Permalink
WIP more test consolidation
Browse files Browse the repository at this point in the history
- needs fix to decision review service to make method signatures match
  • Loading branch information
kayline committed Nov 15, 2024
1 parent 0efc368 commit 5faec8e
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 185 deletions.
103 changes: 1 addition & 102 deletions spec/sidekiq/decision_review/nod_status_updater_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,115 +9,14 @@

include_context 'status updater job context', SavedClaim::NoticeOfDisagreement

let(:upload_response_vbms) do
response = JSON.parse(File.read('spec/fixtures/notice_of_disagreements/NOD_upload_show_response_200.json'))
instance_double(Faraday::Response, body: response)
end

let(:upload_response_processing) do
response = JSON.parse(File.read('spec/fixtures/notice_of_disagreements/NOD_upload_show_response_200.json'))
response['data']['attributes']['status'] = 'processing'
instance_double(Faraday::Response, body: response)
end

let(:upload_response_error) do
response = JSON.parse(File.read('spec/fixtures/supplemental_claims/SC_upload_show_response_200.json'))
response['data']['attributes']['status'] = 'error'
response['data']['attributes']['detail'] = 'Invalid PDF'
instance_double(Faraday::Response, body: response)
end

describe 'perform' do
context 'with flag enabled', :aggregate_failures do
before do
Flipper.enable :decision_review_saved_claim_nod_status_updater_job_enabled
end

include_examples 'status updater job with base forms', SavedClaim::NoticeOfDisagreement

context 'SavedClaim records are present with completed status in LH and have associated evidence uploads' do
let(:upload_id) { SecureRandom.uuid }
let(:upload_id2) { SecureRandom.uuid }
let(:upload_id3) { SecureRandom.uuid }
let(:upload_id4) { SecureRandom.uuid }

before do
allow(Rails.logger).to receive(:info)

SavedClaim::NoticeOfDisagreement.create(guid: guid1, form: '{}')
SavedClaim::NoticeOfDisagreement.create(guid: guid2, form: '{}')
SavedClaim::NoticeOfDisagreement.create(guid: guid3, form: '{}')

appeal_submission = create(:appeal_submission, submitted_appeal_uuid: guid1)
create(:appeal_submission_upload, appeal_submission:, lighthouse_upload_id: upload_id)

appeal_submission2 = create(:appeal_submission, submitted_appeal_uuid: guid2)
create(:appeal_submission_upload, appeal_submission: appeal_submission2, lighthouse_upload_id: upload_id2)

# One upload vbms, other one still processing
appeal_submission3 = create(:appeal_submission, submitted_appeal_uuid: guid3)
create(:appeal_submission_upload, appeal_submission: appeal_submission3, lighthouse_upload_id: upload_id3)
create(:appeal_submission_upload, appeal_submission: appeal_submission3, lighthouse_upload_id: upload_id4)
end

it 'only sets delete_date for SavedClaim::NoticeOfDisagreement with all attachments in vbms status' do
expect(service).to receive(:get_notice_of_disagreement_upload).with(guid: upload_id)
.and_return(upload_response_vbms)
expect(service).to receive(:get_notice_of_disagreement_upload).with(guid: upload_id2)
.and_return(upload_response_processing)
expect(service).to receive(:get_notice_of_disagreement_upload).with(guid: upload_id3)
.and_return(upload_response_vbms)
expect(service).to receive(:get_notice_of_disagreement_upload).with(guid: upload_id4)
.and_return(upload_response_processing)

expect(service).to receive(:get_notice_of_disagreement).with(guid1).and_return(response_complete)
expect(service).to receive(:get_notice_of_disagreement).with(guid2).and_return(response_complete)
expect(service).to receive(:get_notice_of_disagreement).with(guid3).and_return(response_complete)

frozen_time = DateTime.new(2024, 1, 1).utc

Timecop.freeze(frozen_time) do
subject.new.perform

claim1 = SavedClaim::NoticeOfDisagreement.find_by(guid: guid1)
expect(claim1.delete_date).to eq frozen_time + 59.days
expect(claim1.metadata_updated_at).to eq frozen_time
expect(claim1.metadata).to include 'complete'
expect(claim1.metadata).to include 'vbms'

claim2 = SavedClaim::NoticeOfDisagreement.find_by(guid: guid2)
expect(claim2.delete_date).to be_nil
expect(claim2.metadata_updated_at).to eq frozen_time
expect(claim2.metadata).to include 'complete'
expect(claim2.metadata).to include 'processing'

claim3 = SavedClaim::NoticeOfDisagreement.find_by(guid: guid3)
expect(claim3.delete_date).to be_nil
expect(claim3.metadata_updated_at).to eq frozen_time

metadata3 = JSON.parse(claim3.metadata)
expect(metadata3['status']).to eq 'complete'
expect(metadata3['uploads'].pluck('id', 'status'))
.to contain_exactly([upload_id3, 'vbms'], [upload_id4, 'processing'])
end

expect(StatsD).to have_received(:increment)
.with('worker.decision_review.saved_claim_nod_status_updater.processing_records', 3).exactly(1).time
expect(StatsD).to have_received(:increment)
.with('worker.decision_review.saved_claim_nod_status_updater.delete_date_update').exactly(1).time
expect(StatsD).to have_received(:increment)
.with('worker.decision_review.saved_claim_nod_status_updater.status', tags: ['status:complete'])
.exactly(2).times
expect(StatsD).to have_received(:increment)
.with('worker.decision_review.saved_claim_nod_status_updater_upload.status', tags: ['status:vbms'])
.exactly(2).times
expect(StatsD).to have_received(:increment)
.with('worker.decision_review.saved_claim_nod_status_updater_upload.status', tags: ['status:processing'])
.exactly(2).times
expect(Rails.logger).not_to have_received(:info)
.with('DecisionReview::SavedClaimNodStatusUpdaterJob evidence status error', anything)
end
end
include_examples 'status updater job when forms include evidence', SavedClaim::NoticeOfDisagreement
end

context 'with flag disabled' do
Expand Down
84 changes: 1 addition & 83 deletions spec/sidekiq/decision_review/sc_status_updater_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,89 +34,7 @@
end

include_examples 'status updater job with base forms', SavedClaim::SupplementalClaim

context 'SavedClaim records are present with completed status in LH and have associated evidence uploads' do
let(:upload_id) { SecureRandom.uuid }
let(:upload_id2) { SecureRandom.uuid }
let(:upload_id3) { SecureRandom.uuid }
let(:upload_id4) { SecureRandom.uuid }

before do
allow(Rails.logger).to receive(:info)
SavedClaim::SupplementalClaim.create(guid: guid1, form: '{}')
SavedClaim::SupplementalClaim.create(guid: guid2, form: '{}')
SavedClaim::SupplementalClaim.create(guid: guid3, form: '{}')

appeal_submission = create(:appeal_submission, submitted_appeal_uuid: guid1)
create(:appeal_submission_upload, appeal_submission:, lighthouse_upload_id: upload_id)

appeal_submission2 = create(:appeal_submission, submitted_appeal_uuid: guid2)
create(:appeal_submission_upload, appeal_submission: appeal_submission2, lighthouse_upload_id: upload_id2)

# One upload vbms, other one still processing
appeal_submission3 = create(:appeal_submission, submitted_appeal_uuid: guid3)
create(:appeal_submission_upload, appeal_submission: appeal_submission3, lighthouse_upload_id: upload_id3)
create(:appeal_submission_upload, appeal_submission: appeal_submission3, lighthouse_upload_id: upload_id4)
end

it 'only sets delete_date for SavedClaim::SupplementalClaim with all attachments in vbms status' do
expect(service).to receive(:get_supplemental_claim_upload).with(uuid: upload_id)
.and_return(upload_response_vbms)
expect(service).to receive(:get_supplemental_claim_upload).with(uuid: upload_id2)
.and_return(upload_response_processing)
expect(service).to receive(:get_supplemental_claim_upload).with(uuid: upload_id3)
.and_return(upload_response_vbms)
expect(service).to receive(:get_supplemental_claim_upload).with(uuid: upload_id4)
.and_return(upload_response_processing)

expect(service).to receive(:get_supplemental_claim).with(guid1).and_return(response_complete)
expect(service).to receive(:get_supplemental_claim).with(guid2).and_return(response_complete)
expect(service).to receive(:get_supplemental_claim).with(guid3).and_return(response_complete)

frozen_time = DateTime.new(2024, 1, 1).utc

Timecop.freeze(frozen_time) do
subject.new.perform

claim1 = SavedClaim::SupplementalClaim.find_by(guid: guid1)
expect(claim1.delete_date).to eq frozen_time + 59.days
expect(claim1.metadata_updated_at).to eq frozen_time
expect(claim1.metadata).to include 'complete'
expect(claim1.metadata).to include 'vbms'

claim2 = SavedClaim::SupplementalClaim.find_by(guid: guid2)
expect(claim2.delete_date).to be_nil
expect(claim2.metadata_updated_at).to eq frozen_time
expect(claim2.metadata).to include 'complete'
expect(claim2.metadata).to include 'processing'

claim3 = SavedClaim::SupplementalClaim.find_by(guid: guid3)
expect(claim3.delete_date).to be_nil
expect(claim3.metadata_updated_at).to eq frozen_time

metadata3 = JSON.parse(claim3.metadata)
expect(metadata3['status']).to eq 'complete'
expect(metadata3['uploads'].pluck('id', 'status'))
.to contain_exactly([upload_id3, 'vbms'], [upload_id4, 'processing'])
end

expect(StatsD).to have_received(:increment)
.with('worker.decision_review.saved_claim_sc_status_updater.processing_records', 3).exactly(1).time
expect(StatsD).to have_received(:increment)
.with('worker.decision_review.saved_claim_sc_status_updater.delete_date_update').exactly(1).time
expect(StatsD).to have_received(:increment)
.with('worker.decision_review.saved_claim_sc_status_updater.status', tags: ['status:complete'])
.exactly(2).times
expect(StatsD).to have_received(:increment)
.with('worker.decision_review.saved_claim_sc_status_updater_upload.status', tags: ['status:vbms'])
.exactly(2).times
expect(StatsD).to have_received(:increment)
.with('worker.decision_review.saved_claim_sc_status_updater_upload.status', tags: ['status:processing'])
.exactly(2).times
expect(Rails.logger).not_to have_received(:info)
.with('DecisionReview::SavedClaimScStatusUpdaterJob evidence status error', anything)
end
end
include_examples 'status updater job when forms include evidence', SavedClaim::SupplementalClaim

context 'SavedClaim records are present with completed status in LH and have associated secondary forms' do
let(:benefits_intake_service) { instance_double(BenefitsIntake::Service) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@

SUBCLASS_INFO = {
SavedClaim::SupplementalClaim => { service_method: 'get_supplemental_claim',
evidence_service_method: 'get_supplemental_claim_upload',
statsd_prefix: 'worker.decision_review.saved_claim_sc_status_updater',
log_prefix: 'DecisionReview::SavedClaimScStatusUpdaterJob',
service_tag: 'service:supplemental-claims' },
SavedClaim::HigherLevelReview => { service_method: 'get_higher_level_review',
evidence_service_method: nil,
statsd_prefix: 'worker.decision_review.saved_claim_hlr_status_updater',
log_prefix: 'DecisionReview::SavedClaimHlrStatusUpdaterJob',
service_tag: 'service:higher-level-review' },
SavedClaim::NoticeOfDisagreement => { service_method: 'get_notice_of_disagreement',
evidence_service_method: 'get_notice_of_disagreement_upload',
statsd_prefix: 'worker.decision_review.saved_claim_nod_status_updater',
log_prefix: 'DecisionReview::SavedClaimNodStatusUpdaterJob',
service_tag: 'service:board-appeal' }
Expand Down Expand Up @@ -182,3 +185,109 @@
end
end
end

RSpec.shared_examples 'status updater job when forms include evidence' do |subclass|
let(:upload_response_vbms) do
response = JSON.parse(File.read('spec/fixtures/supplemental_claims/SC_upload_show_response_200.json'))
instance_double(Faraday::Response, body: response)
end

let(:upload_response_processing) do
response = JSON.parse(File.read('spec/fixtures/supplemental_claims/SC_upload_show_response_200.json'))
response['data']['attributes']['status'] = 'processing'
instance_double(Faraday::Response, body: response)
end

let(:upload_response_error) do
response = JSON.parse(File.read('spec/fixtures/supplemental_claims/SC_upload_show_response_200.json'))
response['data']['attributes']['status'] = 'error'
response['data']['attributes']['detail'] = 'Invalid PDF'
instance_double(Faraday::Response, body: response)
end

let(:evidence_service_method) { SUBCLASS_INFO[subclass][:evidence_service_method].to_sym}

Check failure on line 208 in spec/sidekiq/decision_review/shared_examples_for_status_updater_jobs.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/SpaceInsideBlockBraces: Space missing inside }.

context 'SavedClaim records are present with completed status in LH and have associated evidence uploads' do
let(:upload_id) { SecureRandom.uuid }
let(:upload_id2) { SecureRandom.uuid }
let(:upload_id3) { SecureRandom.uuid }
let(:upload_id4) { SecureRandom.uuid }

before do
allow(Rails.logger).to receive(:info)

subclass.create(guid: guid1, form: '{}')
subclass.create(guid: guid2, form: '{}')
subclass.create(guid: guid3, form: '{}')

appeal_submission = create(:appeal_submission, submitted_appeal_uuid: guid1)
create(:appeal_submission_upload, appeal_submission:, lighthouse_upload_id: upload_id)

appeal_submission2 = create(:appeal_submission, submitted_appeal_uuid: guid2)
create(:appeal_submission_upload, appeal_submission: appeal_submission2, lighthouse_upload_id: upload_id2)

# One upload vbms, other one still processing
appeal_submission3 = create(:appeal_submission, submitted_appeal_uuid: guid3)
create(:appeal_submission_upload, appeal_submission: appeal_submission3, lighthouse_upload_id: upload_id3)
create(:appeal_submission_upload, appeal_submission: appeal_submission3, lighthouse_upload_id: upload_id4)
end

it 'only sets delete_date for subclass with all attachments in vbms status' do
expect(service).to receive(evidence_service_method).with(guid: upload_id)
.and_return(upload_response_vbms)

Check failure on line 237 in spec/sidekiq/decision_review/shared_examples_for_status_updater_jobs.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/MultilineMethodCallIndentation: Align `.and_return` with `.with` on line 236.
expect(service).to receive(evidence_service_method).with(guid: upload_id2)
.and_return(upload_response_processing)

Check failure on line 239 in spec/sidekiq/decision_review/shared_examples_for_status_updater_jobs.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/MultilineMethodCallIndentation: Align `.and_return` with `.with` on line 238.
expect(service).to receive(evidence_service_method).with(guid: upload_id3)
.and_return(upload_response_vbms)

Check failure on line 241 in spec/sidekiq/decision_review/shared_examples_for_status_updater_jobs.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/MultilineMethodCallIndentation: Align `.and_return` with `.with` on line 240.
expect(service).to receive(evidence_service_method).with(guid: upload_id4)
.and_return(upload_response_processing)

Check failure on line 243 in spec/sidekiq/decision_review/shared_examples_for_status_updater_jobs.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/MultilineMethodCallIndentation: Align `.and_return` with `.with` on line 242.

expect(service).to receive(service_method).with(guid1).and_return(response_complete)
expect(service).to receive(service_method).with(guid2).and_return(response_complete)
expect(service).to receive(service_method).with(guid3).and_return(response_complete)

frozen_time = DateTime.new(2024, 1, 1).utc

Timecop.freeze(frozen_time) do
subject.new.perform

claim1 = subclass.find_by(guid: guid1)
expect(claim1.delete_date).to eq frozen_time + 59.days
expect(claim1.metadata_updated_at).to eq frozen_time
expect(claim1.metadata).to include 'complete'
expect(claim1.metadata).to include 'vbms'

claim2 = subclass.find_by(guid: guid2)
expect(claim2.delete_date).to be_nil
expect(claim2.metadata_updated_at).to eq frozen_time
expect(claim2.metadata).to include 'complete'
expect(claim2.metadata).to include 'processing'

claim3 = subclass.find_by(guid: guid3)
expect(claim3.delete_date).to be_nil
expect(claim3.metadata_updated_at).to eq frozen_time

metadata3 = JSON.parse(claim3.metadata)
expect(metadata3['status']).to eq 'complete'
expect(metadata3['uploads'].pluck('id', 'status'))
.to contain_exactly([upload_id3, 'vbms'], [upload_id4, 'processing'])
end

expect(StatsD).to have_received(:increment)
.with("#{statsd_prefix}.processing_records", 3).exactly(1).time
expect(StatsD).to have_received(:increment)
.with("#{statsd_prefix}.delete_date_update").exactly(1).time
expect(StatsD).to have_received(:increment)
.with("#{statsd_prefix}.status", tags: ['status:complete'])
.exactly(2).times
expect(StatsD).to have_received(:increment)
.with("#{statsd_prefix}_upload.status", tags: ['status:vbms'])
.exactly(2).times
expect(StatsD).to have_received(:increment)
.with("#{statsd_prefix}_upload.status", tags: ['status:processing'])
.exactly(2).times
expect(Rails.logger).not_to have_received(:info)
.with("#{log_prefix} evidence status error", anything)
end
end
end

0 comments on commit 5faec8e

Please sign in to comment.