Skip to content

Commit

Permalink
[Automated] Merged master into target k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
va-vsp-bot authored Apr 23, 2024
2 parents 375f8d1 + 4995a8a commit 00fda33
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/lighthouse/benefits_claims/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module BenefitsClaims
class Configuration < Common::Client::Configuration::REST
self.read_timeout = Settings.lighthouse.benefits_claims.timeout || 20

API_SCOPES = %w[system/claim.read system/claim.write].freeze
API_SCOPES = %w[system/claim.read system/claim.write system/526-pdf.override].freeze
CLAIMS_PATH = 'services/claims/v2/veterans'
TOKEN_PATH = 'oauth2/claims/system/v1/token'

Expand Down
42 changes: 33 additions & 9 deletions lib/lighthouse/benefits_claims/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def create_intent_to_file(type, claimant_ssn, lighthouse_client_id = nil, lighth
handle_error(e, lighthouse_client_id, endpoint)
end

# submit form526 to Lighthouse API endpoint: /services/claims/v2/veterans/{veteranId}/526
# submit form526 to Lighthouse API endpoint: /services/claims/v2/veterans/{veteranId}/526 or
# /services/claims/v2/veterans/{veteranId}/526/generatePdf
# @param [hash || Requests::Form526] body: a hash representing the form526
# attributes in the Lighthouse request schema
# @param [string] lighthouse_client_id: the lighthouse_client_id requested from Lighthouse
Expand All @@ -111,28 +112,31 @@ def create_intent_to_file(type, claimant_ssn, lighthouse_client_id = nil, lighth
# @option options [hash] :body_only only return the body from the request
# @option options [string] :aud_claim_url option to override the aud_claim_url for LH Veteran Verification APIs
# @option options [hash] :auth_params a hash to send in auth params to create the access token
# @option options [hash] :generate_pdf call the generatePdf endpoint to receive the 526 pdf
def submit526(body, lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, options = {})
endpoint = 'benefits_claims/form/526'
endpoint = '{icn}/526'
path = "#{@icn}/526"

if options[:generate_pdf].present?
path += '/generatePDF/minimum-validations'
endpoint += '/generatePDF/minimum-validations'
end

# if we're coming straight from the transformation service without
# making this a jsonapi request body first ({data: {type:, attributes}}),
# this will put it in the correct format for transmission

body = {
data: {
type: 'form/526',
attributes: body
}
}.as_json.deep_transform_keys { |k| k.camelize(:lower) }
body = build_request_body(body)

# Inflection settings force 'current_va_employee' to render as 'currentVAEmployee' in the above camelize() call
# Since Lighthouse needs 'currentVaEmployee', the following workaround renames it.
fix_current_va_employee(body)

json_body = remove_unicode_characters(body)

response = config.post(
path,
body,
json_body,
lighthouse_client_id, lighthouse_rsa_key_path, options
)

Expand All @@ -143,6 +147,26 @@ def submit526(body, lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, o

private

def build_request_body(body)
{
data: {
type: 'form/526',
attributes: body
}
}.as_json.deep_transform_keys { |k| k.camelize(:lower) }
end

# this gsubbing is to fix an issue where the service that generates the 526PDF was failing due to
# unicoded carriage returns:
# i.e.: \n was throwing: "U+000A ('controlLF') is not available in the font Helvetica, encoding: WinAnsiEncoding"
def remove_unicode_characters(body)
body.to_json
.gsub('\\n', ' ')
.gsub('\\r', ' ')
.gsub('\\\\n', ' ')
.gsub('\\\\r', ' ')
end

def fix_current_va_employee(body)
if body.dig('data', 'attributes', 'veteranIdentification')&.select do |field|
field['currentVAEmployee']
Expand Down
9 changes: 9 additions & 0 deletions spec/lib/lighthouse/benefits_claims/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@
expect(response.claim_id).to eq(1_234_567_890)
end
end

context 'when given the option to use generate pdf' do
it 'calls the generate pdf endpoint' do
VCR.use_cassette('lighthouse/benefits_claims/submit526/200_response_generate_pdf') do
raw_response = @service.submit526({}, '', '', { generate_pdf: true })
expect(raw_response.body).to eq('No example available')
end
end
end
end
end
end
Expand Down

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

0 comments on commit 00fda33

Please sign in to comment.