From 112ff76ca96e447ce0efee30ef859da98b73310f Mon Sep 17 00:00:00 2001 From: Dewayne VanHoozer Date: Fri, 26 Apr 2024 09:26:58 -0500 Subject: [PATCH] changed flipper name and other style issues reported by the PR linter --- .../central_mail/submit_form4142_job.rb | 13 +- config/features.yml | 2 +- .../central_mail/submit_form4142_job_spec.rb | 151 +++++++++--------- 3 files changed, 82 insertions(+), 84 deletions(-) diff --git a/app/sidekiq/central_mail/submit_form4142_job.rb b/app/sidekiq/central_mail/submit_form4142_job.rb index 353065be4f7..a1540f72515 100644 --- a/app/sidekiq/central_mail/submit_form4142_job.rb +++ b/app/sidekiq/central_mail/submit_form4142_job.rb @@ -52,7 +52,7 @@ class CentralMailResponseError < Common::Exceptions::BackendServiceException; e bgjob_errors: bgjob_errors.merge(new_error) ) - api_statsd_key = if Flipper.enabled?(:disability_compensation_form_4142) + api_statsd_key = if Flipper.enabled?(:disability_compensation_form4142_supplemental) LIGHTHOUSE_STATSD_KEY_PREFIX else CENTRAL_MAIL_STATSD_KEY_PREFIX @@ -112,7 +112,7 @@ def processor end def upload_to_api - if Flipper.enabled?(:disability_compensation_form_4142) + if Flipper.enabled?(:disability_compensation_form4142_supplemental) upload_to_lighthouse else upload_to_central_mail @@ -144,7 +144,7 @@ def generate_metadata 'veteranFirstName' => vet_name[:first], 'veteranLastName' => vet_name[:last], 'zipCode' => determine_zip, - 'source' => "Form526Submission va.gov", + 'source' => 'Form526Submission va.gov', 'docType' => '4142', 'businessLine' => '', 'fileNumber' => filenumber # wipn8923 TODO: validate that this is correct @@ -156,15 +156,14 @@ def generate_metadata def determine_zip submission.form.dig('form526', 'form526', 'veteran', 'currentMailingAddress', 'zipFirstFive') || - submission.form.dig('form526', 'form526', 'veteran', 'mailingAddress', 'zipFirstFive') || - '00000' + submission.form.dig('form526', 'form526', 'veteran', 'mailingAddress', 'zipFirstFive') || + '00000' end def usa_based? - country = ( + country = submission.form.dig('form526', 'form526', 'veteran', 'currentMailingAddress', 'country') || submission.form.dig('form526', 'form526', 'veteran', 'mailingAddress', 'country') - ) %w[USA US].include?(country&.upcase) end diff --git a/config/features.yml b/config/features.yml index 4eba904eba3..8a396268882 100644 --- a/config/features.yml +++ b/config/features.yml @@ -372,7 +372,7 @@ features: actor_type: user description: enables sending flashes to BGS for disability_compensation submissions. enable_in_development: true - disability_compensation_form_4142: + disability_compensation_form4142_supplemental: actor_type: user description: Use Lighthouse API to submit supplemental Form 21-4142 from Form 526EZ submissions enable_in_development: true diff --git a/spec/sidekiq/central_mail/submit_form4142_job_spec.rb b/spec/sidekiq/central_mail/submit_form4142_job_spec.rb index 6dff6d0ff57..68a1b3bb301 100644 --- a/spec/sidekiq/central_mail/submit_form4142_job_spec.rb +++ b/spec/sidekiq/central_mail/submit_form4142_job_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require "rails_helper" -require "evss/disability_compensation_auth_headers" # required to build a Form526Submission +require 'rails_helper' +require 'evss/disability_compensation_auth_headers' # required to build a Form526Submission RSpec.describe CentralMail::SubmitForm4142Job, type: :job do subject { described_class } @@ -9,17 +9,17 @@ before do Sidekiq::Job.clear_all # Make Job use old CentralMail route for all tests - Flipper.disable(:disability_compensation_form_4142) + Flipper.disable(:disability_compensation_form4142_supplemental) end ####################### ## CentralMail Route ## ####################### - describe "Test old CentralMail route" do + describe 'Test old CentralMail route' do before do # Make Job use old CentralMail route for all tests - Flipper.disable(:disability_compensation_form_4142) + Flipper.disable(:disability_compensation_form4142_supplemental) end let(:user) { FactoryBot.create(:user, :loa3) } @@ -29,9 +29,9 @@ let(:evss_claim_id) { 123_456_789 } let(:saved_claim) { FactoryBot.create(:va526ez) } - describe ".perform_async" do + describe '.perform_async' do let(:form_json) do - File.read("spec/support/disability_compensation_form/submissions/with_4142.json") + File.read('spec/support/disability_compensation_form/submissions/with_4142.json') end let(:submission) do Form526Submission.create(user_uuid: user.uuid, @@ -42,81 +42,81 @@ end let(:metadata_hash) do form4142 = submission.form[Form526Submission::FORM_4142] - form4142["veteranFullName"].update("first" => "Bey'oncé", "last" => "Knowle$-Carter") - form4142["veteranAddress"].update("postalCode" => "123456789") + form4142['veteranFullName'].update('first' => "Bey'oncé", 'last' => 'Knowle$-Carter') + form4142['veteranAddress'].update('postalCode' => '123456789') subject.perform_async(submission.id) - jid = subject.jobs.last["jid"] + jid = subject.jobs.last['jid'] processor = EVSS::DisabilityCompensationForm::Form4142Processor.new(submission, jid) request_body = processor.request_body - JSON.parse(request_body["metadata"]) + JSON.parse(request_body['metadata']) end - context "with a successful submission job" do - it "queues a job for submit" do + context 'with a successful submission job' do + it 'queues a job for submit' do expect do subject.perform_async(submission.id) end.to change(subject.jobs, :size).by(1) end - it "submits successfully" do - VCR.use_cassette("central_mail/submit_4142") do + it 'submits successfully' do + VCR.use_cassette('central_mail/submit_4142') do subject.perform_async(submission.id) - jid = subject.jobs.last["jid"] + jid = subject.jobs.last['jid'] described_class.drain expect(jid).not_to be_empty end end - it "uses proper submission creation date for the received date" do - received_date = metadata_hash["receiveDt"] + it 'uses proper submission creation date for the received date' do + received_date = metadata_hash['receiveDt'] # Form4142Processor should use Central Time Zone # See https://dsva.slack.com/archives/C053U7BUT27/p1706808933985779?thread_ts=1706727152.783229&cid=C053U7BUT27 expect( - submission.created_at.in_time_zone("Central Time (US & Canada)").strftime("%Y-%m-%d %H:%M:%S") + submission.created_at.in_time_zone('Central Time (US & Canada)').strftime('%Y-%m-%d %H:%M:%S') ).to eq(received_date) end - it "corrects for invalid characters in generated metadata" do - veteran_first_name = metadata_hash["veteranFirstName"] - veteran_last_name = metadata_hash["veteranLastName"] + it 'corrects for invalid characters in generated metadata' do + veteran_first_name = metadata_hash['veteranFirstName'] + veteran_last_name = metadata_hash['veteranLastName'] allowed_chars_regex = %r{^[a-zA-Z\/\-\s]} expect(veteran_first_name).to match(allowed_chars_regex) expect(veteran_last_name).to match(allowed_chars_regex) end - it "reformats zip code in generated metadata" do - zip_code = metadata_hash["zipCode"] + it 'reformats zip code in generated metadata' do + zip_code = metadata_hash['zipCode'] expected_zip_format = /\A[0-9]{5}(?:-[0-9]{4})?\z/ expect(zip_code).to match(expected_zip_format) end end - context "with a submission timeout" do + context 'with a submission timeout' do before do allow_any_instance_of(Faraday::Connection).to receive(:post).and_raise(Faraday::TimeoutError) end - it "raises a gateway timeout error" do + it 'raises a gateway timeout error' do subject.perform_async(submission.id) expect { described_class.drain }.to raise_error(Common::Exceptions::GatewayTimeout) end end - context "with an unexpected error" do + context 'with an unexpected error' do before do - allow_any_instance_of(Faraday::Connection).to receive(:post).and_raise(StandardError.new("foo")) + allow_any_instance_of(Faraday::Connection).to receive(:post).and_raise(StandardError.new('foo')) end - it "raises a standard error" do + it 'raises a standard error' do subject.perform_async(submission.id) expect { described_class.drain }.to raise_error(StandardError) end end end - describe ".perform_async for client error" do + describe '.perform_async for client error' do let(:missing_postalcode_form_json) do - File.read "spec/support/disability_compensation_form/submissions/with_4142_missing_postalcode.json" + File.read 'spec/support/disability_compensation_form/submissions/with_4142_missing_postalcode.json' end let(:submission) do Form526Submission.create(user_uuid: user.uuid, @@ -126,9 +126,9 @@ submitted_claim_id: evss_claim_id) end - context "with a client error" do - it "raises a central mail response error" do - VCR.use_cassette("central_mail/submit_4142_400") do + context 'with a client error' do + it 'raises a central mail response error' do + VCR.use_cassette('central_mail/submit_4142_400') do subject.perform_async(submission.id) expect { described_class.drain }.to raise_error(CentralMail::SubmitForm4142Job::CentralMailResponseError) end @@ -136,13 +136,13 @@ end end - context "catastrophic failure state" do - describe "when all retries are exhausted" do + context 'catastrophic failure state' do + describe 'when all retries are exhausted' do let!(:form526_submission) { create(:form526_submission) } let!(:form526_job_status) { create(:form526_job_status, :retryable_error, form526_submission:, job_id: 1) } - it "updates a StatsD counter and updates the status on an exhaustion event" do - subject.within_sidekiq_retries_exhausted_block({ "jid" => form526_job_status.job_id }) do + it 'updates a StatsD counter and updates the status on an exhaustion event' do + subject.within_sidekiq_retries_exhausted_block({ 'jid' => form526_job_status.job_id }) do expect(StatsD).to receive(:increment).with("#{subject::CENTRAL_MAIL_STATSD_KEY_PREFIX}.exhausted") expect(Rails).to receive(:logger).and_call_original end @@ -155,15 +155,14 @@ # End of the Old CentralMail Route tests end - ###################### ## Lighthouse Route ## ###################### - describe "Test new Lighthouse route" do + describe 'Test new Lighthouse route' do before do # Make Job use new Lighthouse route for all tests - Flipper.enable(:disability_compensation_form_4142) + Flipper.enable(:disability_compensation_form4142_supplemental) end let(:user) { FactoryBot.create(:user, :loa3) } @@ -173,9 +172,9 @@ let(:evss_claim_id) { 123_456_789 } let(:saved_claim) { FactoryBot.create(:va526ez) } - describe ".perform_async" do + describe '.perform_async' do let(:form_json) do - File.read("spec/support/disability_compensation_form/submissions/with_4142.json") + File.read('spec/support/disability_compensation_form/submissions/with_4142.json') end let(:submission) do Form526Submission.create(user_uuid: user.uuid, @@ -186,82 +185,82 @@ end let(:metadata_hash) do form4142 = submission.form[Form526Submission::FORM_4142] - form4142["veteranFullName"].update("first" => "Bey'oncé", "last" => "Knowle$-Carter") - form4142["veteranAddress"].update("postalCode" => "123456789") + form4142['veteranFullName'].update('first' => "Bey'oncé", 'last' => 'Knowle$-Carter') + form4142['veteranAddress'].update('postalCode' => '123456789') subject.perform_async(submission.id) - jid = subject.jobs.last["jid"] + jid = subject.jobs.last['jid'] processor = EVSS::DisabilityCompensationForm::Form4142Processor.new(submission, jid) request_body = processor.request_body - JSON.parse(request_body["metadata"]) + JSON.parse(request_body['metadata']) end - context "with a successful submission job" do - it "queues a job for submit" do + context 'with a successful submission job' do + it 'queues a job for submit' do expect do subject.perform_async(submission.id) end.to change(subject.jobs, :size).by(1) end - it "submits successfully" do - skip "The VCR cassette needs to be changed to contain Lighthouse specific data." - VCR.use_cassette("central_mail/submit_4142") do + it 'submits successfully' do + skip 'The VCR cassette needs to be changed to contain Lighthouse specific data.' + VCR.use_cassette('central_mail/submit_4142') do subject.perform_async(submission.id) - jid = subject.jobs.last["jid"] + jid = subject.jobs.last['jid'] described_class.drain expect(jid).not_to be_empty end end - it "uses proper submission creation date for the received date" do - received_date = metadata_hash["receiveDt"] + it 'uses proper submission creation date for the received date' do + received_date = metadata_hash['receiveDt'] # Form4142Processor should use Central Time Zone # See https://dsva.slack.com/archives/C053U7BUT27/p1706808933985779?thread_ts=1706727152.783229&cid=C053U7BUT27 expect( - submission.created_at.in_time_zone("Central Time (US & Canada)").strftime("%Y-%m-%d %H:%M:%S") + submission.created_at.in_time_zone('Central Time (US & Canada)').strftime('%Y-%m-%d %H:%M:%S') ).to eq(received_date) end - it "corrects for invalid characters in generated metadata" do - veteran_first_name = metadata_hash["veteranFirstName"] - veteran_last_name = metadata_hash["veteranLastName"] + it 'corrects for invalid characters in generated metadata' do + veteran_first_name = metadata_hash['veteranFirstName'] + veteran_last_name = metadata_hash['veteranLastName'] allowed_chars_regex = %r{^[a-zA-Z\/\-\s]} expect(veteran_first_name).to match(allowed_chars_regex) expect(veteran_last_name).to match(allowed_chars_regex) end - it "reformats zip code in generated metadata" do - zip_code = metadata_hash["zipCode"] + it 'reformats zip code in generated metadata' do + zip_code = metadata_hash['zipCode'] expected_zip_format = /\A[0-9]{5}(?:-[0-9]{4})?\z/ expect(zip_code).to match(expected_zip_format) end end - context "with a submission timeout" do + context 'with a submission timeout' do before do allow_any_instance_of(Faraday::Connection).to receive(:post).and_raise(Faraday::TimeoutError) end - it "raises a gateway timeout error" do + it 'raises a gateway timeout error' do subject.perform_async(submission.id) expect { described_class.drain }.to raise_error(Common::Exceptions::GatewayTimeout) end end - context "with an unexpected error" do + context 'with an unexpected error' do before do - allow_any_instance_of(Faraday::Connection).to receive(:post).and_raise(StandardError.new("foo")) + allow_any_instance_of(Faraday::Connection).to receive(:post).and_raise(StandardError.new('foo')) end - it "raises a standard error" do + it 'raises a standard error' do subject.perform_async(submission.id) expect { described_class.drain }.to raise_error(StandardError) end end end - describe ".perform_async for client error" do + describe '.perform_async for client error' do let(:missing_postalcode_form_json) do - File.read "spec/support/disability_compensation_form/submissions/with_4142_missing_postalcode.json" + File.read 'spec/support/disability_compensation_form/submissions/with_4142_missing_postalcode.json' end let(:submission) do Form526Submission.create(user_uuid: user.uuid, @@ -271,10 +270,10 @@ submitted_claim_id: evss_claim_id) end - context "with a client error" do - it "raises a central mail response error" do - skip "The VCR cassette needs to be changed to contain Lighthouse specific data." - VCR.use_cassette("central_mail/submit_4142_400") do + context 'with a client error' do + it 'raises a central mail response error' do + skip 'The VCR cassette needs to be changed to contain Lighthouse specific data.' + VCR.use_cassette('central_mail/submit_4142_400') do subject.perform_async(submission.id) expect { described_class.drain }.to raise_error(CentralMail::SubmitForm4142Job::CentralMailResponseError) end @@ -282,13 +281,13 @@ end end - context "catastrophic failure state" do - describe "when all retries are exhausted" do + context 'catastrophic failure state' do + describe 'when all retries are exhausted' do let!(:form526_submission) { create(:form526_submission) } let!(:form526_job_status) { create(:form526_job_status, :retryable_error, form526_submission:, job_id: 1) } - it "updates a StatsD counter and updates the status on an exhaustion event" do - subject.within_sidekiq_retries_exhausted_block({ "jid" => form526_job_status.job_id }) do + it 'updates a StatsD counter and updates the status on an exhaustion event' do + subject.within_sidekiq_retries_exhausted_block({ 'jid' => form526_job_status.job_id }) do expect(StatsD).to receive(:increment).with("#{subject::LIGHTHOUSE_STATSD_KEY_PREFIX}.exhausted") expect(Rails).to receive(:logger).and_call_original end