Skip to content

Commit 9261ded

Browse files
96447 Add drive times endpoint integration (#20027)
* rough draft impl * rspec * consolidate drive time service and specs into provider service and specs * EPS get_drive_times: update params * remove unneeded variable in spec --------- Co-authored-by: Corey Ferris <[email protected]>
1 parent b9b7401 commit 9261ded

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

modules/vaos/app/services/eps/provider_service.rb

+18
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ def get_networks
3535
OpenStruct.new(response.body)
3636
end
3737

38+
##
39+
# Get drive times from EPS
40+
#
41+
# @param destinations [Hash] Hash of UUIDs mapped to lat/long coordinates
42+
# @param origin [Hash] Hash containing origin lat/long coordinates
43+
# @return OpenStruct response from EPS drive times endpoint
44+
#
45+
def get_drive_times(destinations:, origin:)
46+
payload = {
47+
destinations: destinations,
48+
origin: origin
49+
}
50+
51+
response = perform(:post, "/#{config.base_path}/drive-times", payload, headers)
52+
OpenStruct.new(response.body)
53+
end
54+
55+
##
3856
# Retrieves available slots for a specific provider.
3957
#
4058
# @param provider_id [String] The unique identifier of the provider

modules/vaos/spec/services/eps/provider_service_spec.rb

+64
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,70 @@
126126
end
127127
end
128128

129+
describe 'get_drive_times' do
130+
let(:destinations) do
131+
{
132+
'provider-123' => {
133+
latitude: 40.7128,
134+
longitude: -74.0060
135+
}
136+
}
137+
end
138+
let(:origin) do
139+
{
140+
latitude: 40.7589,
141+
longitude: -73.9851
142+
}
143+
end
144+
145+
context 'when the request is successful' do
146+
let(:response) do
147+
double('Response', status: 200, body: {
148+
'destinations' => {
149+
'00eff3f3-ecfb-41ff-9ebc-78ed811e17f9' => {
150+
'distanceInMiles' => '4',
151+
'driveTimeInSecondsWithTraffic' => '566',
152+
'driveTimeInSecondsWithoutTraffic' => '493',
153+
'latitude' => '-74.12870564772521',
154+
'longitude' => '-151.6240405624497'
155+
}
156+
},
157+
'origin' => {
158+
'latitude' => '4.627174468915552',
159+
'longitude' => '-88.72187894562788'
160+
}
161+
})
162+
end
163+
164+
before do
165+
allow_any_instance_of(VAOS::SessionService).to receive(:perform).and_return(response)
166+
end
167+
168+
it 'returns the calculated drive times' do
169+
result = service.get_drive_times(destinations:, origin:)
170+
171+
expect(result).to eq(OpenStruct.new(response.body))
172+
end
173+
end
174+
175+
context 'when the request fails' do
176+
let(:response) { double('Response', status: 500, body: 'Unknown service exception') }
177+
let(:exception) do
178+
Common::Exceptions::BackendServiceException.new(nil, {}, response.status, response.body)
179+
end
180+
181+
before do
182+
allow_any_instance_of(VAOS::SessionService).to receive(:perform).and_raise(exception)
183+
end
184+
185+
it 'raises an error' do
186+
expect do
187+
service.get_drive_times(destinations:, origin:)
188+
end.to raise_error(Common::Exceptions::BackendServiceException, /VA900/)
189+
end
190+
end
191+
end
192+
129193
describe '#get_provider_slots' do
130194
let(:provider_id) { '9mN718pH' }
131195
let(:required_params) do

0 commit comments

Comments
 (0)