diff --git a/app/controllers/concerns/inherited_proofing_concern.rb b/app/controllers/concerns/inherited_proofing_concern.rb index 57b644e7ece..93a0add6f74 100644 --- a/app/controllers/concerns/inherited_proofing_concern.rb +++ b/app/controllers/concerns/inherited_proofing_concern.rb @@ -27,4 +27,38 @@ def va_inherited_proofing_auth_code def va_inherited_proofing_auth_code_params_key 'inherited_proofing_auth' end + + # Service Provider-agnostic members for now. + # Think about putting this in a factory(ies). + + def inherited_proofing_service + inherited_proofing_service_class.new inherited_proofing_service_provider_data + end + + def inherited_proofing_service_class + raise 'Inherited Proofing is not enabled' unless IdentityConfig.store.inherited_proofing_enabled + + if va_inherited_proofing? + if IdentityConfig.store.va_inherited_proofing_mock_enabled + return Idv::InheritedProofing::Va::Mocks::Service + end + return Idv::InheritedProofing::Va::Service + end + + raise 'Inherited proofing service class could not be identified' + end + + def inherited_proofing_form(payload_hash) + return Idv::InheritedProofing::Va::Form.new payload_hash: payload_hash if va_inherited_proofing? + + raise 'Inherited proofing form could not be identified' + end + + def inherited_proofing_service_provider_data + if va_inherited_proofing? + { auth_code: va_inherited_proofing_auth_code } + else + {} + end + end end diff --git a/app/services/idv/inherited_proofing/va/mocks/service.rb b/app/services/idv/inherited_proofing/va/mocks/service.rb index 0358b2c961f..0a580d60b2d 100644 --- a/app/services/idv/inherited_proofing/va/mocks/service.rb +++ b/app/services/idv/inherited_proofing/va/mocks/service.rb @@ -35,8 +35,8 @@ class Service }, }.freeze - def initialize(auth_code) - @auth_code = auth_code + def initialize(service_provider_data) + @auth_code = service_provider_data[:auth_code] end def execute diff --git a/app/services/idv/inherited_proofing/va/service.rb b/app/services/idv/inherited_proofing/va/service.rb index 094d9747ca2..fc7e70cd91e 100644 --- a/app/services/idv/inherited_proofing/va/service.rb +++ b/app/services/idv/inherited_proofing/va/service.rb @@ -9,8 +9,8 @@ class Service attr_reader :auth_code - def initialize(auth_code) - @auth_code = auth_code + def initialize(service_provider_data) + @auth_code = service_provider_data[:auth_code] end # Calls the endpoint and returns the decrypted response. diff --git a/scripts/inherited_proofing/va/user_attributes/test_server.rb b/scripts/inherited_proofing/va/user_attributes/test_server.rb index 894f68f5593..ce5a65b2e9b 100644 --- a/scripts/inherited_proofing/va/user_attributes/test_server.rb +++ b/scripts/inherited_proofing/va/user_attributes/test_server.rb @@ -10,7 +10,7 @@ class TestServer < Idv::InheritedProofing::Va::Service attr_reader :base_uri def initialize(auth_code:, private_key_file: nil, base_uri: nil) - super auth_code + super({ auth_code: auth_code }) if private_key_file.present? @private_key_file = force_tmp_private_key_file_name(private_key_file) diff --git a/spec/controllers/concerns/inherited_proofing_concern_spec.rb b/spec/controllers/concerns/inherited_proofing_concern_spec.rb new file mode 100644 index 00000000000..208d1159f80 --- /dev/null +++ b/spec/controllers/concerns/inherited_proofing_concern_spec.rb @@ -0,0 +1,151 @@ +require 'rails_helper' + +RSpec.describe InheritedProofingConcern do + subject do + Class.new do + include InheritedProofingConcern + end.new + end + + before do + allow(IdentityConfig.store).to receive(:inherited_proofing_enabled).and_return(true) + allow(subject).to receive(:va_inherited_proofing_auth_code).and_return auth_code + end + + let(:auth_code) { Idv::InheritedProofing::Va::Mocks::Service::VALID_AUTH_CODE } + let(:payload_hash) { Idv::InheritedProofing::Va::Mocks::Service::PAYLOAD_HASH } + + describe '#va_inherited_proofing?' do + context 'when the va auth code is present' do + it 'returns true' do + expect(subject.va_inherited_proofing?).to eq true + end + end + + context 'when the va auth code is not present' do + let(:auth_code) { nil } + + it 'returns false' do + expect(subject.va_inherited_proofing?).to eq false + end + end + end + + describe '#va_inherited_proofing_auth_code_params_key' do + it 'returns the correct va auth code url query param key' do + expect(subject.va_inherited_proofing_auth_code_params_key).to eq 'inherited_proofing_auth' + end + end + + describe '#inherited_proofing_service_class' do + context 'when va inherited proofing is disabled' do + before do + allow(IdentityConfig.store).to receive(:inherited_proofing_enabled).and_return(false) + end + + it 'raises an error' do + expect do + subject.inherited_proofing_service_class + end.to raise_error 'Inherited Proofing is not enabled' + end + end + + context 'when there is a va inherited proofing request' do + context 'when va mock proofing is turned on' do + before do + allow(IdentityConfig.store).to \ + receive(:va_inherited_proofing_mock_enabled).and_return(true) + end + + it 'returns the correct service provider service class' do + expect(subject.inherited_proofing_service_class).to \ + eq Idv::InheritedProofing::Va::Mocks::Service + end + end + + context 'when va mock proofing is turned off' do + before do + allow(IdentityConfig.store).to \ + receive(:va_inherited_proofing_mock_enabled).and_return(false) + end + + it 'returns the correct service provider service class' do + expect(subject.inherited_proofing_service_class).to eq Idv::InheritedProofing::Va::Service + end + end + end + + context 'when the inherited proofing request cannot be identified' do + let(:auth_code) { nil } + + it 'raises an error' do + expect do + subject.inherited_proofing_service_class + end.to raise_error 'Inherited proofing service class could not be identified' + end + end + end + + describe '#inherited_proofing_service' do + context 'when there is a va inherited proofing request' do + context 'when va mock proofing is turned on' do + before do + allow(IdentityConfig.store).to \ + receive(:va_inherited_proofing_mock_enabled).and_return(true) + end + + it 'returns the correct service provider service class' do + expect(subject.inherited_proofing_service).to \ + be_kind_of Idv::InheritedProofing::Va::Mocks::Service + end + end + + context 'when va mock proofing is turned off' do + before do + allow(IdentityConfig.store).to \ + receive(:va_inherited_proofing_mock_enabled).and_return(false) + end + + it 'returns the correct service provider service class' do + expect(subject.inherited_proofing_service).to \ + be_kind_of Idv::InheritedProofing::Va::Service + end + end + end + end + + describe '#inherited_proofing_form' do + context 'when there is a va inherited proofing request' do + it 'returns the correct form' do + expect(subject.inherited_proofing_form(payload_hash)).to \ + be_kind_of Idv::InheritedProofing::Va::Form + end + end + + context 'when the inherited proofing request cannot be identified' do + let(:auth_code) { nil } + + it 'raises an error' do + expect { subject.inherited_proofing_form(payload_hash) }.to \ + raise_error 'Inherited proofing form could not be identified' + end + end + end + + describe '#inherited_proofing_service_provider_data' do + context 'when there is a va inherited proofing request' do + it 'returns the correct service provider-specific data' do + expect(subject.inherited_proofing_service_provider_data).to \ + eq({ auth_code: auth_code }) + end + end + + context 'when the inherited proofing request cannot be identified' do + let(:auth_code) { nil } + + it 'returns an empty hash' do + expect(subject.inherited_proofing_service_provider_data).to eq({}) + end + end + end +end diff --git a/spec/features/services/idv/inherited_proofing/va/mocks/service_spec.rb b/spec/features/services/idv/inherited_proofing/va/mocks/service_spec.rb index 7e44e984fdb..88d8c7d429f 100644 --- a/spec/features/services/idv/inherited_proofing/va/mocks/service_spec.rb +++ b/spec/features/services/idv/inherited_proofing/va/mocks/service_spec.rb @@ -3,7 +3,9 @@ RSpec.describe 'Inherited Proofing VA API Proofer Service' do subject(:form) { Idv::InheritedProofing::Va::Form.new(payload_hash: proofer_results) } - let(:proofer_results) { Idv::InheritedProofing::Va::Mocks::Service.new(auth_code).execute } + let(:proofer_results) do + Idv::InheritedProofing::Va::Mocks::Service.new({ auth_code: auth_code }).execute + end let(:auth_code) { Idv::InheritedProofing::Va::Mocks::Service::VALID_AUTH_CODE } context 'when used with the VA Inherited Proofing Response Form' do diff --git a/spec/services/idv/inherited_proofing/va/mocks/service_spec.rb b/spec/services/idv/inherited_proofing/va/mocks/service_spec.rb index 83a88234723..8d0fcf5fc05 100644 --- a/spec/services/idv/inherited_proofing/va/mocks/service_spec.rb +++ b/spec/services/idv/inherited_proofing/va/mocks/service_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' RSpec.describe Idv::InheritedProofing::Va::Mocks::Service do - subject { described_class.new(auth_code) } + subject { described_class.new({ auth_code: auth_code }) } let(:auth_code) { described_class::VALID_AUTH_CODE } describe '#initialize' do diff --git a/spec/services/idv/inherited_proofing/va/service_spec.rb b/spec/services/idv/inherited_proofing/va/service_spec.rb index b53560ccfdf..81695a06e1e 100644 --- a/spec/services/idv/inherited_proofing/va/service_spec.rb +++ b/spec/services/idv/inherited_proofing/va/service_spec.rb @@ -10,7 +10,7 @@ include_context 'va_api_context' include_context 'va_user_context' - subject(:service) { described_class.new auth_code } + subject(:service) { described_class.new(auth_code: auth_code) } before do allow(service).to receive(:private_key).and_return(private_key)