Skip to content

Commit 5f9c1b6

Browse files
authored
105455 add gclaws client (#21463)
* gclaws client wip * spelling * add specs
1 parent f2350d2 commit 5f9c1b6

File tree

8 files changed

+204
-3
lines changed

8 files changed

+204
-3
lines changed

app/models/accredited_individual.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'accredited_representation/constants'
44

55
class AccreditedIndividual < ApplicationRecord
6-
# Represents an accredited individual (attorney, claims agent, representative) as defined by he OGC accreditation
6+
# Represents an accredited individual (attorney, claims agent, representative) as defined by the OGC accreditation
77
# APIs. Until a form of soft deletion is implemented, these records will only reflect individuals with active
88
# accreditation.
99
#

app/models/accredited_organization.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'accredited_representation/constants'
44

55
class AccreditedOrganization < ApplicationRecord
6-
# Represents an accredited organization as defined by he OGC accreditation APIs. Until a form of soft deletion is
6+
# Represents an accredited organization as defined by the OGC accreditation APIs. Until a form of soft deletion is
77
# implemented, these records will only reflect organization with active accreditation.
88
#
99
# Key notes:

config/initializers/inflections.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
inflect.acronym 'DGI' # Digital GI
1313
inflect.acronym 'EVSS'
1414
inflect.acronym 'FHIR'
15+
inflect.acronym 'GCLAWS' # General Counsel Automated Workload System
1516
inflect.acronym 'GIDS'
1617
inflect.acronym 'GI'
1718
inflect.acronym 'HCA'
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# frozen_string_literal: true
2+
3+
# This client is responsible for retrieving accreditation data from the GCLAWS API.
4+
5+
module RepresentationManagement
6+
module GCLAWS
7+
class Client
8+
ALLOWED_TYPES = %w[agents attorneys representatives veteran_service_organizations].freeze
9+
DEFAULT_PAGE = 1
10+
DEFAULT_PAGE_SIZE = 100
11+
12+
def self.get_accredited_entities(type:, page: DEFAULT_PAGE, page_size: DEFAULT_PAGE_SIZE)
13+
return {} unless ALLOWED_TYPES.include?(type)
14+
15+
configuration = GCLAWS::Configuration.new(type:, page:, page_size:)
16+
17+
configuration.connection.get
18+
rescue Faraday::ConnectionFailed
19+
Rails.logger.error(
20+
"GCLAWS Accreditation connection failed for #{type}"
21+
)
22+
Faraday::Response.new(status: :service_unavailable,
23+
body: { errors: 'GCLAWS Accreditation unavailable' }.to_json)
24+
rescue Faraday::TimeoutError
25+
Rails.logger.error("GCLAWS Accreditation request timed out for #{type}")
26+
Faraday::Response.new(status: :request_timeout,
27+
body: { errors: 'GCLAWS Accreditation request timed out' }.to_json)
28+
end
29+
end
30+
end
31+
end
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# frozen_string_literal: true
2+
3+
# HTTP client configuration for the RepresentationManagement::GCLAWS::Client
4+
#
5+
module RepresentationManagement
6+
module GCLAWS
7+
class Configuration
8+
DEFAULT_SORT_PARAMS = {
9+
'agents' => {
10+
'sortColumn' => 'LastName',
11+
'sortOrder' => 'ASC'
12+
},
13+
'attorneys' => {
14+
'sortColumn' => 'LastName',
15+
'sortOrder' => 'ASC'
16+
},
17+
'representatives' => {
18+
'sortColumn' => 'LastName',
19+
'sortOrder' => 'ASC'
20+
},
21+
'veteran_service_organizations' => {
22+
'sortColumn' => 'Organization.OrganizationName',
23+
'sortOrder' => 'ASC'
24+
}
25+
}.freeze
26+
27+
URL_MAPPING = {
28+
'agents' => Settings.gclaws.accreditation.agents.url,
29+
'attorneys' => Settings.gclaws.accreditation.attorneys.url,
30+
'representatives' => Settings.gclaws.accreditation.representatives.url,
31+
'veteran_service_organizations' => Settings.gclaws.accreditation.veteran_service_organizations.url
32+
}.freeze
33+
34+
def initialize(type:, page:, page_size:)
35+
@type = type
36+
@page = page
37+
@page_size = page_size
38+
end
39+
40+
def connection
41+
Faraday.new(url:, params:, headers:) do |conn|
42+
conn.request :json
43+
conn.response :json, content_type: /\bjson$/
44+
conn.adapter Faraday.default_adapter
45+
end
46+
end
47+
48+
private
49+
50+
def api_key
51+
Settings.gclaws.accreditation.api_key
52+
end
53+
54+
def headers
55+
{
56+
'x-api-key' => api_key
57+
}
58+
end
59+
60+
def params
61+
DEFAULT_SORT_PARAMS[@type].merge({ 'page' => @page, 'pageSize' => @page_size })
62+
end
63+
64+
def url
65+
URL_MAPPING[@type]
66+
end
67+
end
68+
end
69+
end

modules/representation_management/spec/models/representation_management/form_2122_digital_submission_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197
end
198198
end
199199

200-
context 'when the user has a participant id' do
200+
context 'when the user has an ICN' do
201201
it 'does not add the blank ICN error to the form' do
202202
subject.valid?
203203

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails_helper'
4+
require 'faraday'
5+
require 'json'
6+
7+
RSpec.describe RepresentationManagement::GCLAWS::Client do
8+
subject { described_class }
9+
10+
describe '.get_accredited_entities' do
11+
context 'when the type is invalid' do
12+
let(:type) { 'invalid' }
13+
14+
it 'returns an empty hash' do
15+
response = subject.get_accredited_entities(type:)
16+
expect(response).to eq({})
17+
end
18+
end
19+
20+
context 'when the type is valid' do
21+
let(:type) { 'agents' }
22+
let(:parsed_body) { { field: 'value' } }
23+
24+
context 'when the request is successful' do
25+
it 'returns a successful response' do
26+
stub_request(:get, Settings.gclaws.accreditation.agents.url)
27+
.with(query: { 'page' => 1, 'pageSize' => 100, 'sortColumn' => 'LastName', 'sortOrder' => 'ASC' })
28+
.to_return(status: 200, body: parsed_body.to_json, headers: { 'Content-Type' => 'application/json' })
29+
30+
response = subject.get_accredited_entities(type:)
31+
32+
expect(response.status).to eq(200)
33+
expect(response.body).to eq(parsed_body.stringify_keys)
34+
end
35+
end
36+
37+
context 'when the connection fails' do
38+
it 'logs the error and returns a service unavailable status' do
39+
stub_request(:get, Settings.gclaws.accreditation.agents.url)
40+
.with(query: { 'page' => 1, 'pageSize' => 100, 'sortColumn' => 'LastName', 'sortOrder' => 'ASC' })
41+
.to_raise(Faraday::ConnectionFailed.new('GCLAWS Accreditation unavailable'))
42+
43+
expect(Rails.logger).to receive(:error).with("GCLAWS Accreditation connection failed for #{type}")
44+
45+
response = subject.get_accredited_entities(type:)
46+
47+
expect(response.status).to eq(:service_unavailable)
48+
expect(JSON.parse(response.body)['errors']).to eq('GCLAWS Accreditation unavailable')
49+
end
50+
end
51+
52+
context 'when the request times out' do
53+
it 'logs the error and returns a request timeout status' do
54+
stub_request(:get, Settings.gclaws.accreditation.agents.url)
55+
.with(query: { 'page' => 1, 'pageSize' => 100, 'sortColumn' => 'LastName', 'sortOrder' => 'ASC' })
56+
.to_raise(Faraday::TimeoutError.new('GCLAWS Accreditation request timed out'))
57+
58+
expect(Rails.logger).to receive(:error).with(
59+
"GCLAWS Accreditation request timed out for #{type}"
60+
)
61+
62+
response = subject.get_accredited_entities(type:)
63+
64+
expect(response.status).to eq(:request_timeout)
65+
expect(JSON.parse(response.body)['errors']).to eq('GCLAWS Accreditation request timed out')
66+
end
67+
end
68+
end
69+
end
70+
end
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails_helper'
4+
5+
describe RepresentationManagement::GCLAWS::Configuration do
6+
subject { described_class.new(type:, page:, page_size:) }
7+
8+
let(:type) { 'agents' }
9+
let(:page) { 1 }
10+
let(:page_size) { 10 }
11+
12+
describe '#connection' do
13+
it 'creates a Faraday connection' do
14+
expect(subject.connection).to be_a(Faraday::Connection)
15+
end
16+
17+
it 'sets the search params' do
18+
expect(subject.connection.params).to eq({ 'sortColumn' => 'LastName', 'sortOrder' => 'ASC', 'page' => 1,
19+
'pageSize' => 10 })
20+
end
21+
22+
it 'sets the url' do
23+
expect(subject.connection.url_prefix.to_s).to eq(Settings.gclaws.accreditation.agents.url)
24+
end
25+
26+
it 'sets the api_key' do
27+
expect(subject.connection.headers['x-api-key']).to eq(Settings.gclaws.accreditation.api_key)
28+
end
29+
end
30+
end

0 commit comments

Comments
 (0)