diff --git a/app/jobs/usps_auth_token_refresh_job.rb b/app/jobs/usps_auth_token_refresh_job.rb index 0cc066b6268..483bdcc5110 100644 --- a/app/jobs/usps_auth_token_refresh_job.rb +++ b/app/jobs/usps_auth_token_refresh_job.rb @@ -7,7 +7,7 @@ def perform analytics.idv_usps_auth_token_refresh_job_started usps_proofer.retrieve_token! - rescue Faraday::TimeoutError, Faraday::ConnectionFailed => err + rescue Faraday::TimeoutError, Faraday::ConnectionFailed, Faraday::ServerError => err analytics.idv_usps_auth_token_refresh_job_network_error( exception_class: err.class.name, exception_message: err.message, diff --git a/spec/jobs/usps_auth_token_refresh_job_spec.rb b/spec/jobs/usps_auth_token_refresh_job_spec.rb index 02fb6bd0d6b..9f7cae055d4 100644 --- a/spec/jobs/usps_auth_token_refresh_job_spec.rb +++ b/spec/jobs/usps_auth_token_refresh_job_spec.rb @@ -5,19 +5,13 @@ let(:subject) { described_class.new } let(:root_url) { 'http://my.root.url' } - let(:analytics) { instance_double(Analytics) } + let(:analytics) { FakeAnalytics.new } let(:usps_auth_token_cache_key) { UspsInPersonProofing::Proofer::AUTH_TOKEN_CACHE_KEY } before do allow(IdentityConfig.store).to receive(:usps_ipp_root_url).and_return(root_url) - allow(Analytics).to receive(:new). - with( - user: an_instance_of(AnonymousUser), - request: nil, - session: {}, - sp: nil, - ).and_return(analytics) + allow(subject).to receive(:analytics).and_return(analytics) end describe 'usps auth token refresh job' do @@ -69,24 +63,19 @@ end context 'auth request throws error' do - it 'still logs analytics' do + it 'catches server errors and logs them as network errors' do stub_error_request_token - expect(analytics).to receive( - :idv_usps_auth_token_refresh_job_started, - ).once - expect(analytics).to receive( - :idv_usps_auth_token_refresh_job_completed, - ).once + subject.perform - expect do - subject.perform - end.to raise_error + expect(analytics).to have_logged_event('UspsAuthTokenRefreshJob: Started') + expect(analytics).to have_logged_event('UspsAuthTokenRefreshJob: Network error') + expect(analytics).to have_logged_event('UspsAuthTokenRefreshJob: Completed') end end context 'auth request throws network error' do - [Faraday::TimeoutError, Faraday::ConnectionFailed].each do |err_class| + [Faraday::TimeoutError, Faraday::ServerError, Faraday::ConnectionFailed].each do |err_class| it "logs analytics without raising the #{err_class.name}" do stub_network_error_request_token( err_class.new('test error'),