-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
401 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
modules/vaos/app/controllers/vaos/cc_eligibility_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
modules/vaos/app/serializers/vaos/cc_eligibility_serializer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } | ||
} | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
spec/support/vcr_cassettes/vaos/cc_eligibility/get_eligibility_400.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
64 changes: 64 additions & 0 deletions
64
spec/support/vcr_cassettes/vaos/cc_eligibility/get_eligibility_false.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.