From 847d3d5ac38b46156986c1d917fc7e51a9f10afb Mon Sep 17 00:00:00 2001 From: Oren Mittman Date: Fri, 26 Apr 2024 04:19:53 -0400 Subject: [PATCH] work on LocalBGS specs --- .../claims_api/lib/bgs_service/local_bgs.rb | 31 ++++++++++++++----- .../claims_api/local_bgs_refactored_spec.rb | 15 ++++++--- .../spec/lib/claims_api/local_bgs_spec.rb | 8 +++++ 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/modules/claims_api/lib/bgs_service/local_bgs.rb b/modules/claims_api/lib/bgs_service/local_bgs.rb index af4480bdf3c..fd891e7bc74 100644 --- a/modules/claims_api/lib/bgs_service/local_bgs.rb +++ b/modules/claims_api/lib/bgs_service/local_bgs.rb @@ -404,19 +404,36 @@ def jrn # This has to come after all `LocalBGS` method definitions. prepend( Module.new do + class << self + def prepended(klass) + # This is just exposed so that we are able to stub the proxied + # method in `RSpec` when we desire. + klass.attr_reader :refactored + end + end + + def initialize(...) + # There is no internal state that changes for instances of this class. + # It is properly stateless. This also means that there is no + # circumstance where state would ever need to be synchronized over + # time between the refactored and original instances of this module. + @refactored = LocalBGSRefactored.new(...) + super + end + meths = LocalBGS.private_instance_methods(false) + - LocalBGS.instance_methods(false) - - [:initialize] + LocalBGS.instance_methods(false) - [ + :initialize, + # These `attr_accessor` methods are not called anywhere as far as I + # can tell. + :external_uid, + :external_key + ] meths.each do |meth| define_method(meth) do |*args, **kwargs, &block| if Flipper.enabled?(:claims_api_local_bgs_refactor) - @refactored ||= - LocalBGSRefactored.new( - external_uid:, - external_key: - ) @refactored.send( meth, diff --git a/modules/claims_api/spec/lib/claims_api/local_bgs_refactored_spec.rb b/modules/claims_api/spec/lib/claims_api/local_bgs_refactored_spec.rb index b8e94b87dfe..9636d8d9994 100644 --- a/modules/claims_api/spec/lib/claims_api/local_bgs_refactored_spec.rb +++ b/modules/claims_api/spec/lib/claims_api/local_bgs_refactored_spec.rb @@ -2,12 +2,11 @@ require 'rails_helper' require 'bgs_service/local_bgs' -require 'claims_api/error/soap_error_handler' describe ClaimsApi::LocalBGS do subject { described_class.new external_uid: 'xUid', external_key: 'xKey' } - let(:soap_error_handler) { ClaimsApi::SoapErrorHandler } + let(:soap_error_handler) { ClaimsApi::LocalBGSRefactored::ErrorHandler } describe '#find_poa_by_participant_id' do it 'responds as expected, with extra ClaimsApi::Logger logging' do @@ -63,7 +62,9 @@ it 'returns an empty array' do expect(error_message.count).to eq(2) # trick the claims count check # error message should trigger return - allow(subject_instance).to receive(:find_benefit_claims_status_by_ptcpnt_id).with(id).and_return(error_message) + allow(subject_instance.refactored).to( + receive(:find_benefit_claims_status_by_ptcpnt_id).with(id).and_return(error_message) + ) expect(subject.all(id)).to eq([]) # verify correct return end end @@ -73,7 +74,9 @@ VCR.use_cassette('claims_api/bgs/claims/claims_trimmed_down') do claims = subject_instance.find_benefit_claims_status_by_ptcpnt_id('600061742') claims[:benefit_claims_dto][:benefit_claim] = claims[:benefit_claims_dto][:benefit_claim][0] - allow(subject_instance).to receive(:find_benefit_claims_status_by_ptcpnt_id).with(id).and_return(claims) + allow(subject_instance.refactored).to( + receive(:find_benefit_claims_status_by_ptcpnt_id).with(id).and_return(claims) + ) begin ret = subject_instance.send(:transform_bgs_claims_to_evss, claims) @@ -90,7 +93,9 @@ context 'when an empty array gets returned it still does not pass the count check' do it 'returns an empty array' do # error message should trigger return - allow(subject_instance).to receive(:find_benefit_claims_status_by_ptcpnt_id).with(id).and_return(empty_array) + allow(subject_instance.refactored).to( + receive(:find_benefit_claims_status_by_ptcpnt_id).with(id).and_return(empty_array) + ) expect(subject.all(id)).to eq([]) # verify correct return end end diff --git a/modules/claims_api/spec/lib/claims_api/local_bgs_spec.rb b/modules/claims_api/spec/lib/claims_api/local_bgs_spec.rb index 482c897a6d8..7f7af23c280 100644 --- a/modules/claims_api/spec/lib/claims_api/local_bgs_spec.rb +++ b/modules/claims_api/spec/lib/claims_api/local_bgs_spec.rb @@ -7,6 +7,14 @@ describe ClaimsApi::LocalBGS do subject { described_class.new external_uid: 'xUid', external_key: 'xKey' } + before do + allow(Flipper).to( + receive(:enabled?) + .with(:claims_api_local_bgs_refactor) + .and_return(false) + ) + end + let(:soap_error_handler) { ClaimsApi::SoapErrorHandler.new } describe '#find_poa_by_participant_id' do