Skip to content

Commit

Permalink
EDM-213/build lce interface and mockdata (#19178)
Browse files Browse the repository at this point in the history
* Create lce client and config

* Create lce client methods

* Create lce controllers

* Update gids redis to respond to lce client

* Create routes

* Enable mocks

* Add gids response to lce client

* Fix linting

* Update gids redis spec

* LCE client spec

* Condense spec file

* Update codeowners

* Fix linting

* Fix typo in spec test

* Fix spec typo

* Fix spec typo

* Fix spec

* Revert codeowners

* Update services config and settings
  • Loading branch information
jefftmarks authored Oct 30, 2024
1 parent dedb94b commit cf664de
Show file tree
Hide file tree
Showing 14 changed files with 256 additions and 3 deletions.
13 changes: 13 additions & 0 deletions app/controllers/v1/gids/lce/certifications_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module V1
module GIDS
module Lce
class CertificationsController < LceController
def show
render json: service.get_certification_details_v1(scrubbed_params)
end
end
end
end
end
13 changes: 13 additions & 0 deletions app/controllers/v1/gids/lce/exams_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module V1
module GIDS
module Lce
class ExamsController < GIDS::LceController
def show
render json: service.get_exam_details_v1(scrubbed_params)
end
end
end
end
end
13 changes: 13 additions & 0 deletions app/controllers/v1/gids/lce/licenses_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module V1
module GIDS
module Lce
class LicensesController < LceController
def show
render json: service.get_license_details_v1(scrubbed_params)
end
end
end
end
end
13 changes: 13 additions & 0 deletions app/controllers/v1/gids/lce/preps_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module V1
module GIDS
module Lce
class PrepsController < LceController
def show
render json: service.get_prep_details_v1(scrubbed_params)
end
end
end
end
end
11 changes: 11 additions & 0 deletions app/controllers/v1/gids/lce_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module V1
module GIDS
class LceController < GIDSController
def index
render json: service.get_lce_search_results_v1(scrubbed_params)
end
end
end
end
11 changes: 11 additions & 0 deletions app/models/gids_redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'common/models/concerns/cache_aside'
require 'gi/client'
require 'gi/search_client'
require 'gi/lce/client'

# Facade for GIDS.
class GIDSRedis < Common::RedisStore
Expand All @@ -24,6 +25,8 @@ def method_missing(name, *args)
response_from_redis_or_service(gi_service).body
elsif search_respond_to?(name)
response_from_redis_or_service(gi_search_service).body
elsif lce_respond_to?(name)
response_from_redis_or_service(gi_lce_service).body
else
super
end
Expand All @@ -37,6 +40,10 @@ def search_respond_to?(name)
gi_search_service.respond_to?(name)
end

def lce_respond_to?(name)
gi_lce_service.respond_to?(name)
end

private

def response_from_redis_or_service(service)
Expand All @@ -52,4 +59,8 @@ def gi_service
def gi_search_service
@search_client ||= ::GI::SearchClient.new
end

def gi_lce_service
@lce_service ||= ::GI::Lce::Client.new
end
end
23 changes: 23 additions & 0 deletions config/betamocks/services_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -920,3 +920,26 @@
- :method: :post
:path: "/profile-service/profile/v3/*/*"
:file_path: "vet360/profile-service/default"

# GIDS
- :name: "GIDS"
:base_uri: <%= "#{URI(Settings.gids.url).host}:#{URI(Settings.gids.url).port}" %>
:endpoints:
- :method: :get
:path: "/gids/v1/lce"
:file_path: "gids/lce"
:cache_multiple_responses:
:uid_location: query
:uid_locator: type
- :method: :get
:path: "/gids/v1/lce/certifications/*"
:file_path: "gids/lce/certifications/default"
- :method: :get
:path: "/gids/v1/lce/exams/*"
:file_path: "gids/lce/exams/default"
- :method: :get
:path: "/gids/v1/lce/licenses/*"
:file_path: "gids/lce/licenses/default"
- :method: :get
:path: "/gids/v1/lce/preps/*"
:file_path: "gids/lce/preps/default"
12 changes: 12 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,18 @@
resources :yellow_ribbon_programs, only: :index, defaults: { format: :json }

resources :zipcode_rates, only: :show, defaults: { format: :json }

resources :lce, only: :index, defaults: { format: :json }

namespace :lce do
resources :certifications, only: :show, defaults: { format: :json }

resources :exams, only: :show, defaults: { format: :json }

resources :licenses, only: :show, defaults: { format: :json }

resources :preps, only: :show, defaults: { format: :json }
end
end

resource :decision_review_evidence, only: :create
Expand Down
2 changes: 2 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ gids:
url: https://dev.va.gov/gids
open_timeout: 1
read_timeout: 1
lce:
use_mocks: false

mvi_hca:
url: http://example.com
Expand Down
6 changes: 6 additions & 0 deletions lib/gi/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def connection
# conn.request :curl, ::Logger.new(STDOUT), :warn

# conn.response :logger, ::Logger.new(STDOUT), bodies: true
conn.response :betamocks if use_mocks?
conn.response :snakecase
conn.response :raise_custom_error, error_prefix: service_name
conn.response :gids_errors
Expand All @@ -35,5 +36,10 @@ def connection
conn.adapter Faraday.default_adapter
end
end

# To be overridden in gi/lce/configuration
def use_mocks?
false
end
end
end
41 changes: 41 additions & 0 deletions lib/gi/lce/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

require 'gi/client'
require_relative 'configuration'

module GI
module Lce
class Client < GI::Client
configuration GI::Lce::Configuration

def get_lce_search_results_v1(params = {})
response = perform(:get, 'v1/lce', params)
gids_response(response)
end

def get_certification_details_v1(params = {})
certification_id = params[:id]
response = perform(:get, "v1/lce/certifications/#{certification_id}", params.except(:id))
gids_response(response)
end

def get_exam_details_v1(params = {})
exam_id = params[:id]
response = perform(:get, "v1/lce/exams/#{exam_id}", params.except(:id))
gids_response(response)
end

def get_license_details_v1(params = {})
license_id = params[:id]
response = perform(:get, "v1/lce/licenses/#{license_id}", params.except(:id))
gids_response(response)
end

def get_prep_details_v1(params = {})
prep_id = params[:id]
response = perform(:get, "v1/lce/preps/#{prep_id}", params.except(:id))
gids_response(response)
end
end
end
end
13 changes: 13 additions & 0 deletions lib/gi/lce/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

require 'gi/configuration'

module GI
module Lce
class Configuration < GI::Configuration
def use_mocks?
Settings.gids.lce.use_mocks || false
end
end
end
end
64 changes: 64 additions & 0 deletions spec/lib/gi/lce/client_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# frozen_string_literal: true

require 'rails_helper'
require 'gi/lce/client'
require 'gi/gids_response'

# TO-DO: Replace stubbed data with VCR cassettes after GIDS connection established
describe GI::Lce::Client do
let(:client) { GI::Lce::Client.new }
let(:search_data) do
[
{
link: 'lce/certifications/1',
name: 'Certification Name',
type: 'certification'
}
]
end
let(:institution) { { name: 'Institution' } }
let(:lcp_data) do
{
desc: 'License Name',
type: 'license',
tests: [{ name: 'Test Name' }],
institution: institution,
officials: [{ title: 'Certifying Official' }]
}
end
let(:exam_data) do
{
name: 'Exam Name',
tests: [{ description: 'Description' }],
institution: institution
}
end

it 'gets a list of licenses, certifications, exams, and prep courses' do
search_response = OpenStruct.new(body: { data: search_data })
allow(client).to receive(:get_lce_search_results_v1).with(type: 'all').and_return(search_response)
client_response = client.get_lce_search_results_v1(type: 'all').body
expect(client_response[:data]).to be_an(Array)
end

%w[license certification prep].each do |type|
it "gets #{type} details" do
details_response = OpenStruct.new(body: { data: lcp_data })
query_method = :"get_#{type}_details_v1"

allow(client).to receive(query_method).with(id: '1').and_return(details_response)
client_response = client.send(query_method, id: '1').body
expect(client_response[:data]).to be_an(Hash)
expect(client_response[:data].keys).to contain_exactly(:desc, :type, :tests, :institution, :officials)
end
end

it 'gets exam details' do
details_response = OpenStruct.new(body: { data: exam_data })

allow(client).to receive(:get_exam_details_v1).with(id: '1').and_return(details_response)
client_response = client.get_exam_details_v1(id: '1').body
expect(client_response[:data]).to be_an(Hash)
expect(client_response[:data].keys).to contain_exactly(:name, :tests, :institution)
end
end
24 changes: 21 additions & 3 deletions spec/models/gids_redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,28 @@
end

context 'when `GIDSRedis` responds to method' do
it 'delegates to `GI::Client`' do
allow_any_instance_of(GI::Client).to receive(:get_institution_details_v0).and_return(gids_response)
context 'and the method belongs to `GI::Client`' do
it 'delegates to `GI::Client`' do
allow_any_instance_of(GI::Client).to receive(:get_institution_details_v0).and_return(gids_response)

expect(subject.get_institution_details_v0(scrubbed_params)).to eq(gids_response.body)
expect(subject.get_institution_details_v0(scrubbed_params)).to eq(gids_response.body)
end
end

context 'and the method belongs to `GI::SearchClient`' do
it 'delegates to `GI::SearchClient`' do
allow_any_instance_of(GI::SearchClient).to receive(:get_institution_search_results_v0).and_return(gids_response)

expect(subject.get_institution_search_results_v0(scrubbed_params)).to eq(gids_response.body)
end
end

context 'and the method belongs to `GI::Lce::Client`' do
it 'delegates to `GI::Lce::Client`' do
allow_any_instance_of(GI::Lce::Client).to receive(:get_lce_search_results_v1).and_return(gids_response)

expect(subject.get_lce_search_results_v1(scrubbed_params)).to eq(gids_response.body)
end
end
end

Expand Down

0 comments on commit cf664de

Please sign in to comment.