diff --git a/config/settings.yml b/config/settings.yml index ae892a18f23..43f3bce3421 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -1289,6 +1289,12 @@ vanotify: claim_submission_success_text: fake_template_id claim_submission_duplicate_text: fake_template_id claim_submission_error_text: fake_template_id + oracle_health: + sms_sender_id: fake_secret + template_id: + claim_submission_success_text: fake_template_id + claim_submission_duplicate_text: fake_template_id + claim_submission_error_text: fake_template_id benefits_decision_review: api_key: fake_secret mock: false diff --git a/config/settings/test.yml b/config/settings/test.yml index bca02f4f213..7fb55bde072 100644 --- a/config/settings/test.yml +++ b/config/settings/test.yml @@ -137,11 +137,17 @@ vanotify: disconnection_template: fake_template_id check_in: api_key: check-in_aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa-bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb - sms_sender_id: fake_sms_sender_id + sms_sender_id: cie_fake_sms_sender_id template_id: - claim_submission_success_text: fake_success_template_id - claim_submission_duplicate_text: fake_duplicate_template_id - claim_submission_error_text: fake_error_template_id + claim_submission_success_text: cie_fake_success_template_id + claim_submission_duplicate_text: cie_fake_duplicate_template_id + claim_submission_error_text: cie_fake_error_template_id + oracle_health: + sms_sender_id: oh_fake_sms_sender_id + template_id: + claim_submission_success_text: oh_fake_success_template_id + claim_submission_duplicate_text: oh_fake_duplicate_template_id + claim_submission_error_text: oh_fake_error_template_id veteran_readiness_and_employment: base_url: https://fake_url.com @@ -225,7 +231,7 @@ lighthouse: client_id: abc123456 rsa_key: path/to/key use_mocks: false - benefits_education: + benefits_education: host: https://sandbox-api.va.gov use_mocks: true access_token: diff --git a/modules/check_in/app/sidekiq/check_in/travel_claim_submission_worker.rb b/modules/check_in/app/sidekiq/check_in/travel_claim_submission_worker.rb index e4bab48d757..c59caa02fd0 100644 --- a/modules/check_in/app/sidekiq/check_in/travel_claim_submission_worker.rb +++ b/modules/check_in/app/sidekiq/check_in/travel_claim_submission_worker.rb @@ -9,72 +9,109 @@ class TravelClaimSubmissionWorker sidekiq_options retry: false - SUCCESS_TEMPLATE_ID = Settings.vanotify.services.check_in.template_id.claim_submission_success_text - DUPLICATE_TEMPLATE_ID = Settings.vanotify.services.check_in.template_id.claim_submission_duplicate_text - ERROR_TEMPLATE_ID = Settings.vanotify.services.check_in.template_id.claim_submission_error_text - - SMS_SENDER_ID = Settings.vanotify.services.check_in.sms_sender_id - + # settings for travel claims for vista appts STATSD_NOTIFY_ERROR = 'worker.checkin.travel_claim.notify.error' STATSD_NOTIFY_SUCCESS = 'worker.checkin.travel_claim.notify.success' - STATSD_BTSSS_SUCCESS = 'worker.checkin.travel_claim.btsss.success' - STATSD_BTSSS_ERROR = 'worker.checkin.travel_claim.btsss.error' - STATSD_BTSSS_DUPLICATE = 'worker.checkin.travel_claim.btsss.duplicate' + CIE_SUCCESS_TEMPLATE_ID = Settings.vanotify.services.check_in.template_id.claim_submission_success_text + CIE_DUPLICATE_TEMPLATE_ID = Settings.vanotify.services.check_in.template_id.claim_submission_duplicate_text + CIE_ERROR_TEMPLATE_ID = Settings.vanotify.services.check_in.template_id.claim_submission_error_text + + CIE_SMS_SENDER_ID = Settings.vanotify.services.check_in.sms_sender_id + + CIE_STATSD_BTSSS_SUCCESS = 'worker.checkin.travel_claim.btsss.success' + CIE_STATSD_BTSSS_ERROR = 'worker.checkin.travel_claim.btsss.error' + CIE_STATSD_BTSSS_DUPLICATE = 'worker.checkin.travel_claim.btsss.duplicate' + + # settings for travel claims for oracle health settings + OH_SUCCESS_TEMPLATE_ID = Settings.vanotify.services.oracle_health.template_id.claim_submission_success_text + OH_DUPLICATE_TEMPLATE_ID = Settings.vanotify.services.oracle_health.template_id.claim_submission_duplicate_text + OH_ERROR_TEMPLATE_ID = Settings.vanotify.services.oracle_health.template_id.claim_submission_error_text + + OH_SMS_SENDER_ID = Settings.vanotify.services.oracle_health.sms_sender_id + + OH_STATSD_BTSSS_SUCCESS = 'worker.oracle_health.travel_claim.btsss.success' + OH_STATSD_BTSSS_ERROR = 'worker.oracle_health.travel_claim.btsss.error' + OH_STATSD_BTSSS_DUPLICATE = 'worker.oracle_health.travel_claim.btsss.duplicate' def perform(uuid, appointment_date) redis_client = TravelClaim::RedisClient.build mobile_phone = redis_client.patient_cell_phone(uuid:) station_number = redis_client.station_number(uuid:) + facility_type = redis_client.facility_type(uuid:) logger.info({ - message: "Submitting travel claim for #{uuid}, #{appointment_date}, #{station_number}", + message: "Submitting travel claim for #{uuid}, #{appointment_date}, " \ + "#{station_number}, #{facility_type}", uuid:, appointment_date:, - station_number: + station_number:, + facility_type: }) - claim_number, template_id = submit_claim(uuid:, appointment_date:, station_number:) + claim_number, template_id = submit_claim(uuid:, appointment_date:, station_number:, facility_type:) - send_notification(mobile_phone:, appointment_date:, template_id:, claim_number:) + send_notification(mobile_phone:, appointment_date:, template_id:, claim_number:, facility_type:) StatsD.increment(STATSD_NOTIFY_SUCCESS) end def submit_claim(opts = {}) check_in_session = CheckIn::V2::Session.build(data: { uuid: opts[:uuid] }) + claims_resp = TravelClaim::Service.build( check_in: check_in_session, params: { appointment_date: opts[:appointment_date] } ).submit_claim - handle_response(claims_resp:) - rescue Common::Exceptions::BackendServiceException => e + handle_response(claims_resp:, facility_type: opts[:facility_type]) + rescue => e logger.error({ message: "Error calling BTSSS Service: #{e.message}" }.merge(opts)) - StatsD.increment(STATSD_BTSSS_ERROR) - [nil, ERROR_TEMPLATE_ID] + if 'oh'.casecmp?(opts[:facility_type]) + StatsD.increment(OH_STATSD_BTSSS_ERROR) + template_id = OH_ERROR_TEMPLATE_ID + else + StatsD.increment(CIE_STATSD_BTSSS_ERROR) + template_id = CIE_ERROR_TEMPLATE_ID + end + [nil, template_id] end - def handle_response(claims_resp:) - claim_number = claims_resp&.dig(:data, :claimNumber)&.last(4) - template_id = - case claims_resp&.dig(:data, :code) - when TravelClaim::Response::CODE_SUCCESS - StatsD.increment(STATSD_BTSSS_SUCCESS) - SUCCESS_TEMPLATE_ID - when TravelClaim::Response::CODE_CLAIM_EXISTS - StatsD.increment(STATSD_BTSSS_DUPLICATE) - DUPLICATE_TEMPLATE_ID - else - StatsD.increment(STATSD_BTSSS_ERROR) - ERROR_TEMPLATE_ID - end + # rubocop:disable Metrics/MethodLength + def handle_response(opts = {}) + claim_number = opts[:claims_resp]&.dig(:data, :claimNumber)&.last(4) + code = opts[:claims_resp]&.dig(:data, :code) + facility_type = opts[:facility_type] || '' + + statsd_metric, template_id = case facility_type.downcase + when 'oh' + case code + when TravelClaim::Response::CODE_SUCCESS + [OH_STATSD_BTSSS_SUCCESS, OH_SUCCESS_TEMPLATE_ID] + when TravelClaim::Response::CODE_CLAIM_EXISTS + [OH_STATSD_BTSSS_DUPLICATE, OH_DUPLICATE_TEMPLATE_ID] + else + [OH_STATSD_BTSSS_ERROR, OH_ERROR_TEMPLATE_ID] + end + else + case code + when TravelClaim::Response::CODE_SUCCESS + [CIE_STATSD_BTSSS_SUCCESS, CIE_SUCCESS_TEMPLATE_ID] + when TravelClaim::Response::CODE_CLAIM_EXISTS + [CIE_STATSD_BTSSS_DUPLICATE, CIE_DUPLICATE_TEMPLATE_ID] + else + [CIE_STATSD_BTSSS_ERROR, CIE_ERROR_TEMPLATE_ID] + end + end + + StatsD.increment(statsd_metric) [claim_number, template_id] end + # rubocop:enable Metrics/MethodLength def send_notification(opts = {}) notify_client = VaNotify::Service.new(Settings.vanotify.services.check_in.api_key) - phone_last_four = opts[:mobile_phone].delete('^0-9').last(4) + logger.info({ message: "Sending travel claim notification to #{phone_last_four}, #{opts[:template_id]}", phone_last_four:, @@ -85,7 +122,7 @@ def send_notification(opts = {}) notify_client.send_sms( phone_number: opts[:mobile_phone], template_id: opts[:template_id], - sms_sender_id: SMS_SENDER_ID, + sms_sender_id: 'oh'.casecmp?(opts[:facility_type]) ? OH_SMS_SENDER_ID : CIE_SMS_SENDER_ID, personalisation: { claim_number: opts[:claim_number], appt_date: appt_date_in_mmm_dd_format diff --git a/modules/check_in/spec/sidekiq/travel_claim_submission_worker_spec.rb b/modules/check_in/spec/sidekiq/travel_claim_submission_worker_spec.rb index be5ae10d835..cce04cc405e 100644 --- a/modules/check_in/spec/sidekiq/travel_claim_submission_worker_spec.rb +++ b/modules/check_in/spec/sidekiq/travel_claim_submission_worker_spec.rb @@ -2,229 +2,229 @@ require 'rails_helper' -describe CheckIn::TravelClaimSubmissionWorker, type: :worker do - describe '#perform' do - let(:uuid) { '3bcd636c-d4d3-4349-9058-03b2f6b38ced' } - let(:appt_date) { '2022-09-01' } - let(:mobile_phone) { '123-345-4566' } - let(:mobile_phone_last_four) { '4566' } - let(:patient_cell_phone) { '123-345-7777' } - let(:patient_cell_phone_last_four) { '7777' } - let(:station_number) { '500xyz' } - let(:redis_token) { '123-456' } - let(:icn) { '123456' } - let(:notify_appt_date) { 'Sep 01' } - let(:claim_last4) { '1666' } - let(:redis_client) { double } - - before do - allow(TravelClaim::RedisClient).to receive(:build).and_return(redis_client) - allow(Flipper).to receive(:enabled?).with('check_in_experience_mock_enabled').and_return(false) - allow(Flipper).to receive(:enabled?).with(:check_in_experience_travel_claim_increase_timeout).and_return(true) - - allow(redis_client).to receive(:mobile_phone).and_return(mobile_phone) - allow(redis_client).to receive(:patient_cell_phone).and_return(patient_cell_phone) - allow(redis_client).to receive(:token).and_return(redis_token) - allow(redis_client).to receive(:icn).and_return(icn) - allow(redis_client).to receive(:station_number).and_return(station_number) - - allow(StatsD).to receive(:increment) +shared_examples 'travel claims worker #perform' do |facility_type| + before do + if 'oracle_health'.casecmp?(facility_type) + @sms_sender_id = Settings.vanotify.services.oracle_health.sms_sender_id + @success_template_id = Settings.vanotify.services.oracle_health.template_id.claim_submission_success_text + @duplicate_template_id = Settings.vanotify.services.oracle_health.template_id.claim_submission_duplicate_text + @error_template_id = Settings.vanotify.services.oracle_health.template_id.claim_submission_error_text + + @statsd_success = CheckIn::TravelClaimSubmissionWorker::OH_STATSD_BTSSS_SUCCESS + @statsd_duplicate = CheckIn::TravelClaimSubmissionWorker::OH_STATSD_BTSSS_DUPLICATE + @statsd_error = CheckIn::TravelClaimSubmissionWorker::OH_STATSD_BTSSS_ERROR + + allow(redis_client).to receive(:facility_type).and_return('oh') + else + @sms_sender_id = Settings.vanotify.services.check_in.sms_sender_id + @success_template_id = Settings.vanotify.services.check_in.template_id.claim_submission_success_text + @duplicate_template_id = Settings.vanotify.services.check_in.template_id.claim_submission_duplicate_text + @error_template_id = Settings.vanotify.services.check_in.template_id.claim_submission_error_text + + @statsd_success = CheckIn::TravelClaimSubmissionWorker::CIE_STATSD_BTSSS_SUCCESS + @statsd_duplicate = CheckIn::TravelClaimSubmissionWorker::CIE_STATSD_BTSSS_DUPLICATE + @statsd_error = CheckIn::TravelClaimSubmissionWorker::CIE_STATSD_BTSSS_ERROR + + allow(redis_client).to receive(:facility_type).and_return(nil) end + end - context 'travel claim returns success' do - it 'sends notification with success template' do - worker = described_class.new - notify_client = double - - expect(VaNotify::Service).to receive(:new).with(Settings.vanotify.services.check_in.api_key) - .and_return(notify_client) - expect(notify_client).to receive(:send_sms).with( - phone_number: patient_cell_phone, - template_id: 'fake_success_template_id', - sms_sender_id: 'fake_sms_sender_id', - personalisation: { claim_number: claim_last4, appt_date: notify_appt_date } - ) - expect(worker).not_to receive(:log_exception_to_sentry) - - Sidekiq::Testing.inline! do - VCR.use_cassette('check_in/btsss/submit_claim/submit_claim_200', match_requests_on: [:host]) do - worker.perform(uuid, appt_date) - end + context "when #{facility_type} facility and travel claim returns success" do + it 'sends notification with success template' do + worker = described_class.new + notify_client = double + + expect(VaNotify::Service).to receive(:new).with(Settings.vanotify.services.check_in.api_key) + .and_return(notify_client) + expect(notify_client).to receive(:send_sms).with( + phone_number: patient_cell_phone, + template_id: @success_template_id, + sms_sender_id: @sms_sender_id, + personalisation: { claim_number: claim_last4, appt_date: notify_appt_date } + ) + expect(worker).not_to receive(:log_exception_to_sentry) + + Sidekiq::Testing.inline! do + VCR.use_cassette('check_in/btsss/submit_claim/submit_claim_200', match_requests_on: [:host]) do + worker.perform(uuid, appt_date) end - - expect(StatsD).to have_received(:increment) - .with(CheckIn::TravelClaimSubmissionWorker::STATSD_BTSSS_SUCCESS).exactly(1).time - expect(StatsD).to have_received(:increment) - .with(CheckIn::TravelClaimSubmissionWorker::STATSD_NOTIFY_SUCCESS).exactly(1).time end + + expect(StatsD).to have_received(:increment).with(@statsd_success).exactly(1).time + expect(StatsD).to have_received(:increment) + .with(CheckIn::TravelClaimSubmissionWorker::STATSD_NOTIFY_SUCCESS).exactly(1).time end + end - context 'travel claim returns duplicate error' do - it 'sends notification with duplicate message' do - worker = described_class.new - notify_client = double - expect(VaNotify::Service).to receive(:new).with(Settings.vanotify.services.check_in.api_key) - .and_return(notify_client) - expect(notify_client).to receive(:send_sms).with( - phone_number: patient_cell_phone, - template_id: 'fake_duplicate_template_id', - sms_sender_id: 'fake_sms_sender_id', - personalisation: { claim_number: nil, appt_date: notify_appt_date } - ) - expect(worker).not_to receive(:log_exception_to_sentry) - - Sidekiq::Testing.inline! do - VCR.use_cassette('check_in/btsss/submit_claim/submit_claim_400_exists', match_requests_on: [:host]) do - worker.perform(uuid, appt_date) - end + context "when #{facility_type} facility and travel claim returns duplicate error" do + it 'sends notification with duplicate message' do + worker = described_class.new + notify_client = double + expect(VaNotify::Service).to receive(:new).with(Settings.vanotify.services.check_in.api_key) + .and_return(notify_client) + expect(notify_client).to receive(:send_sms).with( + phone_number: patient_cell_phone, + template_id: @duplicate_template_id, + sms_sender_id: @sms_sender_id, + personalisation: { claim_number: nil, appt_date: notify_appt_date } + ) + expect(worker).not_to receive(:log_exception_to_sentry) + + Sidekiq::Testing.inline! do + VCR.use_cassette('check_in/btsss/submit_claim/submit_claim_400_exists', match_requests_on: [:host]) do + worker.perform(uuid, appt_date) end - - expect(StatsD).to have_received(:increment) - .with(CheckIn::TravelClaimSubmissionWorker::STATSD_BTSSS_DUPLICATE).exactly(1).time - expect(StatsD).to have_received(:increment) - .with(CheckIn::TravelClaimSubmissionWorker::STATSD_NOTIFY_SUCCESS).exactly(1).time end + + expect(StatsD).to have_received(:increment).with(@statsd_duplicate).exactly(1).time + expect(StatsD).to have_received(:increment) + .with(CheckIn::TravelClaimSubmissionWorker::STATSD_NOTIFY_SUCCESS).exactly(1).time end + end - context 'travel claim returns general error' do - it 'sends notification with error message' do - worker = described_class.new - notify_client = double - expect(VaNotify::Service).to receive(:new).with(Settings.vanotify.services.check_in.api_key) - .and_return(notify_client) - expect(notify_client).to receive(:send_sms).with( - phone_number: patient_cell_phone, - template_id: 'fake_error_template_id', - sms_sender_id: 'fake_sms_sender_id', - personalisation: { claim_number: nil, appt_date: notify_appt_date } - ) - expect(worker).not_to receive(:log_exception_to_sentry) - - Sidekiq::Testing.inline! do - VCR.use_cassette('check_in/btsss/submit_claim/submit_claim_500', match_requests_on: [:host]) do - worker.perform(uuid, appt_date) - end + context "when #{facility_type} facility and travel claim returns general error" do + it 'sends notification with error message' do + worker = described_class.new + notify_client = double + expect(VaNotify::Service).to receive(:new).with(Settings.vanotify.services.check_in.api_key) + .and_return(notify_client) + expect(notify_client).to receive(:send_sms).with( + phone_number: patient_cell_phone, + template_id: @error_template_id, + sms_sender_id: @sms_sender_id, + personalisation: { claim_number: nil, appt_date: notify_appt_date } + ) + expect(worker).not_to receive(:log_exception_to_sentry) + + Sidekiq::Testing.inline! do + VCR.use_cassette('check_in/btsss/submit_claim/submit_claim_500', match_requests_on: [:host]) do + worker.perform(uuid, appt_date) end - - expect(StatsD).to have_received(:increment) - .with(CheckIn::TravelClaimSubmissionWorker::STATSD_BTSSS_ERROR).exactly(1).time - expect(StatsD).to have_received(:increment) - .with(CheckIn::TravelClaimSubmissionWorker::STATSD_NOTIFY_SUCCESS).exactly(1).time end + + expect(StatsD).to have_received(:increment).with(@statsd_error).exactly(1).time + expect(StatsD).to have_received(:increment) + .with(CheckIn::TravelClaimSubmissionWorker::STATSD_NOTIFY_SUCCESS).exactly(1).time + end + end + + context "when #{facility_type} facility and travel claim token call returns error" do + before do + allow(redis_client).to receive(:token).and_return(nil) end - context 'travel claim token call returns error' do - before do - allow(redis_client).to receive(:token).and_return(nil) + it 'sends notification with error message' do + worker = described_class.new + notify_client = double + expect(VaNotify::Service).to receive(:new).with(Settings.vanotify.services.check_in.api_key) + .and_return(notify_client) + expect(notify_client).to receive(:send_sms).with( + phone_number: patient_cell_phone, + template_id: @error_template_id, + sms_sender_id: @sms_sender_id, + personalisation: { claim_number: nil, appt_date: notify_appt_date } + ) + expect(worker).not_to receive(:log_exception_to_sentry) + + Sidekiq::Testing.inline! do + VCR.use_cassette('check_in/btsss/token/token_500', match_requests_on: [:host]) do + worker.perform(uuid, appt_date) + end end - it 'sends notification with error message' do - worker = described_class.new - notify_client = double - expect(VaNotify::Service).to receive(:new).with(Settings.vanotify.services.check_in.api_key) - .and_return(notify_client) - expect(notify_client).to receive(:send_sms).with( - phone_number: patient_cell_phone, - template_id: 'fake_error_template_id', - sms_sender_id: 'fake_sms_sender_id', - personalisation: { claim_number: nil, appt_date: notify_appt_date } - ) - expect(worker).not_to receive(:log_exception_to_sentry) - - Sidekiq::Testing.inline! do - VCR.use_cassette('check_in/btsss/token/token_500', match_requests_on: [:host]) do - worker.perform(uuid, appt_date) + expect(StatsD).to have_received(:increment).with(@statsd_error).exactly(1).time + expect(StatsD).to have_received(:increment) + .with(CheckIn::TravelClaimSubmissionWorker::STATSD_NOTIFY_SUCCESS).exactly(1).time + end + end + + context "when #{facility_type} facility and send_sms returns an error" do + it 'handles the error' do + worker = described_class.new + expect(worker).to receive(:log_exception_to_sentry).with( + instance_of(Common::Exceptions::BackendServiceException), + { phone_number: patient_cell_phone_last_four, template_id: @success_template_id, claim_number: claim_last4 }, + { error: :check_in_va_notify_job, team: 'check-in' } + ) + + expect(StatsD).not_to receive(:increment) + .with(CheckIn::TravelClaimSubmissionWorker::STATSD_NOTIFY_SUCCESS) + expect(StatsD).to receive(:increment) + .with(CheckIn::TravelClaimSubmissionWorker::STATSD_NOTIFY_ERROR).exactly(1).time + + Sidekiq::Testing.inline! do + VCR.use_cassette('check_in/vanotify/send_sms_403_forbidden', match_requests_on: [:host]) do + VCR.use_cassette('check_in/btsss/submit_claim/submit_claim_200', match_requests_on: [:host]) do + expect { worker.perform(uuid, appt_date) }.to raise_error(Common::Exceptions::BackendServiceException) end end - - expect(StatsD).to have_received(:increment) - .with(CheckIn::TravelClaimSubmissionWorker::STATSD_BTSSS_ERROR).exactly(1).time - expect(StatsD).to have_received(:increment) - .with(CheckIn::TravelClaimSubmissionWorker::STATSD_NOTIFY_SUCCESS).exactly(1).time end end + end +end - context 'travel claim taking longer time to respond' do - it 'throws timeout exception and sends notification with error message' do - allow_any_instance_of(Faraday::Connection).to receive(:post).and_raise(Faraday::TimeoutError) - worker = described_class.new - notify_client = double - - expect(VaNotify::Service).to receive(:new).with(Settings.vanotify.services.check_in.api_key) - .and_return(notify_client) +describe CheckIn::TravelClaimSubmissionWorker, type: :worker do + let(:uuid) { '3bcd636c-d4d3-4349-9058-03b2f6b38ced' } + let(:appt_date) { '2022-09-01' } + let(:patient_cell_phone) { '123-345-7777' } + let(:patient_cell_phone_last_four) { '7777' } + let(:station_number) { '500xyz' } + let(:redis_token) { '123-456' } + let(:icn) { '123456' } + let(:notify_appt_date) { 'Sep 01' } + let(:claim_last4) { '1666' } + let(:facility_type) { 'oh' } + let(:redis_client) { double } + + before do + allow(TravelClaim::RedisClient).to receive(:build).and_return(redis_client) + allow(Flipper).to receive(:enabled?).with('check_in_experience_mock_enabled').and_return(false) + allow(Flipper).to receive(:enabled?).with(:check_in_experience_travel_claim_increase_timeout).and_return(true) + + allow(redis_client).to receive(:patient_cell_phone).and_return(patient_cell_phone) + allow(redis_client).to receive(:token).and_return(redis_token) + allow(redis_client).to receive(:icn).and_return(icn) + allow(redis_client).to receive(:station_number).and_return(station_number) + allow(redis_client).to receive(:facility_type).and_return(nil) + + allow(StatsD).to receive(:increment) + end - expect(notify_client).to receive(:send_sms).with( - phone_number: patient_cell_phone, - template_id: 'fake_error_template_id', - sms_sender_id: 'fake_sms_sender_id', - personalisation: { claim_number: nil, appt_date: notify_appt_date } - ) + describe '#perform for vista sites' do + include_examples 'travel claims worker #perform', '' + end - Sidekiq::Testing.inline! do - worker.perform(uuid, appt_date) - end + describe '#perform for oracle health sites' do + include_examples 'travel claims worker #perform', 'oracle_health' + end - expect(StatsD).to have_received(:increment).with(CheckIn::TravelClaimSubmissionWorker::STATSD_BTSSS_ERROR) - .exactly(1).time - expect(StatsD).to have_received(:increment).with(CheckIn::TravelClaimSubmissionWorker::STATSD_NOTIFY_SUCCESS) - .exactly(1).time - end + context 'travel claim throws timeout error' do + before do + allow_any_instance_of(Faraday::Connection).to receive(:post).and_raise(Faraday::TimeoutError) end - context 'send_sms returns an error' do - it 'handles the error' do - worker = described_class.new - expect(worker).to receive(:log_exception_to_sentry).with( - instance_of(Common::Exceptions::BackendServiceException), - { phone_number: patient_cell_phone_last_four, template_id: 'fake_success_template_id', - claim_number: claim_last4 }, - { error: :check_in_va_notify_job, team: 'check-in' } - ) - expect(StatsD).not_to receive(:increment) - .with(CheckIn::TravelClaimSubmissionWorker::STATSD_NOTIFY_SUCCESS) - expect(StatsD).to receive(:increment) - .with(CheckIn::TravelClaimSubmissionWorker::STATSD_NOTIFY_ERROR).exactly(1).time - - Sidekiq::Testing.inline! do - VCR.use_cassette('check_in/vanotify/send_sms_403_forbidden', match_requests_on: [:host]) do - VCR.use_cassette('check_in/btsss/submit_claim/submit_claim_200', match_requests_on: [:host]) do - expect { worker.perform(uuid, appt_date) }.to raise_error(Common::Exceptions::BackendServiceException) - end - end - end - end - end + it 'throws timeout exception and sends notification with error message' do + worker = described_class.new + notify_client = double - context 'travel claim returns success with patient cell phone' do - before do - allow(Flipper).to receive(:enabled?).with('check_in_experience_mock_enabled').and_return(true) - end + expect(VaNotify::Service).to receive(:new).with(Settings.vanotify.services.check_in.api_key) + .and_return(notify_client) - it 'sends notification with success template' do - worker = described_class.new - notify_client = double - - expect(VaNotify::Service).to receive(:new).with(Settings.vanotify.services.check_in.api_key) - .and_return(notify_client) - expect(notify_client).to receive(:send_sms).with( - phone_number: patient_cell_phone, - template_id: 'fake_success_template_id', - sms_sender_id: 'fake_sms_sender_id', - personalisation: { claim_number: claim_last4, appt_date: notify_appt_date } - ) - expect(worker).not_to receive(:log_exception_to_sentry) - - Sidekiq::Testing.inline! do - VCR.use_cassette('check_in/btsss/submit_claim/submit_claim_200', match_requests_on: [:host]) do - worker.perform(uuid, appt_date) - end - end + expect(notify_client).to receive(:send_sms).with( + phone_number: patient_cell_phone, + template_id: 'cie_fake_error_template_id', + sms_sender_id: 'cie_fake_sms_sender_id', + personalisation: { claim_number: nil, appt_date: notify_appt_date } + ) - expect(StatsD).to have_received(:increment) - .with(CheckIn::TravelClaimSubmissionWorker::STATSD_BTSSS_SUCCESS).exactly(1).time - expect(StatsD).to have_received(:increment) - .with(CheckIn::TravelClaimSubmissionWorker::STATSD_NOTIFY_SUCCESS).exactly(1).time + Sidekiq::Testing.inline! do + worker.perform(uuid, appt_date) end + + expect(StatsD).to have_received(:increment).with(CheckIn::TravelClaimSubmissionWorker::CIE_STATSD_BTSSS_ERROR) + .exactly(1).time + expect(StatsD).to have_received(:increment).with(CheckIn::TravelClaimSubmissionWorker::STATSD_NOTIFY_SUCCESS) + .exactly(1).time end end end