Skip to content

Commit

Permalink
Adds tests for flipper.
Browse files Browse the repository at this point in the history
  • Loading branch information
stiehlrod committed Nov 26, 2024
1 parent 23aabb1 commit 62ecd17
Show file tree
Hide file tree
Showing 2 changed files with 914 additions and 315 deletions.
74 changes: 33 additions & 41 deletions modules/claims_api/spec/sidekiq/poa_updater_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# frozen_string_literal: true

require 'rails_helper'
require 'bgs_service/person_web_service'
require 'bgs_service/vet_record_web_service'

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

before do
Expand All @@ -25,8 +22,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
use_vet_record_web_service_flipper
use_person_web_service_flipper
allow(Flipper).to receive(:enabled?).with(:claims_api_use_person_web_service).and_return false
create_mock_lighthouse_service
expect(ClaimsApi::PoaVBMSUpdater).to receive(:perform_async)

poa = create_poa
Expand Down Expand Up @@ -56,8 +53,7 @@

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

poa = create_poa
Expand All @@ -73,8 +69,7 @@
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
use_vet_record_web_service_flipper
use_person_web_service_flipper
create_mock_lighthouse_service
expect(ClaimsApi::PoaVBMSUpdater).not_to receive(:perform_async)

poa = create_poa
Expand All @@ -89,8 +84,7 @@

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

poa = create_poa
Expand All @@ -107,9 +101,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
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(
create_mock_lighthouse_service
allow_any_instance_of(BGS::VetRecordWebService).to receive(:update_birls_record).and_return(
return_code: 'some error code'
)
expect(ClaimsApi::PoaVBMSUpdater).not_to receive(:perform_async)
Expand All @@ -124,17 +117,15 @@

context 'deciding to send a VA Notify email' do
before do
use_vet_record_web_service_flipper
use_person_web_service_flipper
create_mock_lighthouse_service
allow(Flipper).to receive(:enabled?).with(:lighthouse_claims_api_v2_poa_va_notify).and_return true
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 All @@ -148,6 +139,7 @@

context 'when the flipper is on' do
it 'does not send the vanotify job' do
allow(Flipper).to receive(:enabled?).with(:lighthouse_claims_api_v2_poa_va_notify).and_return false
Flipper.disable(:lighthouse_claims_api_v2_poa_va_notify)

poa.auth_headers.merge!({
Expand Down Expand Up @@ -202,26 +194,38 @@

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

before do
allow(Flipper).to receive(:enabled?).with(:claims_api_use_person_web_service).and_return true
allow(Flipper).to receive(:enabled?).with(:claims_api_use_vet_record_web_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 person web service 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

describe '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(:claims_api_use_vet_record_service).and_return true
allow(ClaimsApi::VetRecordWebService).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' })
.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
it 'calls local bgs vet record service instead of bgs-ext' do
poa = create_poa
subject.new.perform(poa.id)

expect(person_web_service).to have_received(:find_by_ssn)
expect(vet_record_web_service).to have_received(:update_birls_record)
end
end
Expand All @@ -235,21 +239,9 @@ def create_poa
poa
end

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

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
def create_mock_lighthouse_service
allow_any_instance_of(BGS::PersonWebService).to receive(:find_by_ssn).and_return({ file_nbr: '123456789' })
allow_any_instance_of(BGS::VetRecordWebService).to receive(:update_birls_record)
.and_return({ return_code: 'BMOD0001' })
end
end
Loading

0 comments on commit 62ecd17

Please sign in to comment.