-
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.
Merge branch 'master' into dependabot/bundler/rubocop-1.69.0
- Loading branch information
Showing
6 changed files
with
84 additions
and
4 deletions.
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
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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module Eps | ||
class AppointmentService < BaseService | ||
## | ||
# Get appointments data from EPS | ||
# | ||
# @return OpenStruct response from EPS appointments endpoint | ||
# | ||
def get_appointments(patient_id:) | ||
response = perform(:get, "/#{config.base_path}/appointments?patientId=#{patient_id}", | ||
{}, headers) | ||
OpenStruct.new(response.body) | ||
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
59 changes: 59 additions & 0 deletions
59
modules/vaos/spec/services/eps/appointment_service_spec.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,59 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe Eps::AppointmentService do | ||
subject(:service) { described_class.new(user) } | ||
|
||
let(:user) { double('User', account_uuid: '1234') } | ||
let(:successful_appt_response) do | ||
double('Response', status: 200, body: { 'count' => 1, | ||
'appointments' => [ | ||
{ | ||
'id' => 'test-id', | ||
'state' => 'booked', | ||
'patientId' => patient_id | ||
} | ||
] }) | ||
end | ||
let(:patient_id) { 'test-patient-id' } | ||
let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) } | ||
|
||
describe 'get_appointments' do | ||
before do | ||
allow(Rails.cache).to receive(:fetch).and_return(memory_store) | ||
Rails.cache.clear | ||
end | ||
|
||
context 'when requesting appointments for a given patient_id' do | ||
before do | ||
allow_any_instance_of(VAOS::SessionService).to receive(:perform).and_return(successful_appt_response) | ||
end | ||
|
||
it 'returns the appointments scheduled' do | ||
exp_response = OpenStruct.new(successful_appt_response.body) | ||
|
||
expect(service.get_appointments(patient_id:)).to eq(exp_response) | ||
end | ||
end | ||
|
||
context 'when the endpoint fails to return appointments' do | ||
let(:failed_appt_response) do | ||
double('Response', status: 500, body: 'Unknown service exception') | ||
end | ||
let(:exception) do | ||
Common::Exceptions::BackendServiceException.new(nil, {}, failed_appt_response.status, | ||
failed_appt_response.body) | ||
end | ||
|
||
before do | ||
allow_any_instance_of(VAOS::SessionService).to receive(:perform).and_raise(exception) | ||
end | ||
|
||
it 'throws exception' do | ||
expect { service.get_appointments(patient_id:) }.to raise_error(Common::Exceptions::BackendServiceException, | ||
/VA900/) | ||
end | ||
end | ||
end | ||
end |