From 4caacaa26e916b87df64745b59305d2e69653163 Mon Sep 17 00:00:00 2001 From: Lee Delarm <135059743+lee-delarm6@users.noreply.github.com> Date: Wed, 20 Nov 2024 17:28:59 -0500 Subject: [PATCH] 96000 part a eps service (#19451) * Creating eps provider service Creating eps provider service * Added specs Added specs and service provider update * Eps service initial Eps service initial * Moved files Moved files, set settings, removed code we won't be using * Token service not in yet Token service not in yet, skipping tests for this service * Update to use BaseService Update to use BaseService * Fixed format, changed inherited type Fixed format, changed inherited type * Rubocop fixes Rubocop fixes * Settings autoformat update Settings autoformat update * changed init changed init * Fixing tests, adding methods Fixed a bunch of tests, lots of mocks added, copied in connection method to Eps::Confg, minor change in base_service * Minor change to init Minor change to init, attempting to commit without rubocop error, we'll see * Adding super back Adding super back, I don't see the init method either, I don't know why it demands it * Simplified code and specs Simplified code and specs * Adding config tests, minor config changes Adding config tests, minor config changes * minor change Changed to call header directly * Adding middleware Adding middleware * Removed vaos logging Removed vaos logging --- config/settings.yml | 3 ++ modules/vaos/app/services/eps/base_service.rb | 19 +++++++ .../vaos/app/services/eps/configuration.rb | 37 +++++++++++++ .../spec/services/eps/base_service_spec.rb | 27 ++++++++++ .../spec/services/eps/configuration_spec.rb | 53 +++++++++++++++++++ 5 files changed, 139 insertions(+) create mode 100644 modules/vaos/app/services/eps/base_service.rb create mode 100644 modules/vaos/app/services/eps/configuration.rb create mode 100644 modules/vaos/spec/services/eps/base_service_spec.rb create mode 100644 modules/vaos/spec/services/eps/configuration_spec.rb diff --git a/config/settings.yml b/config/settings.yml index 2706a07c878..72aec2753c5 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -1833,7 +1833,10 @@ vaos: mock: false client_id: "fake_client_id" kid: "fake_kid" + grant_type: "client_credentials" + client_assertion_type: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer" audience_claim_url: "https://login.wellhive.com/oauth2/default/v1/token" access_token_url: "https://login.wellhive.com/oauth2/default/v1/token" api_url: "https://api.wellhive.com/care-navigation/v1" scopes: "care-nav" + diff --git a/modules/vaos/app/services/eps/base_service.rb b/modules/vaos/app/services/eps/base_service.rb new file mode 100644 index 00000000000..0ac2c701c0b --- /dev/null +++ b/modules/vaos/app/services/eps/base_service.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Eps + class BaseService < VAOS::SessionService + STATSD_KEY_PREFIX = 'api.eps' + + def headers + { + 'Authorization' => 'Bearer 1234', + 'Content-Type' => 'application/json', + 'X-Request-ID' => RequestStore.store['request_id'] + } + end + + def config + Eps::Configuration.instance + end + end +end diff --git a/modules/vaos/app/services/eps/configuration.rb b/modules/vaos/app/services/eps/configuration.rb new file mode 100644 index 00000000000..27c0954bcdd --- /dev/null +++ b/modules/vaos/app/services/eps/configuration.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +module Eps + class Configuration < Common::Client::Configuration::REST + delegate :access_token_url, :api_url, :grant_type, :scopes, :client_assertion_type, to: :settings + + def settings + Settings.vaos.eps + end + + def service_name + 'EPS' + end + + def mock_enabled? + [true, 'true'].include?(settings.mock) + end + + def connection + Faraday.new(api_url, headers: base_request_headers, request: request_options) do |conn| + conn.use :breakers + conn.request :camelcase + conn.request :json + + if ENV['VAOS_DEBUG'] && !Rails.env.production? + conn.request(:curl, ::Logger.new($stdout), :warn) + conn.response(:logger, ::Logger.new($stdout), bodies: true) + end + + conn.response :betamocks if mock_enabled? + conn.response :snakecase + conn.response :json, content_type: /\bjson$/ + conn.adapter Faraday.default_adapter + end + end + end +end diff --git a/modules/vaos/spec/services/eps/base_service_spec.rb b/modules/vaos/spec/services/eps/base_service_spec.rb new file mode 100644 index 00000000000..b12817b59d3 --- /dev/null +++ b/modules/vaos/spec/services/eps/base_service_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe Eps::BaseService do + let(:user) { double('User', account_uuid: '1234') } + let(:service) { described_class.new(user) } + + describe '#headers' do + it 'returns the correct headers' do + allow(RequestStore.store).to receive(:[]).with('request_id').and_return('request-id') + + expected_headers = { + 'Authorization' => 'Bearer 1234', + 'Content-Type' => 'application/json', + 'X-Request-ID' => 'request-id' + } + expect(service.headers).to eq(expected_headers) + end + end + + describe '#config' do + it 'returns the Eps::Configuration instance' do + expect(service.config).to be_instance_of(Eps::Configuration) + end + end +end diff --git a/modules/vaos/spec/services/eps/configuration_spec.rb b/modules/vaos/spec/services/eps/configuration_spec.rb new file mode 100644 index 00000000000..fbfd6d068a6 --- /dev/null +++ b/modules/vaos/spec/services/eps/configuration_spec.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe Eps::Configuration do + describe '#service_name' do + it 'has a service name' do + expect(Eps::Configuration.instance.service_name).to eq('EPS') + end + end + + describe '#connection' do + it 'returns a connection' do + expect(Eps::Configuration.instance.connection).not_to be_nil + end + + context 'when VAOS_DEBUG is set and not in production' do + it 'sets up the connection with a stdout logger to display requests in curl format' do + allow(ENV).to receive(:[]).and_call_original + allow(ENV).to receive(:[]).with('VAOS_DEBUG').and_return('true') + allow(Rails.env).to receive(:production?).and_return(false) + + conn = Eps::Configuration.instance.connection + expect(conn.builder.handlers).to include(Faraday::Response::Logger) + expect(conn.builder.handlers).to include(Faraday::Curl::Middleware) + end + end + end + + describe '#mock_enabled?' do + context 'when Settings.vaos.eps.mock is true' do + before { allow(Settings.vaos.eps).to receive(:mock).and_return(true) } + + it 'returns true' do + expect(Eps::Configuration.instance).to be_mock_enabled + end + end + + context 'when Settings.vaos.eps.mock is false' do + before { allow(Settings.vaos.eps).to receive(:mock).and_return(false) } + + it 'returns false' do + expect(Eps::Configuration.instance).not_to be_mock_enabled + end + end + end + + describe '#settings' do + it 'returns the settings' do + expect(Eps::Configuration.instance.settings).to eq(Settings.vaos.eps) + end + end +end