Skip to content

Commit

Permalink
Validating 526 for no claims (#3471)
Browse files Browse the repository at this point in the history
* Validating 526 for no claims

* rubocop fix

* validating initial claim

* fixing validation error

* fixing EVSSError

* V1 test spec

* last fix

* reducing complexity

* rubocop fix
  • Loading branch information
bastosmichael authored Nov 12, 2019
1 parent dbb95e4 commit 348439e
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_dependency 'claims_api/concerns/mvi_verification'
require_dependency 'claims_api/concerns/header_validation'
require_dependency 'claims_api/unsynchronized_evss_claims_service'

module ClaimsApi
class ApplicationController < ::OpenidApplicationController
Expand All @@ -12,6 +13,10 @@ class ApplicationController < ::OpenidApplicationController

private

def claims_service
ClaimsApi::UnsynchronizedEVSSClaimService.new(target_veteran)
end

def header(key)
request.headers[key]
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# frozen_string_literal: true

require_dependency 'claims_api/application_controller'
require_dependency 'claims_api/unsynchronized_evss_claims_service'

module ClaimsApi
module V0
class ClaimsController < ApplicationController
skip_before_action(:authenticate)

def index
claims = service.all
claims = claims_service.all
render json: claims,
serializer: ActiveModel::Serializer::CollectionSerializer,
each_serializer: ClaimsApi::ClaimListSerializer
Expand Down Expand Up @@ -40,13 +39,9 @@ def show
private

def fetch_and_render_evss_claim(id)
claim = service.update_from_remote(id)
claim = claims_service.update_from_remote(id)
render json: claim, serializer: ClaimsApi::ClaimDetailSerializer
end

def service
ClaimsApi::UnsynchronizedEVSSClaimService.new(target_veteran)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require_dependency 'claims_api/application_controller'
require_dependency 'claims_api/unsynchronized_evss_claims_service'
require_dependency 'claims_api/concerns/poa_verification'

module ClaimsApi
Expand All @@ -11,7 +10,7 @@ class ClaimsController < ApplicationController
before_action { permit_scopes %w[claim.read] }

def index
claims = service.all
claims = claims_service.all
render json: claims,
serializer: ActiveModel::Serializer::CollectionSerializer,
each_serializer: ClaimsApi::ClaimListSerializer
Expand Down Expand Up @@ -42,13 +41,9 @@ def show
private

def fetch_and_render_evss_claim(id)
claim = service.update_from_remote(id)
claim = claims_service.update_from_remote(id)
render json: claim, serializer: ClaimsApi::ClaimDetailSerializer
end

def service
ClaimsApi::UnsynchronizedEVSSClaimService.new(target_veteran)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class DisabilityCompensationController < BaseDisabilityCompensationController

before_action { permit_scopes %w[claim.write] }
before_action :validate_json_schema, only: %i[submit_form_526 validate_form_526]
before_action :validate_initial_claim, only: %i[submit_form_526 validate_form_526]
before_action :validate_documents_page_size, only: %i[upload_supporting_documents]

def submit_form_526
Expand Down Expand Up @@ -69,6 +70,20 @@ def source_name
user = poa_request? ? @current_user : target_veteran
"#{user.first_name} #{user.last_name}"
end

def validate_initial_claim
if claims_service.claims_count.zero? && form_attributes['autoCestPDFGenerationDisabled'] == false
error = {
errors: [
{
status: 422,
details: 'Veteran has no claims, autoCestPDFGenerationDisabled requires true for Initial Claim'
}
]
}
render json: error, status: :unprocessable_entity
end
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ def initialize(user)
@user = user
end

def raw_claims
@raw_claims ||= client.all_claims.body
end

def all
raw_claims = client.all_claims.body
EVSS_CLAIM_KEYS.each_with_object([]) do |key, claim_accum|
next unless raw_claims[key]

Expand All @@ -25,6 +28,14 @@ def all
end.flatten
end

def claims_count
EVSS_CLAIM_KEYS.reduce(0) do |sum, key|
sum + (raw_claims[key].try(:count) || 0)
end
rescue EVSS::ErrorMiddleware::EVSSError
0
end

def update_from_remote(evss_id)
raw_claim = client.find_claim_by_id(evss_id).body.fetch('claim', {})
create_claim(evss_id, :data, raw_claim)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,49 @@

it 'returns a successful response with all the data' do
with_okta_user(scopes) do |auth_header|
klass = EVSS::DisabilityCompensationForm::ServiceAllClaim
expect_any_instance_of(klass).to receive(:validate_form526).and_return(true)
post path, params: data, headers: headers.merge(auth_header)
parsed = JSON.parse(response.body)
expect(parsed['data']['type']).to eq('claims_api_claim')
expect(parsed['data']['attributes']['status']).to eq('pending')
VCR.use_cassette('evss/claims/claims') do
klass = EVSS::DisabilityCompensationForm::ServiceAllClaim
expect_any_instance_of(klass).to receive(:validate_form526).and_return(true)
post path, params: data, headers: headers.merge(auth_header)
parsed = JSON.parse(response.body)
expect(parsed['data']['type']).to eq('claims_api_claim')
expect(parsed['data']['attributes']['status']).to eq('pending')
end
end
end

it 'creates the sidekick job' do
with_okta_user(scopes) do |auth_header|
klass = EVSS::DisabilityCompensationForm::ServiceAllClaim
expect_any_instance_of(klass).to receive(:validate_form526).and_return(true)
expect(ClaimsApi::ClaimEstablisher).to receive(:perform_async)
post path, params: data, headers: headers.merge(auth_header)
VCR.use_cassette('evss/claims/claims') do
klass = EVSS::DisabilityCompensationForm::ServiceAllClaim
expect_any_instance_of(klass).to receive(:validate_form526).and_return(true)
expect(ClaimsApi::ClaimEstablisher).to receive(:perform_async)
post path, params: data, headers: headers.merge(auth_header)
end
end
end

it 'assigns a source' do
with_okta_user(scopes) do |auth_header|
klass = EVSS::DisabilityCompensationForm::ServiceAllClaim
expect_any_instance_of(klass).to receive(:validate_form526).and_return(true)
post path, params: data, headers: headers.merge(auth_header)
token = JSON.parse(response.body)['data']['attributes']['token']
aec = ClaimsApi::AutoEstablishedClaim.find(token)
expect(aec.source).to eq('abraham lincoln')
VCR.use_cassette('evss/claims/claims') do
klass = EVSS::DisabilityCompensationForm::ServiceAllClaim
expect_any_instance_of(klass).to receive(:validate_form526).and_return(true)
post path, params: data, headers: headers.merge(auth_header)
token = JSON.parse(response.body)['data']['attributes']['token']
aec = ClaimsApi::AutoEstablishedClaim.find(token)
expect(aec.source).to eq('abraham lincoln')
end
end
end

it 'builds the auth headers' do
with_okta_user(scopes) do |auth_header|
auth_header_stub = instance_double('EVSS::DisabilityCompensationAuthHeaders')
expect(EVSS::DisabilityCompensationAuthHeaders).to(receive(:new).twice { auth_header_stub })
expect(auth_header_stub).to receive(:add_headers).twice
post path, params: data, headers: headers.merge(auth_header)
VCR.use_cassette('evss/claims/claims') do
auth_header_stub = instance_double('EVSS::DisabilityCompensationAuthHeaders')
expect(EVSS::DisabilityCompensationAuthHeaders).to(receive(:new).twice { auth_header_stub })
expect(auth_header_stub).to receive(:add_headers).twice
post path, params: data, headers: headers.merge(auth_header)
end
end
end

Expand Down Expand Up @@ -114,22 +122,26 @@
it 'returns a successful response when valid' do
VCR.use_cassette('evss/disability_compensation_form/form_526_valid_validation') do
with_okta_user(scopes) do |auth_header|
data = File.read(Rails.root.join('modules', 'claims_api', 'spec', 'fixtures', 'form_526_json_api.json'))
post '/services/claims/v1/forms/526/validate', params: data, headers: headers.merge(auth_header)
parsed = JSON.parse(response.body)
expect(parsed['data']['type']).to eq('claims_api_auto_established_claim_validation')
expect(parsed['data']['attributes']['status']).to eq('valid')
VCR.use_cassette('evss/claims/claims') do
data = File.read(Rails.root.join('modules', 'claims_api', 'spec', 'fixtures', 'form_526_json_api.json'))
post '/services/claims/v1/forms/526/validate', params: data, headers: headers.merge(auth_header)
parsed = JSON.parse(response.body)
expect(parsed['data']['type']).to eq('claims_api_auto_established_claim_validation')
expect(parsed['data']['attributes']['status']).to eq('valid')
end
end
end
end

it 'returns a list of errors when invalid hitting EVSS' do
with_okta_user(scopes) do |auth_header|
VCR.use_cassette('evss/disability_compensation_form/form_526_invalid_validation') do
post '/services/claims/v1/forms/526/validate', params: data, headers: headers.merge(auth_header)
parsed = JSON.parse(response.body)
expect(response.status).to eq(422)
expect(parsed['errors'].size).to eq(2)
VCR.use_cassette('evss/claims/claims') do
post '/services/claims/v1/forms/526/validate', params: data, headers: headers.merge(auth_header)
parsed = JSON.parse(response.body)
expect(response.status).to eq(422)
expect(parsed['errors'].size).to eq(2)
end
end
end
end
Expand Down

0 comments on commit 348439e

Please sign in to comment.