Skip to content

Commit

Permalink
Updates test and shared vcr cassette.
Browse files Browse the repository at this point in the history
  • Loading branch information
stiehlrod committed Nov 22, 2024
1 parent a6a97f2 commit 384dfa7
Show file tree
Hide file tree
Showing 3 changed files with 922 additions and 755 deletions.
89 changes: 22 additions & 67 deletions modules/claims_api/spec/sidekiq/poa_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
require 'bgs_service/person_web_service'
require 'bgs_service/vet_record_web_service'

RSpec.describe ClaimsApi::PoaUpdater, type: :job, vcr: 'bgs/person_web_service/poa_updater' do
RSpec.describe ClaimsApi::PoaUpdater, type: :job, vcr: 'bgs/person_web_service/find_by_ssn' do
subject { described_class }

before do
Sidekiq::Job.clear_all
allow(Flipper).to receive(:enabled?).with(:claims_api_use_vet_record_service).and_return false
allow(Flipper).to receive(:enabled?).with(:claims_api_use_person_web_service).and_return false
allow(Flipper).to receive(:enabled?).with(:lighthouse_claims_api_v2_poa_va_notify).and_return false
end

let(:user) { FactoryBot.create(:user, :loa3) }
Expand All @@ -23,8 +24,8 @@
context "when call to BGS 'update_birls_record' is successful" do
context 'and the poaCode is retrieved successfully from the V2 2122a form data' do
it "updates the form's status and creates 'ClaimsApi::PoaVBMSUpdater' job" do
mock_service_by_flipper
use_person_web_service_flipper_service
use_vet_record_web_service_flipper
use_person_web_service_flipper
expect(ClaimsApi::PoaVBMSUpdater).to receive(:perform_async)

poa = create_poa
Expand Down Expand Up @@ -54,8 +55,8 @@

context 'and record consent is granted' do
it "updates the form's status and creates 'ClaimsApi::PoaVBMSUpdater' job" do
mock_service_by_flipper
use_person_web_service_flipper_service
use_vet_record_web_service_flipper
use_person_web_service_flipper
expect(ClaimsApi::PoaVBMSUpdater).to receive(:perform_async)

poa = create_poa
Expand All @@ -71,8 +72,8 @@
context 'and record consent is not granted' do
context "because 'recordConsent' is false" do
it "updates the form's status but does not create a 'ClaimsApi::PoaVBMSUpdater' job" do
mock_service_by_flipper
use_person_web_service_flipper_service
use_vet_record_web_service_flipper
use_person_web_service_flipper
expect(ClaimsApi::PoaVBMSUpdater).not_to receive(:perform_async)

poa = create_poa
Expand All @@ -87,8 +88,8 @@

context "because a limitation exists in 'consentLimits'" do
it "updates the form's status but does not create a 'ClaimsApi::PoaVBMSUpdater' job" do
mock_service_by_flipper
use_person_web_service_flipper_service
use_vet_record_web_service_flipper
use_person_web_service_flipper
expect(ClaimsApi::PoaVBMSUpdater).not_to receive(:perform_async)

poa = create_poa
Expand All @@ -105,8 +106,8 @@

context "when call to BGS 'update_birls_record' fails" do
it "updates the form's status and does not create a 'ClaimsApi::PoaVBMSUpdater' job" do
mock_service_by_flipper
use_person_web_service_flipper_service
allow(Flipper).to receive(:enabled?).with(:claims_api_use_vet_record_service).and_return true

allow_any_instance_of(ClaimsApi::VetRecordWebService).to receive(:update_birls_record).and_return(
return_code: 'some error code'
)
Expand All @@ -122,15 +123,17 @@

context 'deciding to send a VA Notify email' do
before do
mock_service_by_flipper
use_person_web_service_flipper_service
use_vet_record_web_service_flipper
use_person_web_service_flipper
end

let(:poa) { create_poa }
let(:header_key) { ClaimsApi::V2::Veterans::PowerOfAttorney::BaseController::VA_NOTIFY_KEY }

context 'when the header key and rep are present' do
it 'sends the vanotify job' do
allow(Flipper).to receive(:enabled?).with(:lighthouse_claims_api_v2_poa_va_notify).and_return true

poa.auth_headers.merge!({
header_key => 'this_value'
})
Expand Down Expand Up @@ -196,46 +199,6 @@
end
end

context 'when the claims_api_use_person_web_service flipper is on' do
let(:person_web_service) { instance_double(ClaimsApi::PersonWebService) }

before do
allow(Flipper).to receive(:enabled?).with(:lighthouse_claims_api_v2_poa_va_notify).and_return false
allow(Flipper).to receive(:enabled?).with(:claims_api_use_vet_record_service).and_return true
allow(ClaimsApi::PersonWebService).to receive(:new).with(external_uid: anything,
external_key: anything)
.and_return(person_web_service)
allow(person_web_service).to receive(:find_by_ssn).and_return({ file_nbr: '796111863' })
end

it 'calls local bgs services instead of bgs-ext' do
poa = create_poa

subject.new.perform(poa.id)
expect(person_web_service).to have_received(:find_by_ssn)
end
end

context 'when the claims_api_use_vet_record_service flipper is on' do
let(:vet_record_web_service) { instance_double(ClaimsApi::VetRecordWebService) }

before do
allow(Flipper).to receive(:enabled?).with(:lighthouse_claims_api_v2_poa_va_notify).and_return false
allow(Flipper).to receive(:enabled?).with(:claims_api_use_vet_record_service).and_return true
allow(ClaimsApi::PersonWebService).to receive(:new).with(external_uid: anything,
external_key: anything)
.and_return(vet_record_web_service)
allow(vet_record_web_service).to receive(:update_birls_record).and_return({ return_code: 'BMOD0001' })
end

it 'calls local bgs services instead of bgs-ext' do
poa = create_poa

subject.new.perform(poa.id)
expect(vet_record_web_service).to have_received(:update_birls_record)
end
end

private

def create_poa
Expand All @@ -245,29 +208,21 @@ def create_poa
poa
end

def mock_service_by_flipper
def use_vet_record_web_service_flipper
if Flipper.enabled? :claims_api_use_vet_record_service
create_mock_local_bgs_service
allow_any_instance_of(ClaimsApi::VetRecordWebService).to receive(:update_birls_record)
.and_return({ return_code: 'BMOD0001' })
else
create_mock_bgs_ext_service
allow_any_instance_of(BGS::VetRecordWebService).to receive(:update_birls_record)
.and_return({ return_code: 'BMOD0001' })
end
end

def use_person_web_service_flipper_service
def use_person_web_service_flipper
if Flipper.enabled? :claims_api_use_person_web_service
allow_any_instance_of(ClaimsApi::PersonWebService).to receive(:find_by_ssn).and_return({ file_nbr: '123456789' })
else
allow_any_instance_of(ClaimsApi::LocalBGS).to receive(:find_by_ssn).and_return({ file_nbr: '123456789' })
end
end

def create_mock_bgs_ext_service
allow_any_instance_of(BGS::VetRecordWebService).to receive(:update_birls_record)
.and_return({ return_code: 'BMOD0001' })
end

def create_mock_local_bgs_service
allow_any_instance_of(ClaimsApi::VetRecordWebService).to receive(:update_birls_record)
.and_return({ return_code: 'BMOD0001' })
end
end
Loading

0 comments on commit 384dfa7

Please sign in to comment.