diff --git a/app/controllers/v0/intent_to_files_controller.rb b/app/controllers/v0/intent_to_files_controller.rb index 9e3c4b58532..33733cd77b9 100644 --- a/app/controllers/v0/intent_to_files_controller.rb +++ b/app/controllers/v0/intent_to_files_controller.rb @@ -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 @@ -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 diff --git a/lib/disability_compensation/providers/intent_to_file/evss_intent_to_file_provider.rb b/lib/disability_compensation/providers/intent_to_file/evss_intent_to_file_provider.rb index 6a04ac70f7d..60715c76ffb 100644 --- a/lib/disability_compensation/providers/intent_to_file/evss_intent_to_file_provider.rb +++ b/lib/disability_compensation/providers/intent_to_file/evss_intent_to_file_provider.rb @@ -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 diff --git a/lib/disability_compensation/providers/intent_to_file/lighthouse_intent_to_file_provider.rb b/lib/disability_compensation/providers/intent_to_file/lighthouse_intent_to_file_provider.rb index d87d1894cb0..2945de4b99a 100644 --- a/lib/disability_compensation/providers/intent_to_file/lighthouse_intent_to_file_provider.rb +++ b/lib/disability_compensation/providers/intent_to_file/lighthouse_intent_to_file_provider.rb @@ -8,8 +8,8 @@ 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) @@ -17,11 +17,10 @@ def get_intent_to_file(type, lighthouse_client_id, lighthouse_rsa_key_path) 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 diff --git a/lib/lighthouse/benefits_claims/configuration.rb b/lib/lighthouse/benefits_claims/configuration.rb index 867422ee107..bd958cdce9c 100644 --- a/lib/lighthouse/benefits_claims/configuration.rb +++ b/lib/lighthouse/benefits_claims/configuration.rb @@ -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 ## diff --git a/lib/lighthouse/benefits_claims/service.rb b/lib/lighthouse/benefits_claims/service.rb index 00534d4daa0..472ef935b06 100644 --- a/lib/lighthouse/benefits_claims/service.rb +++ b/lib/lighthouse/benefits_claims/service.rb @@ -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) diff --git a/spec/lib/disability_compensation/providers/intent_to_file/evss_intent_to_file_provider_spec.rb b/spec/lib/disability_compensation/providers/intent_to_file/evss_intent_to_file_provider_spec.rb index 6be2fc3e6fd..898521acf5b 100644 --- a/spec/lib/disability_compensation/providers/intent_to_file/evss_intent_to_file_provider_spec.rb +++ b/spec/lib/disability_compensation/providers/intent_to_file/evss_intent_to_file_provider_spec.rb @@ -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) diff --git a/spec/lib/disability_compensation/providers/intent_to_file/lighthouse_intent_to_file_provider_spec.rb b/spec/lib/disability_compensation/providers/intent_to_file/lighthouse_intent_to_file_provider_spec.rb index 04913850114..3598b72b502 100644 --- a/spec/lib/disability_compensation/providers/intent_to_file/lighthouse_intent_to_file_provider_spec.rb +++ b/spec/lib/disability_compensation/providers/intent_to_file/lighthouse_intent_to_file_provider_spec.rb @@ -19,6 +19,8 @@ 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', '', '') @@ -26,6 +28,24 @@ 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 diff --git a/spec/lib/lighthouse/benefits_claims/service_spec.rb b/spec/lib/lighthouse/benefits_claims/service_spec.rb index 44e06653cd9..d4d75c77619 100644 --- a/spec/lib/lighthouse/benefits_claims/service_spec.rb +++ b/spec/lib/lighthouse/benefits_claims/service_spec.rb @@ -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 diff --git a/spec/support/vcr_cassettes/lighthouse/benefits_claims/intent_to_file/create_compensation_200_response.yml b/spec/support/vcr_cassettes/lighthouse/benefits_claims/intent_to_file/create_compensation_200_response.yml new file mode 100644 index 00000000000..107333d5ff4 --- /dev/null +++ b/spec/support/vcr_cassettes/lighthouse/benefits_claims/intent_to_file/create_compensation_200_response.yml @@ -0,0 +1,85 @@ +--- +http_interactions: +- request: + method: post + uri: https://sandbox-api.va.gov/services/claims/v2/veterans/123498767V234859/intent-to-file + body: + encoding: UTF-8 + string: '{"data":{"type":"intent_to_file","attributes":{"type":"compensation","claimantSsn":""}}}' + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - Vets.gov Agent + Authorization: + - Bearer fake_access_token + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 200 + message: OK + headers: + Date: + - Thu, 25 May 2023 17:29:49 GMT + Content-Type: + - application/json; charset=utf-8 + Connection: + - keep-alive + X-Ratelimit-Limit-Minute: + - '60' + Ratelimit-Remaining: + - '59' + Ratelimit-Reset: + - '11' + Ratelimit-Limit: + - '60' + X-Ratelimit-Remaining-Minute: + - '59' + Referrer-Policy: + - strict-origin-when-cross-origin + Vary: + - Origin + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + - SAMEORIGIN + X-Git-Sha: + - 6ebccff8d7858ebdfc79da40bfd10fbcf7c11578 + X-Github-Repository: + - https://github.com/department-of-veterans-affairs/vets-api + X-Permitted-Cross-Domain-Policies: + - none + X-Request-Id: + - 5386b494-2551-46ed-b6f9-536dfb1badec + X-Runtime: + - '0.078298' + X-Xss-Protection: + - 1; mode=block + Access-Control-Allow-Origin: + - "*" + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Transfer-Encoding: + - chunked + body: + encoding: UTF-8 + string: '{ + "data": { + "id": "193685", + "type": "intent_to_file", + "attributes": { + "creationDate": "2021-03-16T19:15:21.000-05:00", + "expirationDate": "2022-03-16T19:15:20.000-05:00", + "type": "compensation", + "status": "active" + } + } + }' + recorded_at: Thu, 25 May 2023 17:29:49 GMT +recorded_with: VCR 6.1.0 diff --git a/spec/support/vcr_cassettes/lighthouse/benefits_claims/intent_to_file/create_survivor_200_response.yml b/spec/support/vcr_cassettes/lighthouse/benefits_claims/intent_to_file/create_survivor_200_response.yml new file mode 100644 index 00000000000..2781a2fdd7b --- /dev/null +++ b/spec/support/vcr_cassettes/lighthouse/benefits_claims/intent_to_file/create_survivor_200_response.yml @@ -0,0 +1,85 @@ +--- +http_interactions: +- request: + method: post + uri: https://sandbox-api.va.gov/services/claims/v2/veterans/123498767V234859/intent-to-file + body: + encoding: UTF-8 + string: '{"data":{"type":"intent_to_file","attributes":{"type":"survivor","claimantSsn":"011223344"}}}' + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - Vets.gov Agent + Authorization: + - Bearer fake_access_token + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 200 + message: OK + headers: + Date: + - Thu, 25 May 2023 17:31:52 GMT + Content-Type: + - application/json; charset=utf-8 + Connection: + - keep-alive + X-Ratelimit-Limit-Minute: + - '60' + Ratelimit-Remaining: + - '59' + Ratelimit-Reset: + - '8' + Ratelimit-Limit: + - '60' + X-Ratelimit-Remaining-Minute: + - '59' + Referrer-Policy: + - strict-origin-when-cross-origin + Vary: + - Origin + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + - SAMEORIGIN + X-Git-Sha: + - 6ebccff8d7858ebdfc79da40bfd10fbcf7c11578 + X-Github-Repository: + - https://github.com/department-of-veterans-affairs/vets-api + X-Permitted-Cross-Domain-Policies: + - none + X-Request-Id: + - 457efe4d-03ff-47c2-96df-3131cca0d1a7 + X-Runtime: + - '0.078882' + X-Xss-Protection: + - 1; mode=block + Access-Control-Allow-Origin: + - "*" + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Transfer-Encoding: + - chunked + body: + encoding: UTF-8 + string: '{ + "data": { + "id": "193685", + "type": "intent_to_file", + "attributes": { + "creationDate": "2021-03-16T19:15:21.000-05:00", + "expirationDate": "2022-03-16T19:15:20.000-05:00", + "type": "survivor", + "status": "active" + } + } + }' + recorded_at: Thu, 25 May 2023 17:31:52 GMT +recorded_with: VCR 6.1.0