Skip to content

Commit

Permalink
96000 part a eps service (#19451)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lee-delarm6 authored Nov 20, 2024
1 parent c9f3774 commit 4caacaa
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

19 changes: 19 additions & 0 deletions modules/vaos/app/services/eps/base_service.rb
Original file line number Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions modules/vaos/app/services/eps/configuration.rb
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions modules/vaos/spec/services/eps/base_service_spec.rb
Original file line number Diff line number Diff line change
@@ -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
53 changes: 53 additions & 0 deletions modules/vaos/spec/services/eps/configuration_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4caacaa

Please sign in to comment.