Skip to content

Commit

Permalink
bdex/80773: Toxic Exposure - [Lighthouse API] generatePdf hook up (#1…
Browse files Browse the repository at this point in the history
…6411)

* dbex/80773: enable benefits_claims/service#submit526 to call LH's /generatePDF endpoint

* bdex/80773: enable benefits_claims/service#submit526 to call LH's /generatePDF endpoint

* bdex/80773: enable benefits_claims/service#submit526 to call LH's /generatePDF endpoint

* linting fix

* bdex/80773: add removal of unicode carriage return and new line characters

* bdex/80773: add generate pdf option unit test

---------

Co-authored-by: Seth Darr <92405130+sethdarragile6@users.noreply.github.com>
Co-authored-by: Seth Darr <seth.darr@agile6.com>
  • Loading branch information
3 people committed Apr 23, 2024
1 parent 5494d60 commit 4995a8a
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
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
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
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 4995a8a

Please sign in to comment.