Skip to content

Commit

Permalink
VAOS - GET CC Eligibility (#3640)
Browse files Browse the repository at this point in the history
  • Loading branch information
saneshark authored Dec 16, 2019
1 parent e66b613 commit 0619232
Show file tree
Hide file tree
Showing 13 changed files with 401 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/initializers/inflections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

ActiveSupport::Inflector.inflections do |inflect|
inflect.acronym 'AWS'
inflect.acronym 'CC'
inflect.acronym 'DOD'
inflect.acronym 'EMIS'
inflect.acronym 'EVSS'
Expand Down
16 changes: 16 additions & 0 deletions modules/vaos/app/controllers/vaos/cc_eligibility_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module VAOS
class CCEligibilityController < VAOS::BaseController
def show
response = cce_service.get_eligibility(params[:service_type])
render json: VAOS::CCEligibilitySerializer.new(response[:data], meta: response[:meta])
end

private

def cce_service
VAOS::CCEligibilityService.for_user(current_user)
end
end
end
17 changes: 17 additions & 0 deletions modules/vaos/app/serializers/vaos/cc_eligibility_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

require 'fast_jsonapi'

module VAOS
class CCEligibilitySerializer
include FastJsonapi::ObjectSerializer

set_id do |object|
object.patient_request[:service_type]
end

set_type :cc_eligibility

attributes :eligible
end
end
39 changes: 39 additions & 0 deletions modules/vaos/app/services/vaos/cc_eligibility_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

require_relative '../vaos/concerns/headers'

module VAOS
class CCEligibilityService < Common::Client::Base
include Common::Client::Monitoring
include SentryLogging
include VAOS::Headers

configuration VAOS::Configuration

STATSD_KEY_PREFIX = 'api.vaos'

attr_accessor :user

def self.for_user(user)
as = VAOS::CCEligibilityService.new
as.user = user
as
end

def get_eligibility(service_type)
with_monitoring do
response = perform(:get, url(service_type), nil, headers(user))
{
data: OpenStruct.new(response.body),
meta: {}
}
end
end

private

def url(service_type)
"/cce/v1/patients/#{user.icn}/eligibility/#{service_type}"
end
end
end
7 changes: 6 additions & 1 deletion modules/vaos/app/services/vaos/middleware/response/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ def error_400(body)
end

def parse_error(body)
JSON.parse(body)['errors'].first['errorMessage']
parsed = JSON.parse(body)
if parsed['errors']
parsed['errors'].first['errorMessage']
else
parsed['message']
end
rescue
body
end
Expand Down
1 change: 1 addition & 0 deletions modules/vaos/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
resources :appointment_requests, only: %i[index create update] do
resources :messages, only: %i[index create]
end
get 'community_care/eligibility/:service_type', to: 'cc_eligibility#show'
resources :systems, only: :index do
resources :direct_scheduling_facilities, only: :index
resources :pact, only: :index
Expand Down
66 changes: 66 additions & 0 deletions modules/vaos/spec/request/cc_eligibility_request_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# frozen_string_literal: true

require 'rails_helper'
RSpec.describe 'vaos community care eligibility', type: :request do
include SchemaMatchers

before do
Flipper.enable('va_online_scheduling')
sign_in_as(current_user)
allow_any_instance_of(VAOS::UserService).to receive(:session).and_return('stubbed_token')
end

describe 'GET eligibility' do
let(:service_type) { 'PrimaryCare' }

context 'loa1 user with flipper enabled' do
let(:current_user) { build(:user, :loa1) }

it 'does not have access' do
get "/v0/vaos/community_care/eligibility/#{service_type}"
expect(response).to have_http_status(:forbidden)
expect(JSON.parse(response.body)['errors'].first['detail'])
.to eq('You do not have access to online scheduling')
end
end

context 'loa3 user' do
let(:current_user) { build(:user, :vaos) }

context 'with flipper disabled' do
it 'does not have access' do
Flipper.disable('va_online_scheduling')
get "/v0/vaos/community_care/eligibility/#{service_type}"
expect(response).to have_http_status(:forbidden)
expect(JSON.parse(response.body)['errors'].first['detail'])
.to eq('You do not have access to online scheduling')
end
end

it 'has access and returns eligibility true', :skip_mvi do
VCR.use_cassette('vaos/cc_eligibility/get_eligibility_true', match_requests_on: %i[method uri]) do
get "/v0/vaos/community_care/eligibility/#{service_type}"

expect(response).to have_http_status(:success)
expect(response.body).to be_a(String)
expect(json_body_for(response)).to match_schema('vaos/cc_eligibility')
end
end

context 'with access and invalid service_type' do
let(:service_type) { 'NotAType' }

it 'returns a validation error', :skip_mvi do
VCR.use_cassette('vaos/cc_eligibility/get_eligibility_400', match_requests_on: %i[method uri]) do
get "/v0/vaos/community_care/eligibility/#{service_type}"

expect(response).to have_http_status(:bad_request)
expect(response.body).to be_a(String)
expect(JSON.parse(response.body)['errors'].first['detail'])
.to eq('Unknown service type: NotAType')
end
end
end
end
end
end
9 changes: 9 additions & 0 deletions modules/vaos/spec/routing/vaos_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@
schedule_type: 'direct'
)
end

it 'routes to the community care eligibilty endpoint' do
expect(get('/v0/vaos/community_care/eligibility/PrimaryCare')).to route_to(
format: :json,
controller: 'vaos/cc_eligibility',
action: 'show',
service_type: 'PrimaryCare'
)
end
end
40 changes: 40 additions & 0 deletions modules/vaos/spec/services/cc_eligibility_service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

require 'rails_helper'

describe VAOS::CCEligibilityService do
subject { described_class.for_user(user) }

let(:user) { build(:user, :vaos) }
let(:service_type) { 'PrimaryCare' }

before { allow_any_instance_of(VAOS::UserService).to receive(:session).and_return('stubbed_token') }

describe '#get_eligibility', :skip_mvi do
it 'gets an eligibility of true' do
VCR.use_cassette('vaos/cc_eligibility/get_eligibility_true', match_requests_on: %i[method uri]) do
response = subject.get_eligibility(service_type)
expect(response[:data].eligible).to eq(true)
end
end

it 'gets an eligibility of false' do
VCR.use_cassette('vaos/cc_eligibility/get_eligibility_false', match_requests_on: %i[method uri]) do
response = subject.get_eligibility(service_type)
expect(response[:data].eligible).to eq(false)
end
end

context 'invalid service_type' do
let(:service_type) { 'NotAType' }

it 'handles 400 error appropriately' do
VCR.use_cassette('vaos/cc_eligibility/get_eligibility_400', match_requests_on: %i[method uri]) do
expect { subject.get_eligibility(service_type) }.to raise_error(
Common::Exceptions::BackendServiceException
)
end
end
end
end
end
15 changes: 15 additions & 0 deletions spec/support/schemas/vaos/cc_eligibility.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema" : "http://json-schema.org/draft-04/schema#",
"type": "object",
"required": ["id", "type", "attributes"],
"properties": {
"id": { "type": "string" },
"type": { "type": "string", "enum": ["cc_eligibility"] },
"attributes": {
"type": "object",
"properties": {
"eligible": { "type": "boolean" }
}
}
}
}

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

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

Loading

0 comments on commit 0619232

Please sign in to comment.