Skip to content

Commit

Permalink
Migrate the form526_rapid_ready_for_decision_concern to ApiProviderFa…
Browse files Browse the repository at this point in the history
…ctory (#12524)

* migrate the form526_rapid_ready_for_decision_concern to apiProviderFactory

* fixed form526_submission_spec

* Fixed submit_form526_all_claim_spec

* bdex/57215: clean up unit tests

* bdex/57215: clean up unit tests

---------

Co-authored-by: lightning <[email protected]>
  • Loading branch information
sethdarragile6 and aurora-a-k-a-lightning authored May 3, 2023
1 parent 0340421 commit 497a65d
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def rated_disabilities
application = params['application'] || 'form526'
settings = Settings.lighthouse.veteran_verification[application]
service = ApiProviderFactory.rated_disabilities_service_provider(
@current_user
{ icn: @current_user.icn.to_s, auth_headers: }
)

response = service.get_rated_disabilities(settings.access_token.client_id, settings.access_token.rsa_key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,13 @@ def open_claims

# fetch, memoize, and return all of the veteran's rated disabilities from EVSS
def all_rated_disabilities
settings = Settings.lighthouse.veteran_verification.form526
service = ApiProviderFactory.rated_disabilities_service_provider(
# TODO: get ICN from job workflow
{ auth_headers:, icn: '' }
)
@all_rated_disabilities ||= begin
response = EVSS::DisabilityCompensationForm::Service.new(auth_headers).get_rated_disabilities
response = service.get_rated_disabilities(settings.access_token.client_id, settings.access_token.rsa_key)
response.rated_disabilities
end
end
Expand Down
5 changes: 4 additions & 1 deletion app/models/form_profiles/va_526ez.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ def initialize_rated_disabilities_information

settings = Settings.lighthouse.veteran_verification.form526
service = ApiProviderFactory.rated_disabilities_service_provider(
user
{
auth_headers: EVSS::DisabilityCompensationAuthHeaders.new(user).add_headers(EVSS::AuthHeaders.new(user).to_h),
icn: user.icn.to_s
}
)
response = service.get_rated_disabilities(settings.access_token.client_id, settings.access_token.rsa_key)

Expand Down
9 changes: 6 additions & 3 deletions lib/disability_compensation/factories/api_provider_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class ApiProviderFactory
FEATURE_TOGGLE_RATED_DISABILITIES = 'disability_compensation_lighthouse_rated_disabilities_provider'
FEATURE_TOGGLE_INTENT_TO_FILE = 'disability_compensation_lighthouse_intent_to_file_provider'

def self.rated_disabilities_service_provider(current_user, api_provider = nil)
# @param [hash] options: options to provide auth_headers
# @option options [hash] :auth_headers auth headers for the EVSS request
# @option options [string] :icn Veteran's ICN
def self.rated_disabilities_service_provider(options, api_provider = nil)
api_provider ||= if Flipper.enabled?(FEATURE_TOGGLE_RATED_DISABILITIES)
API_PROVIDER[:lighthouse]
else
Expand All @@ -25,9 +28,9 @@ def self.rated_disabilities_service_provider(current_user, api_provider = nil)

case api_provider
when API_PROVIDER[:evss]
EvssRatedDisabilitiesProvider.new(current_user)
EvssRatedDisabilitiesProvider.new(options[:auth_headers])
when API_PROVIDER[:lighthouse]
LighthouseRatedDisabilitiesProvider.new(current_user)
LighthouseRatedDisabilitiesProvider.new(options[:icn])
else
raise NotImplementedError, 'No known Rated Disabilities Api Provider type provided'
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

class EvssRatedDisabilitiesProvider
include RatedDisabilitiesProvider
def initialize(current_user)
@service = EVSS::DisabilityCompensationForm::Service.new(auth_headers(current_user))

def initialize(auth_headers)
@service = EVSS::DisabilityCompensationForm::Service.new(auth_headers)
end

# @param [string] _client_id: (unused) the lighthouse_client_id requested from Lighthouse
Expand All @@ -16,10 +17,6 @@ def get_rated_disabilities(_client_id = nil, _rsa_key_path = nil)
transform(data)
end

def auth_headers(current_user)
EVSS::DisabilityCompensationAuthHeaders.new(current_user).add_headers(EVSS::AuthHeaders.new(current_user).to_h)
end

def transform(data)
rated_disabilities =
data[:rated_disabilities].map do |rated_disability|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
class LighthouseRatedDisabilitiesProvider
include RatedDisabilitiesProvider

def initialize(current_user)
@current_user = current_user
def initialize(icn)
@service = VeteranVerification::Service.new
@icn = icn
end

# @param [string] lighthouse_client_id: the lighthouse_client_id requested from Lighthouse
# @param [string] lighthouse_rsa_key_path: path to the private RSA key used to create the lighthouse_client_id
def get_rated_disabilities(lighthouse_client_id, lighthouse_rsa_key_path)
auth_params = {
launch: Base64.encode64(JSON.generate({ patient: @current_user.icn.to_s }))
launch: Base64.encode64(JSON.generate({ patient: @icn }))
}
data = @service.get_rated_disabilities(
lighthouse_client_id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'rails_helper'
require 'disability_compensation/factories/api_provider_factory'

RSpec.describe EVSS::DisabilityCompensationForm::SubmitForm526AllClaim, type: :job do
subject { described_class }
Expand Down Expand Up @@ -32,6 +33,7 @@

before do
cassettes.each { |cassette| VCR.insert_cassette(cassette) }
Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_RATED_DISABILITIES)
end

after do
Expand Down Expand Up @@ -73,7 +75,9 @@ def expect_retryable_error(error_class)
[open_claims_cassette, rated_disabilities_cassette, submit_form_cassette, mas_cassette]
end

before { allow(StatsD).to receive(:increment) }
before do
allow(StatsD).to receive(:increment)
end

it 'sends form526 to the MAS endpoint successfully' do
subject.perform_async(submission.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

RSpec.describe ApiProviderFactory do
let(:current_user) { build(:user, :loa3) }
let(:auth_headers) do
EVSS::DisabilityCompensationAuthHeaders.new(current_user).add_headers(EVSS::AuthHeaders.new(current_user).to_h)
end
let(:icn) { current_user.icn.to_s }

context 'rated_disabilities' do
it 'provides an EVSS rated disabilities provider' do
Expand All @@ -17,23 +21,23 @@

it 'provides rated disabilities provider based on Flipper' do
Flipper.enable(ApiProviderFactory::FEATURE_TOGGLE_RATED_DISABILITIES)
provider = ApiProviderFactory.rated_disabilities_service_provider(current_user)
provider = ApiProviderFactory.rated_disabilities_service_provider({ auth_headers:, icn: })
expect(provider.class).to equal(LighthouseRatedDisabilitiesProvider)

Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_RATED_DISABILITIES)
provider = ApiProviderFactory.rated_disabilities_service_provider(current_user)
provider = ApiProviderFactory.rated_disabilities_service_provider({ auth_headers:, icn: })
expect(provider.class).to equal(EvssRatedDisabilitiesProvider)
end

it 'throw error if provider unknown' do
expect do
ApiProviderFactory.rated_disabilities_service_provider(current_user, :random)
ApiProviderFactory.rated_disabilities_service_provider({ auth_headers:, icn: }, :random)
end.to raise_error NotImplementedError
end

def provider(api_provider = nil)
ApiProviderFactory.rated_disabilities_service_provider(
current_user,
{ auth_headers:, icn: },
api_provider
)
end
Expand Down
4 changes: 4 additions & 0 deletions spec/models/form526_submission_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'rails_helper'
require 'disability_compensation/factories/api_provider_factory'

RSpec.describe Form526Submission do
subject do
Expand Down Expand Up @@ -888,6 +889,7 @@
after { VCR.eject_cassette('evss/disability_compensation_form/rated_disabilities_with_non_service_connected') }

context 'when all corresponding rated disabilities are not service-connected' do
Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_RATED_DISABILITIES)
let(:form_json_filename) { 'only_526_asthma.json' }

it 'returns true' do
Expand All @@ -896,6 +898,7 @@
end

context 'when some but not all corresponding rated disabilities are not service-connected' do
Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_RATED_DISABILITIES)
let(:form_json_filename) { 'only_526_two_rated_disabilities.json' }

it 'returns false' do
Expand All @@ -904,6 +907,7 @@
end

context 'when some disabilities do not have a ratedDisabilityId yet' do
Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_RATED_DISABILITIES)
let(:form_json_filename) { 'only_526_mixed_action_disabilities.json' }

it 'returns false' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@

shared_examples 'rated disabilities provider' do
# this is used to instantiate any RateDisabilitiesProvider with a current_user
subject { described_class.new(current_user) }
subject do
described_class.new(
{
auth_headers: EVSS::DisabilityCompensationAuthHeaders
.new(current_user)
.add_headers(EVSS::AuthHeaders.new(current_user).to_h),
icn: ''
}
)
end

it { is_expected.to respond_to(:get_rated_disabilities) }
end

0 comments on commit 497a65d

Please sign in to comment.