-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DisabilityMaxRating client, configuration, and tests with get_rat…
…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
Showing
16 changed files
with
488 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.