Skip to content

Commit

Permalink
EPS get_drive_times: update params
Browse files Browse the repository at this point in the history
  • Loading branch information
randomsync committed Dec 25, 2024
1 parent 4092f7b commit ce91d59
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 54 deletions.
24 changes: 8 additions & 16 deletions modules/vaos/app/services/eps/provider_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,21 @@ def get_networks
##
# Get drive times from EPS
#
# @param destinations [Hash] Hash of UUIDs mapped to lat/long coordinates
# @param origin [Hash] Hash containing origin lat/long coordinates
# @return OpenStruct response from EPS drive times endpoint
#
def get_drive_times(latitude, longitude)

# Latitude and longitude from provider data passed in and used here
destinations = {
"12345-abcdef": {
latitude: latitude,
longitude: longitude
}
}

origin: {
# TODO: verify user object attributes (ie, is this where we get origin lat/long from)
latitude: user.latitude,
longitude: user.longitude
def get_drive_times(destinations:, origin:)
payload = {
destinations: destinations,
origin: origin
}

response = perform(:get, "/#{config.base_path}/drive-times",
{ destinations: destinations, origin: origin }, headers)
response = perform(:post, "/#{config.base_path}/drive-times", payload, headers)
OpenStruct.new(response.body)
end

##
# Retrieves available slots for a specific provider.
#
# @param provider_id [String] The unique identifier of the provider
Expand Down
89 changes: 51 additions & 38 deletions modules/vaos/spec/services/eps/provider_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,6 @@
let(:config) { instance_double(Eps::Configuration) }
let(:headers) { { 'Authorization' => 'Bearer token123' } }

let(:successful_drive_time_response) do
double('Response', status: 200, body: {
'destinations' => {
'00eff3f3-ecfb-41ff-9ebc-78ed811e17f9' => {
'distanceInMiles' => '4',
'driveTimeInSecondsWithTraffic' => '566',
'driveTimeInSecondsWithoutTraffic' => '493',
'latitude' => '-74.12870564772521',
'longitude' => '-151.6240405624497'
},
'69cd9203-5e92-47a3-aa03-94b03752872a' => {
'distanceInMiles' => '9',
'driveTimeInSecondsWithTraffic' => '1314',
'driveTimeInSecondsWithoutTraffic' => '1039',
'latitude' => '-1.7437745123171688',
'longitude' => '-54.19187859370315'
}
},
'origin' => {
'latitude' => '4.627174468915552',
'longitude' => '-88.72187894562788'
}
})
end
let(:referral_id) { 'test-referral-id' }
# TODO: make successful_referrals_response test object,
# once we know what that should look like.
Expand Down Expand Up @@ -155,32 +131,69 @@
end

describe 'get_drive_times' do
context 'when requesting drive times for a logged in user' do
let(:destinations) do
{
'provider-123' => {
latitude: 40.7128,
longitude: -74.0060
}
}
end
let(:origin) do
{
latitude: 40.7589,
longitude: -73.9851
}
end

context 'when the request is successful' do
let(:response) do
double('Response', status: 200, body: {
'destinations' => {
'00eff3f3-ecfb-41ff-9ebc-78ed811e17f9' => {
'distanceInMiles' => '4',
'driveTimeInSecondsWithTraffic' => '566',
'driveTimeInSecondsWithoutTraffic' => '493',
'latitude' => '-74.12870564772521',
'longitude' => '-151.6240405624497'
}
},
'origin' => {
'latitude' => '4.627174468915552',
'longitude' => '-88.72187894562788'
}
})
end

before do
allow_any_instance_of(VAOS::SessionService).to receive(:perform).and_return(successful_drive_time_response)
allow_any_instance_of(VAOS::SessionService).to receive(:perform).and_return(response)
end

it 'returns the calculated drive times' do
exp_response = OpenStruct.new(successful_drive_time_response.body)
result = service.get_drive_times(destinations:, origin:)

expect(service.get_drive_times).to eq(exp_response)
expect(result).to eq(OpenStruct.new(response.body))
end
end

context 'when the endpoint fails to return appointments' do
let(:failed_drive_time_response) do
double('Response', status: 500, body: 'Unknown service exception')
end
context 'when the request fails' do
let(:response) { double('Response', status: 500, body: 'Unknown service exception') }
let(:exception) do
Common::Exceptions::BackendServiceException.new(nil, {}, failed_drive_time_response.status,
failed_drive_time_response.body)
Common::Exceptions::BackendServiceException.new(nil, {}, response.status, response.body)
end

it 'throws exception' do
expect { service.get_drive_times }.to raise_error(Common::Exceptions::BackendServiceException,
/VA900/)
end
before do
allow_any_instance_of(VAOS::SessionService).to receive(:perform).and_raise(exception)
end

it 'raises an error' do
expect do
service.get_drive_times(destinations:, origin:)
end.to raise_error(Common::Exceptions::BackendServiceException, /VA900/)
end
end
end

describe '#get_provider_slots' do
let(:provider_id) { '9mN718pH' }
let(:required_params) do
Expand Down

0 comments on commit ce91d59

Please sign in to comment.