Skip to content

Commit

Permalink
Add DisabilityMaxRating client, configuration, and tests with get_rat…
Browse files Browse the repository at this point in the history
…ings update (#20483)

* add DisabilityMaxRating client, configuration, and tests with get_ratings update

* add spec for the configuration

* add codeowners for client files

* fix tests

* fix tests

* add new disability max rating cassette and update/add form profile specs

* update form_profile_spec tests

* update per pr feedback

* update codeowners

* update module name

* Use base_path from Configuration in Client

* update per pr feedback

* remove comments
  • Loading branch information
asiisii authored Feb 3, 2025
1 parent f738008 commit 062d788
Show file tree
Hide file tree
Showing 16 changed files with 488 additions and 50 deletions.
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,7 @@ lib/decision_review @department-of-veterans-affairs/benefits-decision-reviews-be
lib/decision_review_v1 @department-of-veterans-affairs/benefits-decision-reviews-be @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
lib/dependents @department-of-veterans-affairs/benefits-dependents-management @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
lib/disability_compensation @department-of-veterans-affairs/Disability-Experience @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group @department-of-veterans-affairs/dbex-trex @department-of-veterans-affairs/benefits-disability-2
lib/disability_max_ratings @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group @department-of-veterans-affairs/benefits-vro-engineers @department-of-veterans-affairs/benefits-employee-exp-engineers
lib/efolder @department-of-veterans-affairs/vsa-debt-resolution @department-of-veterans-affairs/backend-review-group
lib/efolder/service.rb @department-of-veterans-affairs/vsa-debt-resolution @department-of-veterans-affairs/backend-review-group
lib/evss/auth_headers.rb @department-of-veterans-affairs/vsa-debt-resolution @department-of-veterans-affairs/backend-review-group
Expand Down Expand Up @@ -1453,6 +1454,7 @@ spec/lib/decision_review @department-of-veterans-affairs/benefits-decision-revie
spec/lib/decision_review_v1 @department-of-veterans-affairs/benefits-decision-reviews-be @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/lib/dependents/monitor_spec.rb @department-of-veterans-affairs/benefits-dependents-management @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/lib/disability_compensation @department-of-veterans-affairs/Disability-Experience @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/lib/disability_max_ratings @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group @department-of-veterans-affairs/benefits-vro-engineers @department-of-veterans-affairs/benefits-employee-exp-engineers
spec/lib/efolder/service_spec.rb @department-of-veterans-affairs/vsa-debt-resolution @department-of-veterans-affairs/backend-review-group
spec/lib/evss/auth_headers_spec.rb @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/lib/evss/common_service_spec.rb @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
Expand Down Expand Up @@ -2090,6 +2092,7 @@ spec/support/vcr_cassettes/cypress_viewport_updater @department-of-veterans-affa
spec/support/vcr_cassettes/debts @department-of-veterans-affairs/vsa-debt-resolution @department-of-veterans-affairs/backend-review-group
spec/support/vcr_cassettes/decision_review @department-of-veterans-affairs/benefits-decision-reviews-be @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/support/vcr_cassettes/dgi @department-of-veterans-affairs/my-education-benefits @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/support/vcr_cassettes/disability_max_ratings @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group @department-of-veterans-affairs/benefits-vro-engineers @department-of-veterans-affairs/benefits-employee-exp-engineers
spec/support/vcr_cassettes/dmc @department-of-veterans-affairs/vsa-debt-resolution
spec/support/vcr_cassettes/dmc/download_pdf.yml @department-of-veterans-affairs/vsa-debt-resolution @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/support/vcr_cassettes/dmc/submit_to_vbs.yml @department-of-veterans-affairs/vsa-debt-resolution @department-of-veterans-affairs/backend-review-group @department-of-veterans-affairs/va-api-engineers
Expand Down
10 changes: 7 additions & 3 deletions app/services/claim_fast_tracking/max_rating_annotator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'virtual_regional_office/client'
require 'disability_max_ratings/client'

module ClaimFastTracking
class MaxRatingAnnotator
Expand Down Expand Up @@ -58,13 +59,16 @@ def self.diagnostic_code_type(rated_disability)

def self.get_ratings(diagnostic_codes, user)
if Flipper.enabled?(:disability_526_max_cfi_service_switch, user)
Rails.logger.info('New Max Ratings service triggered by feature flag, but implementation is pending')
# TODO: Handle the new logic for max ratings when switching to the new service
disability_max_ratings_client = DisabilityMaxRatings::Client.new
response = disability_max_ratings_client.post_for_max_ratings(diagnostic_codes)
else
vro_client = VirtualRegionalOffice::Client.new
response = vro_client.get_max_rating_for_diagnostic_codes(diagnostic_codes)
response.body['ratings']
end
response.body['ratings']
rescue Faraday::TimeoutError
Rails.logger.error 'Get Max Ratings Failed: Request timed out.'
nil
rescue Common::Client::Errors::ClientError => e
Rails.logger.error "Get Max Ratings Failed #{e.message}.", backtrace: e.backtrace
nil
Expand Down
1 change: 1 addition & 0 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ features:
disability_526_max_cfi_service_switch:
actor_type: user
description: Enables the use of the new Max Ratings CFI service instead of the VRO client for fetching max ratings.
enable_in_development: true
disability_compensation_flashes:
actor_type: user
description: enables sending flashes to BGS for disability_compensation submissions.
Expand Down
6 changes: 6 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,12 @@ virtual_regional_office:
expanded_classification_path: contention-classification/expanded-contention-classification
max_cfi_path: employee-experience/max-ratings

disability_max_ratings_api:
url: http://disability-max-ratings-api-dev.vfs.va.gov
ratings_path: /disability-max-ratings
open_timeout: 5
read_timeout: 10

# Settings for Test User Dashboard modules
test_user_dashboard:
env: dev
Expand Down
27 changes: 27 additions & 0 deletions lib/disability_max_ratings/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require 'disability_max_ratings/configuration'

module DisabilityMaxRatings
class Client < Common::Client::Base
include Common::Client::Concerns::Monitoring
configuration DisabilityMaxRatings::Configuration

STATSD_KEY_PREFIX = 'api.disability_max_ratings'

def post_for_max_ratings(diagnostic_codes_array)
with_monitoring do
params = { diagnostic_codes: diagnostic_codes_array }
perform(:post, Settings.disability_max_ratings_api.ratings_path, params.to_json, headers_hash)
end
end

private

def headers_hash
{
'Content-Type': 'application/json'
}
end
end
end
28 changes: 28 additions & 0 deletions lib/disability_max_ratings/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

require 'common/client/configuration/rest'
require 'common/client/middleware/response/raise_custom_error'

module DisabilityMaxRatings
class Configuration < Common::Client::Configuration::REST
self.open_timeout = Settings.disability_max_ratings_api.open_timeout
self.read_timeout = Settings.disability_max_ratings_api.read_timeout

def base_path
Settings.disability_max_ratings_api.url.to_s
end

def service_name
'DisabilityMaxRatingsApiClient'
end

def connection
Faraday.new(base_path, headers: base_request_headers, request: request_options) do |faraday|
faraday.use :breakers
faraday.use Faraday::Response::RaiseError
faraday.response :json, content_type: /\bjson/
faraday.adapter Faraday.default_adapter
end
end
end
end
53 changes: 53 additions & 0 deletions spec/lib/disability_max_ratings/client_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# frozen_string_literal: true

require 'rails_helper'
require 'disability_max_ratings/client'

RSpec.describe DisabilityMaxRatings::Client do
let(:client) { DisabilityMaxRatings::Client.new }
let(:max_ratings_params) { { diagnostic_codes: [1234] } }

describe 'making max rating requests' do
subject { client.post_for_max_ratings(max_ratings_params[:diagnostic_codes]) }

context 'valid requests' do
describe 'when requesting max ratings' do
let(:generic_response) do
double(
'disability max ratings response', status: 200,
body: {
ratings: [
diagnostic_code: 1234, max_rating: 100
]
}.as_json
)
end

before do
allow(client).to receive(:perform).and_return(generic_response)
end

it 'returns the API response' do
expect(subject).to eq generic_response
end
end
end

context 'unsuccessful requests' do
let(:error_state) do
double(
'disability max ratings response', status: 404,
body: { message: 'Something went wrong.' }.as_json
)
end

before do
allow(client).to receive(:perform).and_return(error_state)
end

it 'handles an error' do
expect(subject).to eq error_state
end
end
end
end
29 changes: 29 additions & 0 deletions spec/lib/disability_max_ratings/configuration_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require 'rails_helper'
require 'disability_max_ratings/configuration'

RSpec.describe DisabilityMaxRatings::Configuration do
subject { described_class.send(:new) }

describe '#base_path' do
it 'returns the correct base URL from the settings' do
expect(subject.base_path).to eq(Settings.disability_max_ratings_api.url.to_s)
end
end

describe '#service_name' do
it 'returns the DisabilityMaxRatingsApiClient service name' do
expect(subject.service_name).to eq('DisabilityMaxRatingsApiClient')
end
end

describe '#connection' do
it 'includes the correct middleware' do
connection = subject.connection

expect(connection.builder.handlers).to include(Faraday::Response::RaiseError)
expect(connection.builder.handlers).to include(Faraday::Response::Json)
end
end
end
81 changes: 73 additions & 8 deletions spec/models/form_profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
let(:user) { build(:user, :loa3, suffix: 'Jr.', address: build(:mpi_profile_address)) }

before do
Flipper.disable(:remove_pciu)
stub_evss_pciu(user)
described_class.instance_variable_set(:@mappings, nil)
Flipper.disable(:va_v3_contact_information_service)
Flipper.disable(:remove_pciu)
Flipper.disable('remove_pciu_2')
Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_PPIU_DIRECT_DEPOSIT)
allow(Flipper).to receive(:enabled?).and_call_original
allow(Flipper).to receive(:enabled?).with(:remove_pciu, anything).and_return(false)
allow(Flipper).to receive(:enabled?).with(:disability_526_max_cfi_service_switch, anything).and_return(false)
allow(Flipper).to receive(:enabled?).with(:va_v3_contact_information_service, anything)
.and_return(false)
allow(Flipper).to receive(:enabled?).with(ApiProviderFactory::FEATURE_TOGGLE_PPIU_DIRECT_DEPOSIT,
anything).and_return(false)
end

let(:street_check) { build(:street_check) }
Expand Down Expand Up @@ -1830,8 +1832,15 @@ def expect_prefilled(form_id)
end

it 'returns prefilled 21-526EZ' do
Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_RATED_DISABILITIES_FOREGROUND)
Flipper.disable(:disability_compensation_remove_pciu)
allow(Flipper).to receive(:enabled?)
.with(
ApiProviderFactory::FEATURE_TOGGLE_RATED_DISABILITIES_FOREGROUND,
anything
)
.and_return(false)

allow(Flipper).to receive(:enabled?).with(:disability_compensation_remove_pciu,
anything).and_return(false)
VCR.use_cassette('evss/pciu_address/address_domestic') do
VCR.use_cassette('evss/disability_compensation_form/rated_disabilities') do
VCR.use_cassette('evss/ppiu/payment_information') do
Expand All @@ -1845,6 +1854,31 @@ def expect_prefilled(form_id)
end
end
end

it 'returns prefilled 21-526EZ when disability_526_max_cfi_service_switch is enabled' do
allow(Flipper).to receive(:enabled?)
.with(
ApiProviderFactory::FEATURE_TOGGLE_RATED_DISABILITIES_FOREGROUND,
anything
)
.and_return(false)
allow(Flipper).to receive(:enabled?).with(:disability_compensation_remove_pciu,
anything).and_return(false)
allow(Flipper).to receive(:enabled?).with(:disability_526_max_cfi_service_switch,
anything).and_return(true)
VCR.use_cassette('evss/pciu_address/address_domestic') do
VCR.use_cassette('evss/disability_compensation_form/rated_disabilities') do
VCR.use_cassette('evss/ppiu/payment_information') do
VCR.use_cassette('va_profile/military_personnel/service_history_200_many_episodes',
allow_playback_repeats: true, match_requests_on: %i[uri method body]) do
VCR.use_cassette('/disability-max-ratings/max_ratings') do
expect_prefilled('21-526EZ')
end
end
end
end
end
end
end
end

Expand All @@ -1863,7 +1897,12 @@ def expect_prefilled(form_id)
end

it 'returns prefilled 21-526EZ' do
Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_RATED_DISABILITIES_FOREGROUND)
allow(Flipper).to receive(:enabled?)
.with(
ApiProviderFactory::FEATURE_TOGGLE_RATED_DISABILITIES_FOREGROUND,
anything
)
.and_return(false)
expect(user).to receive(:authorize).with(:ppiu, :access?).and_return(true).at_least(:once)
expect(user).to receive(:authorize).with(:evss, :access?).and_return(true).at_least(:once)
expect(user).to receive(:authorize).with(:va_profile, :access_to_v2?).and_return(true).at_least(:once)
Expand All @@ -1880,6 +1919,32 @@ def expect_prefilled(form_id)
end
end
end

it 'returns prefilled 21-526EZ when disability_526_max_cfi_service_switch is enabled' do
allow(Flipper).to receive(:enabled?)
.with(
ApiProviderFactory::FEATURE_TOGGLE_RATED_DISABILITIES_FOREGROUND,
anything
)
.and_return(false)
allow(Flipper).to receive(:enabled?).with(:disability_526_max_cfi_service_switch,
anything).and_return(true)
expect(user).to receive(:authorize).with(:ppiu, :access?).and_return(true).at_least(:once)
expect(user).to receive(:authorize).with(:evss, :access?).and_return(true).at_least(:once)
expect(user).to receive(:authorize).with(:va_profile, :access_to_v2?).and_return(true).at_least(:once)
VCR.use_cassette('evss/pciu_address/address_domestic') do
VCR.use_cassette('evss/disability_compensation_form/rated_disabilities') do
VCR.use_cassette('evss/ppiu/payment_information') do
VCR.use_cassette('va_profile/military_personnel/service_history_200_many_episodes',
allow_playback_repeats: true, match_requests_on: %i[uri method body]) do
VCR.use_cassette('/disability-max-ratings/max_ratings') do
expect_prefilled('21-526EZ')
end
end
end
end
end
end
end

it 'returns prefilled 21-686C' do
Expand Down
Loading

0 comments on commit 062d788

Please sign in to comment.