Skip to content

Commit

Permalink
work on LocalBGS specs
Browse files Browse the repository at this point in the history
  • Loading branch information
nihil2501 committed Apr 26, 2024
1 parent 0c82c67 commit 847d3d5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
31 changes: 24 additions & 7 deletions modules/claims_api/lib/bgs_service/local_bgs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions modules/claims_api/spec/lib/claims_api/local_bgs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 847d3d5

Please sign in to comment.