-
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.
* 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
1 parent
c9f3774
commit 4caacaa
Showing
5 changed files
with
139 additions
and
0 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
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 |
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,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 |
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 '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 |
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' | ||
|
||
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 |