From 84c8363f94f6fc47ad214b2b1013924a5de08111 Mon Sep 17 00:00:00 2001 From: Alison Jones Date: Mon, 28 Oct 2024 16:48:04 -0500 Subject: [PATCH] Finish specs for EVSS path, linting --- .../submit_form0781_spec.rb | 102 ++++++++++-------- 1 file changed, 58 insertions(+), 44 deletions(-) diff --git a/spec/sidekiq/evss/disability_compensation_form/submit_form0781_spec.rb b/spec/sidekiq/evss/disability_compensation_form/submit_form0781_spec.rb index 7a3afbfdc83..d14a087f012 100644 --- a/spec/sidekiq/evss/disability_compensation_form/submit_form0781_spec.rb +++ b/spec/sidekiq/evss/disability_compensation_form/submit_form0781_spec.rb @@ -148,24 +148,34 @@ it 'uploads the 0781 documents to Lighthouse' do # 0781 - allow_any_instance_of(described_class).to receive(:generate_stamp_pdf).with(parsed_0781_form, - submission.submitted_claim_id, '21-0781').and_return(path_to_0781_fixture) + allow_any_instance_of(described_class) + .to receive(:generate_stamp_pdf) + .with(parsed_0781_form, submission.submitted_claim_id, '21-0781') + .and_return(path_to_0781_fixture) - allow_any_instance_of(LighthouseSupplementalDocumentUploadProvider).to receive(:generate_upload_document).and_return(lighthouse_0781_document) + allow_any_instance_of(LighthouseSupplementalDocumentUploadProvider) + .to receive(:generate_upload_document) + .and_return(lighthouse_0781_document) allow(File).to receive(:delete).and_return(nil) - expect(BenefitsDocuments::Form526::UploadSupplementalDocumentService).to receive(:call).with(sample_0781_file_read, - lighthouse_0781a_document) + expect(BenefitsDocuments::Form526::UploadSupplementalDocumentService) + .to receive(:call) + .with(sample_0781_file_read, lighthouse_0781a_document) # 0781a - allow_any_instance_of(described_class).to receive(:generate_stamp_pdf).with(parsed_0781a_form, - submission.submitted_claim_id, '21-0781a').and_return(path_to_0781a_fixture) + allow_any_instance_of(described_class) + .to receive(:generate_stamp_pdf) + .with(parsed_0781a_form, submission.submitted_claim_id, '21-0781a') + .and_return(path_to_0781a_fixture) - allow_any_instance_of(LighthouseSupplementalDocumentUploadProvider).to receive(:generate_upload_document).and_return(lighthouse_0781a_document) + allow_any_instance_of(LighthouseSupplementalDocumentUploadProvider) + .to receive(:generate_upload_document) + .and_return(lighthouse_0781a_document) - expect(BenefitsDocuments::Form526::UploadSupplementalDocumentService).to receive(:call).with(sample_0781a_file_read, - lighthouse_0781a_document) + expect(BenefitsDocuments::Form526::UploadSupplementalDocumentService) + .to receive(:call) + .with(sample_0781a_file_read, lighthouse_0781a_document) perform_upload end @@ -281,19 +291,22 @@ before do Flipper.disable(:disability_compensation_upload_0781_to_lighthouse) allow(EVSS::DocumentsService).to receive(:new) { client_stub } - allow_any_instance_of(EVSS::DocumentsService).to receive(:upload) - - allow_any_instance_of(described_class).to receive(:generate_stamp_pdf).with(parsed_0781_form, - submission.submitted_claim_id, '21-0781').and_return(path_to_0781_fixture) - - allow_any_instance_of(EVSSSupplementalDocumentUploadProvider).to receive(:generate_upload_document).with('simple_0781.pdf').and_return(evss_claim_0781_document) - + allow(client_stub).to receive(:upload) + allow_any_instance_of(described_class) + .to receive(:generate_stamp_pdf).with(parsed_0781_form, submission.submitted_claim_id, '21-0781') + .and_return(path_to_0781_fixture) + allow_any_instance_of(EVSSSupplementalDocumentUploadProvider) + .to receive(:generate_upload_document) + .with('simple_0781.pdf') + .and_return(evss_claim_0781_document) allow(File).to receive(:delete).and_return(nil) - - allow_any_instance_of(described_class).to receive(:generate_stamp_pdf).with(parsed_0781a_form, - submission.submitted_claim_id, '21-0781a').and_return(path_to_0781a_fixture) - - allow_any_instance_of(EVSSSupplementalDocumentUploadProvider).to receive(:generate_upload_document).with('simple.pdf').and_return(evss_claim_0781a_document) + allow_any_instance_of(described_class) + .to receive(:generate_stamp_pdf) + .with(parsed_0781a_form, submission.submitted_claim_id, '21-0781a') + .and_return(path_to_0781a_fixture) + allow_any_instance_of(EVSSSupplementalDocumentUploadProvider) + .to receive(:generate_upload_document).with('simple.pdf') + .and_return(evss_claim_0781a_document) end it 'uploads the 0781 documents to EVSS' do @@ -304,33 +317,34 @@ perform_upload end - # TODO: it 'logs the upload attempt with the correct job prefix' do - # expect(StatsD).to receive(:increment).with( - # "#{expected_statsd_metrics_prefix}.upload_attempt" - # ).twice # For 0781 and 0781a + it 'logs the upload attempt with the correct job prefix' do + allow(client_stub).to receive(:upload) + expect(StatsD).to receive(:increment).with( + "#{expected_statsd_metrics_prefix}.upload_attempt" + ).twice # For 0781 and 0781a - # perform_upload - # end + perform_upload + end - # TODO: it 'increments the correct StatsD success metric' do - # expect(StatsD).to receive(:increment).with( - # "#{expected_statsd_metrics_prefix}.upload_success" - # ).twice # For 0781 and 0781a + it 'increments the correct StatsD success metric' do + allow(client_stub).to receive(:upload) + expect(StatsD).to receive(:increment).with( + "#{expected_statsd_metrics_prefix}.upload_success" + ).twice # For 0781 and 0781a - # perform_upload - # end + perform_upload + end context 'when an upload raises an EVSS response error' do - # TODO: it 'logs an upload error' do - # allow_any_instance_of(EVSS::DocumentsService).to receive(:upload) - # .and_raise(EVSS::ErrorMiddleware::EVSSError) - # expect_any_instance_of(EVSSSupplementalDocumentUploadProvider).to receive(:log_upload_failure) - - # expect do - # subject.perform_async(submission.id) - # described_class.drain - # end.to raise_error(EVSS::ErrorMiddleware::EVSSError) - # end + it 'logs an upload error' do + allow(client_stub).to receive(:upload).and_raise(EVSS::ErrorMiddleware::EVSSError) + expect_any_instance_of(EVSSSupplementalDocumentUploadProvider).to receive(:log_upload_failure) + + expect do + subject.perform_async(submission.id) + described_class.drain + end.to raise_error(EVSS::ErrorMiddleware::EVSSError) + end end end end