Skip to content

Commit

Permalink
Merge branch 'master' into API-32462
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike committed Apr 24, 2024
2 parents 122608c + 994c71f commit 2cdc1e6
Show file tree
Hide file tree
Showing 27 changed files with 812 additions and 135 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ GEM
content_disposition (1.0.0)
cork (0.3.0)
colored2 (~> 3.1)
coverband (6.1.0)
coverband (6.1.1)
redis (>= 3.0)
crack (1.0.0)
bigdecimal
Expand Down Expand Up @@ -692,7 +692,7 @@ GEM
os (1.1.4)
ox (2.14.18)
parallel (1.24.0)
parallel_tests (4.6.1)
parallel_tests (4.7.0)
parallel
parser (3.3.0.5)
ast (~> 2.4.1)
Expand Down
31 changes: 29 additions & 2 deletions app/models/form526_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class Form526Submission < ApplicationRecord
state :unprocessed, initial: true
state :delivered_to_primary, :failed_primary_delivery, :rejected_by_primary,
:delivered_to_backup, :failed_backup_delivery, :rejected_by_backup,
:in_remediation, :finalized_as_successful, :unprocessable
:in_remediation, :finalized_as_successful, :unprocessable,
:processed_in_batch_remediation, :ignorable_duplicate

# - a submission has been delivered to our happy path
# - requires polling to finalize
Expand Down Expand Up @@ -62,7 +63,6 @@ class Form526Submission < ApplicationRecord
transitions to: :in_remediation
end

# TODO: add this transition when we add 526 completion polling
# - The only state that means we no longer own completion of this submission
# - There is nothing more to do. E.G.
# - VBMS has accepted and returned the applicable status to us via
Expand All @@ -78,6 +78,33 @@ class Form526Submission < ApplicationRecord
event :mark_as_unprocessable do
transitions to: :unprocessable
end

# A special state to indicate this was part of our remediation 'batching'
# process in 2023. These were handled manually and are distinct from `in_remediation`
# in that they were not tracked at the time of remediation, but rather later in
# the 2024 526 State audit.
#
# This state is useful to us at the time of creation, but may be something
# to flatten to a simple `finalized_as_successful` in the future.
event :process_in_batch_remediation do
transitions to: :processed_in_batch_remediation
end

# A special state to indicate this was part of our remediation 'batching'
# process in 2023. These submissions may have been processed or not, but
# we don't care because they have an earlier, successful duplicate.
#
# Duplicates are identified by comparing form_json, using this script:
# https://github.com/department-of-veterans-affairs/va.gov-team-sensitive/blob/master/teams/benefits/scripts/526/submission_deduper.rb
# The result of this script can be evaluated by a qualified stakeholder to make
# a judgement call on whether or not a submission is a 'perfect' duplicate.
#
# IF a submission is found to be an exact duplicate of another
# AND its duplicate was previously submitted / remediated successfully
# THEN we can ignore it as a duplicate
event :ignore_as_duplicate do
transitions to: :ignorable_duplicate
end
end

wrap_with_logging(:start_evss_submission_job,
Expand Down
3 changes: 3 additions & 0 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,9 @@ features:
actor_type: user
description: Enables/disables refill-related content for Medications on VA.gov
enable_in_development: true
mhv_landing_page_enable_va_gov_health_tools_links:
actor_type: user
description: Enables VA.gov Health Tools links (Appts, SM, Rx, Records) on MHV-on-VA.gov Landing Page
mhv_to_logingov_account_transition:
actor_type: cookie_id
description: Enables/disables MHV to Login.gov account transfer experience (Identity)
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ def test_create
end

def create
response = Inquiries::Creator.new(icn: current_user.icn).call(params: inquiry_params)
response = Inquiries::Creator.new(icn: current_user.icn).call(payload: inquiry_params)
render json: response.to_json, status: :created
end

def unauth_create
response = Inquiries::Creator.new(icn: nil).call(params: inquiry_params)
response = Inquiries::Creator.new(icn: nil).call(payload: inquiry_params)
render json: response.to_json, status: :created
end

Expand Down Expand Up @@ -101,7 +101,7 @@ def inquiry_params
*dependant_parameters,
*submitter_parameters,
*veteran_parameters,
school_obj: school_parameters
SchoolObj: school_parameters
).to_h
end

Expand All @@ -112,7 +112,7 @@ def base_parameters
InquiryCategory InquirySource InquirySubtopic InquirySummary InquiryTopic
InquiryType IsVAEmployee IsVeteran IsVeteranAnEmployee IsVeteranDeceased
LevelOfAuthentication MedicalCenter MiddleName PreferredName Pronouns
StreetAddress2 SupervisorFlag VaEmployeeTimeStamp ZipCode
StreetAddress2 SupervisorFlag VaEmployeeTimeStamp ZipCode Suffix
]
end

Expand All @@ -130,7 +130,7 @@ def submitter_parameters
Submitter SubmitterDependent SubmitterDOB SubmitterGender SubmitterProvince
SubmitterSSN SubmitterState SubmitterStateOfResidency SubmitterStateOfSchool
SubmitterStateProperty SubmitterStreetAddress SubmitterVetCenter
SubmitterZipCodeOfResidency SubmitterQuestion
SubmitterZipCodeOfResidency SubmitterQuestion SubmittersDodIdEdipiNumber
]
end

Expand All @@ -143,7 +143,7 @@ def veteran_parameters
VeteranRelationship VeteranServiceEndDate VeteranServiceNumber
VeteranServiceStartDate VeteranSSN VeteransState VeteranStreetAddress
VeteranSuffix VeteranSuiteAptOther VeteranZipCode WhoWasTheirCounselor
YourLastName
YourLastName VeteranDodIdEdipiNumber
]
end

Expand Down
4 changes: 2 additions & 2 deletions modules/ask_va_api/app/lib/ask_va_api/inquiries/creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def initialize(icn:, service: nil)
@service = service || default_service
end

def call(params:)
post_data(payload: { params: })
def call(payload:)
post_data(payload:)
rescue => e
ErrorHandler.handle_service_error(e)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let(:icn) { '123456' }
let(:service) { instance_double(Crm::Service) }
let(:creator) { described_class.new(icn:, service:) }
let(:params) { { FirstName: 'Fake', YourLastName: 'Smith' } }
let(:payload) { { FirstName: 'Fake', YourLastName: 'Smith' } }
let(:endpoint) { AskVAApi::Inquiries::Creator::ENDPOINT }

before do
Expand All @@ -17,21 +17,21 @@
context 'when the API call is successful' do
before do
allow(service).to receive(:call).with(endpoint:, method: :put,
payload: { params: }).and_return({
Data: {
InquiryNumber: '530d56a8-affd-ee11' \
'-a1fe-001dd8094ff1'
},
Message: '',
ExceptionOccurred: false,
ExceptionMessage: '',
MessageId: 'b8ebd8e7-3bbf-49c5' \
'-aff0-99503e50ee27'
})
payload:).and_return({
Data: {
InquiryNumber: '530d56a8-affd-ee11' \
'-a1fe-001dd8094ff1'
},
Message: '',
ExceptionOccurred: false,
ExceptionMessage: '',
MessageId: 'b8ebd8e7-3bbf-49c5' \
'-aff0-99503e50ee27'
})
end

it 'posts data to the service and returns the response' do
expect(creator.call(params:)).to eq({ InquiryNumber: '530d56a8-affd-ee11-a1fe-001dd8094ff1' })
expect(creator.call(payload:)).to eq({ InquiryNumber: '530d56a8-affd-ee11-a1fe-001dd8094ff1' })
end
end

Expand All @@ -45,7 +45,7 @@
end

it 'raise InquiriesCreatorError' do
expect { creator.call(params:) }.to raise_error(ErrorHandler::ServiceError)
expect { creator.call(payload:) }.to raise_error(ErrorHandler::ServiceError)
end
end
end
Expand Down
68 changes: 34 additions & 34 deletions modules/ask_va_api/spec/requests/v0/inquiries_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,24 +332,24 @@
end

describe 'POST #create' do
let(:params) { { FirstName: 'Fake', YourLastName: 'Smith' } }
let(:payload) { { FirstName: 'Fake', YourLastName: 'Smith' } }
let(:endpoint) { AskVAApi::Inquiries::Creator::ENDPOINT }

context 'when successful' do
before do
allow_any_instance_of(Crm::Service).to receive(:call)
.with(endpoint:, method: :put,
payload: { params: }).and_return({
Data: {
Id: '530d56a8-affd-ee11-a1fe-001dd8094ff1'
},
Message: '',
ExceptionOccurred: false,
ExceptionMessage: '',
MessageId: 'b8ebd8e7-3bbf-49c5-aff0-99503e50ee27'
})
payload:).and_return({
Data: {
Id: '530d56a8-affd-ee11-a1fe-001dd8094ff1'
},
Message: '',
ExceptionOccurred: false,
ExceptionMessage: '',
MessageId: 'b8ebd8e7-3bbf-49c5-aff0-99503e50ee27'
})
sign_in(authorized_user)
post '/ask_va_api/v0/inquiries/auth', params:
post '/ask_va_api/v0/inquiries/auth', params: payload
end

it { expect(response).to have_http_status(:created) }
Expand All @@ -360,13 +360,13 @@
before do
allow_any_instance_of(Crm::Service).to receive(:call)
.with(endpoint:, method: :put,
payload: { params: }).and_return({ Data: nil,
Message: 'Data Validation: missing InquiryCategory',
ExceptionOccurred: true,
ExceptionMessage: 'Data Validation: missing InquiryCategory',
MessageId: '13bc59ea-c90a-4d48-8979-fe71e0f7ddeb' })
payload:).and_return({ Data: nil,
Message: 'Data Validation: missing InquiryCategory',
ExceptionOccurred: true,
ExceptionMessage: 'Data Validation: missing InquiryCategory',
MessageId: '13bc59ea-c90a-4d48-8979-fe71e0f7ddeb' })
sign_in(authorized_user)
post '/ask_va_api/v0/inquiries/auth', params:
post '/ask_va_api/v0/inquiries/auth', params: payload
end

it 'raise InquiriesCreatorError' do
Expand All @@ -380,23 +380,23 @@
end

describe 'POST #unauth_create' do
let(:params) { { FirstName: 'Fake', YourLastName: 'Smith' } }
let(:payload) { { FirstName: 'Fake', YourLastName: 'Smith' } }
let(:endpoint) { AskVAApi::Inquiries::Creator::ENDPOINT }

context 'when successful' do
before do
allow_any_instance_of(Crm::Service).to receive(:call)
.with(endpoint:, method: :put,
payload: { params: }).and_return({
Data: {
Id: '530d56a8-affd-ee11-a1fe-001dd8094ff1'
},
Message: '',
ExceptionOccurred: false,
ExceptionMessage: '',
MessageId: 'b8ebd8e7-3bbf-49c5-aff0-99503e50ee27'
})
post inquiry_path, params:
payload:).and_return({
Data: {
Id: '530d56a8-affd-ee11-a1fe-001dd8094ff1'
},
Message: '',
ExceptionOccurred: false,
ExceptionMessage: '',
MessageId: 'b8ebd8e7-3bbf-49c5-aff0-99503e50ee27'
})
post inquiry_path, params: payload
end

it { expect(response).to have_http_status(:created) }
Expand All @@ -407,12 +407,12 @@
before do
allow_any_instance_of(Crm::Service).to receive(:call)
.with(endpoint:, method: :put,
payload: { params: }).and_return({ Data: nil,
Message: 'Data Validation: missing InquiryCategory',
ExceptionOccurred: true,
ExceptionMessage: 'Data Validation: missing InquiryCategory',
MessageId: '13bc59ea-c90a-4d48-8979-fe71e0f7ddeb' })
post '/ask_va_api/v0/inquiries', params:
payload:).and_return({ Data: nil,
Message: 'Data Validation: missing InquiryCategory',
ExceptionOccurred: true,
ExceptionMessage: 'Data Validation: missing InquiryCategory',
MessageId: '13bc59ea-c90a-4d48-8979-fe71e0f7ddeb' })
post '/ask_va_api/v0/inquiries', params: payload
end

it 'raise InquiriesCreatorError' do
Expand Down
Loading

0 comments on commit 2cdc1e6

Please sign in to comment.