Skip to content

Commit

Permalink
Bdex/57064 migrate post intent to file to lighthouse (#12753)
Browse files Browse the repository at this point in the history
* implement GET request for Lighthouse intent-to-file

* modify BenefitsClaims::Service to request intent to file data

* extend BenefitsService::Configuration to handle different consumer/client needs

* modify existing BenefitsClaims index and show operations to handle new configuration

* implement GET request for Lighthouse intent-to-file

* modify BenefitsClaims::Service to request intent to file data

* extend BenefitsService::Configuration to handle different consumer/client needs

* modify existing BenefitsClaims index and show operations to handle new configuration

* add parameters to fix evss method, move transform to private method, rm unneeded comment

* add error handling and request specs

* fix a few request specs

* fix some tests to accommodate provider pattern

* fix rubocop errors, add tests to lighthouse itf provider

* Merge branch 'bdex/57063/migrate-get-intent_to_file-to-lighthouse' of https://github.com/department-of-veterans-affairs/vets-api into bdex/57063/migrate-get-intent_to_file-to-lighthouse

* Implement service ITF post

* Add TODO for swagger spec

* implement GET request for Lighthouse intent-to-file

* modify BenefitsClaims::Service to request intent to file data

* extend BenefitsService::Configuration to handle different consumer/client needs

* modify existing BenefitsClaims index and show operations to handle new configuration

* add parameters to fix evss method, move transform to private method, rm unneeded comment

* add error handling and request specs

* fix a few request specs

* fix some tests to accommodate provider pattern

* fix rubocop errors, add tests to lighthouse itf provider

* a little cleanup, fixing errors in lighthouse service, config, and spec

* Revert "Add TODO for swagger spec"

This reverts commit ca98b3c.

* minor tweak for Rubocop and require needed files

* Correct stomped swagger_spec

* Remove committed debug statements; Update TODOs to be more indexable

* Update parameters of evss provider

* Add template automated tests

* Correct improper identifier in EVSS ITF provider

* Correct LH provider parameters and tests

* Update evss itf spec

* Update LH ITF specs; Attempt VCR continuous integration; Add mock responses

* Remove some TODOs

* Add missing param to service spec

* Some cleanup and missed comments

* Change create to supply ssn on function call instead of initialize; Simpliy current_user interface

* Regenerate VCR cassettes

* Add some future TODO considerations; Fix expects to match data structure

* Fix missed parameter update

* Linting auto-fixes

* Revert changes to benefits_claims_controller

* Commit removing credentials from intent_to_files_controller

* Remove missed comments and unused var assignment

---------

Co-authored-by: Eddie Glenn <eddieglenn@navapbc.com>
  • Loading branch information
mchae-nava and navaeddie authored May 26, 2023
1 parent 9bd9358 commit d7192ab
Show file tree
Hide file tree
Showing 10 changed files with 264 additions and 19 deletions.
12 changes: 3 additions & 9 deletions app/controllers/v0/intent_to_files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,9 @@ class IntentToFilesController < ApplicationController
TYPES = %w[compensation].freeze

def index
# TODO: Hard-coding 'form526' as the application that consumes this for now
# need whichever app that consumes this endpoint to switch to their credentials for Lighthouse API consumption
application = params['application'] || 'form526'
settings = Settings.lighthouse.benefits_claims[application]

intent_to_file_service = ApiProviderFactory.intent_to_file_service_provider(@current_user)
type = params['itf_type'] || 'compensation'
response = intent_to_file_service.get_intent_to_file(type, settings.access_token.client_id,
settings.access_token.rsa_key)
response = intent_to_file_service.get_intent_to_file(type, nil, nil)
render json: response,
serializer: IntentToFileSerializer
end
Expand All @@ -35,8 +29,8 @@ def active

def submit
intent_to_file_service = ApiProviderFactory.intent_to_file_service_provider(@current_user)

response = intent_to_file_service.create_intent_to_file(params[:type])
type = params['itf_type'] || 'compensation'
response = intent_to_file_service.create_intent_to_file(type, nil, nil)
render json: response,
serializer: IntentToFileSerializer
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def get_intent_to_file(_type, _client_id, _rsa_key_path)
@service.get_intent_to_file
end

def create_intent_to_file(type)
def create_intent_to_file(type, _client_id, _rsa_key_path)
@service.create_intent_to_file(type)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@ class LighthouseIntentToFileProvider
include IntentToFileProvider

def initialize(current_user)
icn = current_user.icn
@service = BenefitsClaims::Service.new(icn)
@current_user = current_user
@service = BenefitsClaims::Service.new(current_user.icn)
end

def get_intent_to_file(type, lighthouse_client_id, lighthouse_rsa_key_path)
data = @service.get_intent_to_file(type, lighthouse_client_id, lighthouse_rsa_key_path)['data']
transform(data)
end

def create_intent_to_file(type)
# Will implement in 57064
# data = @service.get_intent_to_file(type)['data']
# return 401 response if something is missing?
# transform(data)
def create_intent_to_file(type, lighthouse_client_id, lighthouse_rsa_key_path)
data = @service.create_intent_to_file(type, @current_user.ssn, lighthouse_client_id,
lighthouse_rsa_key_path)['data']
transform(data)
end

private
Expand Down
10 changes: 8 additions & 2 deletions lib/lighthouse/benefits_claims/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,14 @@ def get(path, lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, options
##
# @return [Faraday::Response] response from POST request
#
def post(path, body = {})
connection.post(path, body, { Authorization: "Bearer #{access_token}" })
def post(path, body, lighthouse_client_id, lighthouse_rsa_key_path, options = {})
connection.post(path, body, { Authorization: "Bearer #{
access_token(
lighthouse_client_id,
lighthouse_rsa_key_path,
options
)
}" })
end

##
Expand Down
28 changes: 28 additions & 0 deletions lib/lighthouse/benefits_claims/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,34 @@ def get_intent_to_file(type, lighthouse_client_id = nil, lighthouse_rsa_key_path
handle_error(e, lighthouse_client_id, endpoint)
end

# For type "survivor", the request must include claimantSsn and be made by a valid Veteran Representative.
# If the Representative is not a Veteran or a VA employee, this method is currently not available to them,
# and they should use the Benefits Intake API as an alternative.
def create_intent_to_file(type, claimant_ssn, lighthouse_client_id = nil, lighthouse_rsa_key_path = nil,
options = {})
if claimant_ssn.blank? && type == 'survivor'
raise ArgumentError, 'BenefitsClaims::Service: No SSN provided for survivor type create request.'
end

endpoint = 'benefits_claims/intent_to_file'
path = "#{@icn}/intent-to-file"
config.post(
path,
{
data: {
type: 'intent_to_file',
attributes: {
type:,
claimantSsn: claimant_ssn
}
}
},
lighthouse_client_id, lighthouse_rsa_key_path, options
).body
rescue Faraday::ClientError => e
handle_error(e, lighthouse_client_id, endpoint)
end

private

def filter_by_status(items)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@
end
end

it 'creates intent to file from the EVSS API' do
VCR.use_cassette('evss/intent_to_file/create_compensation') do
provider = EvssIntentToFileProvider.new(nil, auth_headers)
response = provider.create_intent_to_file('compensation', '', '')
expect(response).to be_an_instance_of(EVSS::IntentToFile::IntentToFileResponse)
expect(response['intent_to_file']['type']).to eq('compensation')

# No ActiveRecord inheritance; verify the id as a workaround
expect(response['intent_to_file']['id']).to be_present
end
end

it 'raises an exception if there is an error from EVSS' do
allow_any_instance_of(Common::Client::Base).to(
receive(:perform).and_raise(Common::Client::Errors::ClientError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,33 @@

it_behaves_like 'intent to file provider'

# TODO-BDEX: Down the line, revisit re-generating cassettes using some local test credentials
# and actual interaction with LH
it 'retrieves intent to file from the Lighthouse API' do
VCR.use_cassette('lighthouse/benefits_claims/intent_to_file/200_response') do
response = provider.get_intent_to_file('compensation', '', '')
expect(response['intent_to_file'].length).to eq(1)
end
end

it 'creates intent to file using the Lighthouse API' do
VCR.use_cassette('lighthouse/benefits_claims/intent_to_file/create_compensation_200_response') do
response = provider.create_intent_to_file('compensation', '', '')
expect(response).to be_an_instance_of(DisabilityCompensation::ApiProvider::IntentToFilesResponse)
expect(response['intent_to_file'][0]['type']).to eq('compensation')
expect(response['intent_to_file'][0]['id']).to be_present
end
end

it 'creates intent to file with the survivor type' do
VCR.use_cassette('lighthouse/benefits_claims/intent_to_file/create_survivor_200_response') do
response = provider.create_intent_to_file('survivor', '', '')
expect(response).to be_an_instance_of(DisabilityCompensation::ApiProvider::IntentToFilesResponse)
expect(response['intent_to_file'][0]['type']).to eq('survivor')
expect(response['intent_to_file'][0]['id']).to be_present
end
end

Lighthouse::ServiceException::ERROR_MAP.each do |status, error_class|
it "throws a #{status} error if Lighthouse sends it back" do
expect do
Expand Down
16 changes: 16 additions & 0 deletions spec/lib/lighthouse/benefits_claims/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,28 @@
end

describe 'when requesting intent_to_file' do
# TODO-BDEX: Down the line, revisit re-generating cassettes using some local test credentials
# and actual interaction with LH
it 'retrieves a intent to file from the Lighthouse API' do
VCR.use_cassette('lighthouse/benefits_claims/intent_to_file/200_response') do
response = @service.get_intent_to_file('compensation', '', '')
expect(response['data']['id']).to eq('193685')
end
end

it 'creates intent to file using the Lighthouse API' do
VCR.use_cassette('lighthouse/benefits_claims/intent_to_file/create_compensation_200_response') do
response = @service.create_intent_to_file('compensation', '', '')
expect(response['data']['attributes']['type']).to eq('compensation')
end
end

it 'creates intent to file with the survivor type' do
VCR.use_cassette('lighthouse/benefits_claims/intent_to_file/create_survivor_200_response') do
response = @service.create_intent_to_file('survivor', '011223344', '', '')
expect(response['data']['attributes']['type']).to eq('survivor')
end
end
end

describe 'when requesting a list of benefits claims' do
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d7192ab

Please sign in to comment.