Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DisabilityMaxRating client, configuration, and tests with get_ratings update #20483

Merged
merged 17 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
dfitchett marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -1455,6 +1456,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 @@ -2091,6 +2093,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.get_max_rating_for_diagnostic_codes(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 @@ -1509,6 +1509,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'
dfitchett marked this conversation as resolved.
Show resolved Hide resolved

def get_max_rating_for_diagnostic_codes(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)
dfitchett marked this conversation as resolved.
Show resolved Hide resolved
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.get_max_rating_for_diagnostic_codes(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
40 changes: 40 additions & 0 deletions spec/models/form_profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

before do
Flipper.disable(:remove_pciu)
Flipper.disable(:disability_526_max_cfi_service_switch)
stub_evss_pciu(user)
described_class.instance_variable_set(:@mappings, nil)
Flipper.disable(:va_v3_contact_information_service)
Expand Down Expand Up @@ -1858,6 +1859,24 @@ def expect_prefilled(form_id)
end
end
end

it 'returns prefilled 21-526EZ when disability_526_max_cfi_service_switch is enabled' do
Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_RATED_DISABILITIES_FOREGROUND)
Flipper.disable(:disability_compensation_remove_pciu)
Flipper.enable(:disability_526_max_cfi_service_switch)
asiisii marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -1877,6 +1896,7 @@ def expect_prefilled(form_id)

it 'returns prefilled 21-526EZ' do
Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_RATED_DISABILITIES_FOREGROUND)
Flipper.disable(:disability_526_max_cfi_service_switch)
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 @@ -1893,6 +1913,26 @@ def expect_prefilled(form_id)
end
end
end

it 'returns prefilled 21-526EZ when disability_526_max_cfi_service_switch is enabled' do
Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_RATED_DISABILITIES_FOREGROUND)
Flipper.enable(:disability_526_max_cfi_service_switch)
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
24 changes: 23 additions & 1 deletion spec/models/form_profile_v2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

before do
Flipper.enable(:remove_pciu)
Flipper.disable(:disability_526_max_cfi_service_switch)
Flipper.enable(:va_v3_contact_information_service)
Flipper.enable(:disability_compensation_remove_pciu)
described_class.instance_variable_set(:@mappings, nil)
Expand Down Expand Up @@ -1581,7 +1582,7 @@ def expect_prefilled(form_id)
VAProfile::Configuration::SETTINGS.prefill = false
end

it 'returns prefilled 21-526EZ' do
it 'returns prefilled 21-526EZ when disability_526_max_cfi_service_switch is disabled' do
Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_RATED_DISABILITIES_FOREGROUND)
Flipper.enable(:disability_526_toxic_exposure, user)
expect(user).to receive(:authorize).with(:ppiu, :access?).and_return(true).at_least(:once)
Expand All @@ -1600,6 +1601,27 @@ def expect_prefilled(form_id)
end
end
end

it 'returns prefilled 21-526EZ when disability_526_max_cfi_service_switch is enabled' do
Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_RATED_DISABILITIES_FOREGROUND)
Flipper.enable(:disability_526_max_cfi_service_switch)
Flipper.enable(:disability_526_toxic_exposure, user)
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('va_profile/v2/contact_information/get_address') 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
end
Expand Down
Loading
Loading