Skip to content

Commit

Permalink
Migrate 1010ez disability rating code to BGS (#12442)
Browse files Browse the repository at this point in the history
* remove prefill compensation type

* find rating data method

* add rating info method to hca controller

* convert disability rating to integer

* add swagger

* lint
  • Loading branch information
lihanli authored Apr 24, 2023
1 parent fa42e72 commit a40b2ac
Show file tree
Hide file tree
Showing 11 changed files with 295 additions and 65 deletions.
15 changes: 14 additions & 1 deletion app/controllers/v0/health_care_applications_controller.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
# frozen_string_literal: true

require 'hca/service'
require 'bgs/service'

module V0
class HealthCareApplicationsController < ApplicationController
FORM_ID = '1010ez'

skip_before_action(:authenticate)
skip_before_action(:authenticate, only: %i[create show enrollment_status healthcheck])

before_action :record_submission_attempt, only: :create
before_action :load_user, only: %i[create enrollment_status]

def rating_info
service = BGS::Service.new(current_user)
disability_rating = service.find_rating_data[:disability_rating_record][:service_connected_combined_degree]

render(
json: {
user_percent_of_disability: disability_rating
},
serializer: HCARatingInfoSerializer
)
end

def create
@health_care_application.async_compatible = params[:async_all]
@health_care_application.google_analytics_client_id = params[:ga_client_id]
Expand Down
17 changes: 0 additions & 17 deletions app/models/health_care_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,21 +203,6 @@ def long_form_required_fields
end
end

def prefill_compensation_type
auth_headers = EVSS::DisabilityCompensationAuthHeaders.new(user).add_headers(EVSS::AuthHeaders.new(user).to_h)
rating_info_service = EVSS::CommonService.new(auth_headers)
response = rating_info_service.get_rating_info

return if response.user_percent_of_disability.nil?

Raven.extra_context(disability_rating: response.user_percent_of_disability)

parsed_form['vaCompensationType'] = 'highDisability' if response.user_percent_of_disability >= DISABILITY_THRESHOLD
rescue => e
Raven.extra_context(disability_rating: 'error')
log_exception_to_sentry(e)
end

def prefill_fields
return if user.blank? || !user.loa3?

Expand All @@ -226,8 +211,6 @@ def prefill_fields
'veteranDateOfBirth' => user.birth_date,
'veteranSocialSecurityNumber' => user.ssn_normalized
}.compact)

prefill_compensation_type
end

def submit_async(has_email)
Expand Down
13 changes: 13 additions & 0 deletions app/serializers/hca_rating_info_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

class HCARatingInfoSerializer < ActiveModel::Serializer
attribute :user_percent_of_disability

def user_percent_of_disability
object[:user_percent_of_disability].to_i
end

def id
nil
end
end
26 changes: 26 additions & 0 deletions app/swagger/swagger/requests/health_care_applications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,32 @@ module Requests
class HealthCareApplications
include Swagger::Blocks

swagger_path '/v0/health_care_applications/rating_info' do
operation :get do
key :description, 'Get the user\'s service connected disability rating'
key :operationId, 'getDisabilityRating'
key :tags, %w[benefits_forms]

response 200 do
key :description, 'disability rating response'

schema do
property :data, type: :object do
key :required, %i[attributes]
property :id, type: :string
property :type, type: :string

property :attributes, type: :object do
key :required, %i[user_percent_of_disability]

property :user_percent_of_disability, type: :integer
end
end
end
end
end
end

swagger_path '/v0/health_care_applications/{id}' do
operation :get do
key :description, 'Show the status of a health care application'
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
collection do
get(:healthcheck)
get(:enrollment_status)
get(:rating_info)
end
end

Expand Down
4 changes: 4 additions & 0 deletions lib/bgs/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def create_proc(proc_state: 'Started')
end
end

def find_rating_data
service.rating.find_rating_data(@user.ssn)
end

def create_proc_form(vnp_proc_id, form_type_code)
# Temporary log proc_id to sentry
log_message_to_sentry(vnp_proc_id, :warn, '', { team: 'vfs-ebenefits' })
Expand Down
11 changes: 11 additions & 0 deletions spec/lib/bgs/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
let(:participant_id) { '149456' }
let(:first_name) { 'abraham.lincoln@vets.gov' }

describe '#find_rating_data' do
let(:user_object) { build(:ch33_dd_user) }

it 'gets the users disability rating data' do
VCR.use_cassette('bgs/service/find_rating_data', VCR::MATCH_EVERYTHING) do
response = bgs_service.find_rating_data
expect(response[:disability_rating_record][:service_connected_combined_degree]).to eq('100')
end
end
end

context 'direct deposit methods' do
let(:user_object) { build(:ch33_dd_user, first_name:) }

Expand Down
47 changes: 0 additions & 47 deletions spec/models/health_care_application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,7 @@
let(:inelig_character_of_discharge) { HCA::EnrollmentEligibility::Constants::INELIG_CHARACTER_OF_DISCHARGE }
let(:login_required) { HCA::EnrollmentEligibility::Constants::LOGIN_REQUIRED }

describe '#prefill_compensation_type' do
before do
health_care_application.user = FactoryBot.build(:evss_user)
allow(Raven).to receive(:extra_context)
end

it 'prefills compensation type' do
VCR.use_cassette('evss/disability_compensation_form/rating_info_with_disability') do
expect(Raven).to receive(:extra_context).with(disability_rating: 100)
health_care_application.send(:prefill_compensation_type)
expect(health_care_application.parsed_form['vaCompensationType']).to eq('highDisability')
end
end

context 'when disability_rating is nil' do
it 'does nothing' do
expect_any_instance_of(EVSS::CommonService).to receive(
:get_rating_info
).and_return(OpenStruct.new(user_percent_of_disability: nil))

expect(health_care_application).not_to receive(:log_exception_to_sentry)

health_care_application.send(:prefill_compensation_type)

expect(health_care_application.parsed_form['vaCompensationType']).to eq(nil)
end
end

context 'with an error' do
it 'logs to sentry and doesnt raise the error' do
expect(health_care_application).to receive(:log_exception_to_sentry)
expect(Raven).to receive(:extra_context).with(disability_rating: 'error')

health_care_application.send(:prefill_compensation_type)
expect(health_care_application.parsed_form['vaCompensationType']).to eq(nil)
end
end
end

describe '#prefill_fields' do
before do
allow(health_care_application).to receive(:prefill_compensation_type)
end

let(:health_care_application) { build(:health_care_application) }

context 'with missing fields' do
Expand Down Expand Up @@ -93,8 +50,6 @@
end

it 'doesnt set a field if the user data is null' do
expect(health_care_application).to receive(:prefill_compensation_type)

health_care_application.send(:prefill_fields)

parsed_form = health_care_application.parsed_form
Expand All @@ -104,8 +59,6 @@
end

it 'sets uneditable fields using user data' do
expect(health_care_application).to receive(:prefill_compensation_type)

expect(health_care_application.valid?).to eq(false)
health_care_application.send(:prefill_fields)
expect(health_care_application.valid?).to eq(true)
Expand Down
18 changes: 18 additions & 0 deletions spec/requests/health_care_applications_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@
)
end

describe 'GET rating_info' do
let(:current_user) { build(:ch33_dd_user) }

before do
sign_in_as(current_user)
end

it 'returns the users rating info' do
VCR.use_cassette('bgs/service/find_rating_data', VCR::MATCH_EVERYTHING) do
get(rating_info_v0_health_care_applications_path)
end

expect(JSON.parse(response.body)['data']['attributes']).to eq(
{ 'user_percent_of_disability' => 100 }
)
end
end

describe 'GET healthcheck' do
subject do
get(healthcheck_v0_health_care_applications_path)
Expand Down
15 changes: 15 additions & 0 deletions spec/requests/swagger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,21 @@
json.delete('email')
json.to_json
end
let(:user) { build(:ch33_dd_user) }
let(:headers) do
{ '_headers' => { 'Cookie' => sign_in(user, nil, true) } }
end

it 'supports getting the disability rating' do
VCR.use_cassette('bgs/service/find_rating_data', VCR::MATCH_EVERYTHING) do
expect(subject).to validate(
:get,
'/v0/health_care_applications/rating_info',
200,
headers
)
end
end

it 'supports getting the hca enrollment status' do
expect(HealthCareApplication).to receive(:user_icn).and_return('123')
Expand Down
Loading

0 comments on commit a40b2ac

Please sign in to comment.