Skip to content

Commit

Permalink
59503 add schedulable param to get_facilities (#12865)
Browse files Browse the repository at this point in the history
* add schedulable param
  • Loading branch information
cferris32 authored Jun 13, 2023
1 parent 4c43ff8 commit e41fd07
Show file tree
Hide file tree
Showing 9 changed files with 571 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class FacilitiesController < VAOS::BaseController
def index
response = mobile_facility_service.get_facilities(ids:,
children:,
type:)
type:,
schedulable:)
render json: VAOS::V2::FacilitiesSerializer.new(response[:data], meta: response[:meta])
end

Expand Down Expand Up @@ -43,6 +44,10 @@ def children
def type
params[:type]
end

def schedulable
params[:schedulable]
end
end
end
end
5 changes: 5 additions & 0 deletions modules/vaos/app/docs/vaos/v2/vaos_v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ paths:
schema:
type: boolean
description: Indicates whether child facilities should be returned for matching parent facilities.
- in: query
name: schedulable
schema:
type: boolean
description: Filters facilities based on their schedulability, will return schedulable ones if true and non schedulable ones if false.
responses:
'200':
description: Success
Expand Down
5 changes: 3 additions & 2 deletions modules/vaos/app/services/vaos/v2/mobile_facility_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ def get_clinics(station_id, *clinic_ids)
# - :data: A hash containing information about the facilities
# - :meta: A hash containing pagination information
#
def get_facilities(ids:, children: nil, type: nil, pagination_params: {})
def get_facilities(ids:, children: nil, type: nil, schedulable: nil, pagination_params: {})
params = {
ids:,
children:,
type:
type:,
schedulable:
}.merge(page_params(pagination_params)).compact
with_monitoring do
options = { params_encoder: Faraday::FlatParamsEncoder }
Expand Down
55 changes: 55 additions & 0 deletions modules/vaos/spec/request/v2/facilities_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,61 @@
end
end

context 'on successful query for facilities given schedulable true' do
it 'returns schedulable facilities' do
VCR.use_cassette('vaos/v2/mobile_facility_service/get_facilities_200_schedulable_true',
match_requests_on: %i[method path query]) do
get '/vaos/v2/facilities?ids=983,%20983GB,%20983GC,%20983GD&pageSize=0&schedulable=true',
headers: inflection_header
expect(response).to have_http_status(:ok)
expect(response.body).to be_a(String)
expect(JSON.parse(response.body)['data'].size).to eq(4)
expect(response).to match_camelized_response_schema('vaos/v2/get_facilities', { strict: false })
end
end
end

context 'on successful query for facilities given schedulable false' do
it 'filters out schedulable facilities' do
VCR.use_cassette('vaos/v2/mobile_facility_service/get_facilities_200_schedulable_false',
match_requests_on: %i[method path query]) do
get '/vaos/v2/facilities?ids=983,%20983GB,%20983GC,%20983GD&pageSize=0&schedulable=false',
headers: inflection_header
expect(response).to have_http_status(:ok)
expect(response.body).to be_a(String)
expect(JSON.parse(response.body)['data'].size).to eq(0)
expect(response).to match_camelized_response_schema('vaos/v2/get_facilities', { strict: false })
end
end
end

context 'on successful query for facilities given schedulable not passed' do
it 'returns unfiltered facilities' do
VCR.use_cassette('vaos/v2/mobile_facility_service/get_facilities_200_schedulable_not_passed',
match_requests_on: %i[method path query]) do
get '/vaos/v2/facilities?ids=983,%20983GB,%20983GC,%20983GD&pageSize=0',
headers: inflection_header
expect(response).to have_http_status(:ok)
expect(response.body).to be_a(String)
expect(JSON.parse(response.body)['data'].size).to eq(4)
expect(response).to match_camelized_response_schema('vaos/v2/get_facilities', { strict: false })
end
end
end

context 'on sending request with schedulable and children params' do
it 'returns a 400 http status' do
VCR.use_cassette('vaos/v2/mobile_facility_service/get_facilities_with_children_and_schedulable_true_400',
match_requests_on: %i[method path query]) do
get '/vaos/v2/facilities?children=true&ids=688&pageSize=0&schedulable=true'
expect(response).to have_http_status(:bad_request)
expect(JSON.parse(response.body)['errors'][0]['code']).to eq('VAOS_400')
expect(JSON.parse(response.body)['errors'][0]['detail']).to eq('children param is only allowed ' \
'in conjunction with the ids param.')
end
end
end

context 'on sending a bad request to the VAOS Service' do
it 'returns a 400 http status' do
VCR.use_cassette('vaos/v2/mobile_facility_service/get_facilities_400',
Expand Down
47 changes: 47 additions & 0 deletions modules/vaos/spec/services/v2/mobile_facility_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,42 @@
end
end

context 'with facility ids and schedulable not passed' do
it 'returns configurations' do
VCR.use_cassette('vaos/v2/mobile_facility_service/get_facilities_200_schedulable_not_passed',
match_requests_on: %i[method path query]) do
response = subject.get_facilities(ids: '983, 983GB, 983GC, 983GD')
expect(response[:data][0][:classification]).to eq('Primary Care CBOC')
expect(response[:data][1][:classification]).to eq('Multi-Specialty CBOC')
expect(response[:data][2][:classification]).to eq('Other Outpatient Services (OOS)')
expect(response[:data][3][:classification]).to eq('VA Medical Center (VAMC)')
end
end
end

context 'with facility ids and schedulable false' do
it 'filters out schedulable configurations' do
VCR.use_cassette('vaos/v2/mobile_facility_service/get_facilities_200_schedulable_false',
match_requests_on: %i[method path query]) do
response = subject.get_facilities(ids: '983, 983GB, 983GC, 983GD', schedulable: false)
expect(response[:data].size).to eq(0)
end
end
end

context 'with facility ids and schedulable true' do
it 'returns schedulable configurations' do
VCR.use_cassette('vaos/v2/mobile_facility_service/get_facilities_200_schedulable_true',
match_requests_on: %i[method path query]) do
response = subject.get_facilities(ids: '983, 983GB, 983GC, 983GD', schedulable: true)
expect(response[:data][0][:classification]).to eq('Primary Care CBOC')
expect(response[:data][1][:classification]).to eq('Multi-Specialty CBOC')
expect(response[:data][2][:classification]).to eq('Other Outpatient Services (OOS)')
expect(response[:data][3][:classification]).to eq('VA Medical Center (VAMC)')
end
end
end

context 'with multiple facility ids' do
it 'returns a configuration' do
VCR.use_cassette('vaos/v2/mobile_facility_service/get_facilities_200',
Expand All @@ -88,6 +124,17 @@
end
end

context 'with a facility id and children true and facilities true' do
it 'raises bad request error - children param is only allowed in conjunction with the ids param' do
VCR.use_cassette('vaos/v2/mobile_facility_service/get_facilities_with_children_and_schedulable_true_400',
match_requests_on: %i[method path query]) do
expect { subject.get_facilities(children: true, schedulable: true, ids: '688') }.to raise_error(
Common::Exceptions::BackendServiceException
)
end
end
end

context 'when the upstream server returns a 400' do
it 'raises a backend exception' do
VCR.use_cassette('vaos/v2/mobile_facility_service/get_facilities_400',
Expand Down

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 e41fd07

Please sign in to comment.