From 9261ded8bb04471409a5957e4ac8a76b31f0c935 Mon Sep 17 00:00:00 2001 From: Gaurav Gupta Date: Fri, 27 Dec 2024 11:01:31 -0800 Subject: [PATCH] 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 --- .../vaos/app/services/eps/provider_service.rb | 18 ++++++ .../services/eps/provider_service_spec.rb | 64 +++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/modules/vaos/app/services/eps/provider_service.rb b/modules/vaos/app/services/eps/provider_service.rb index 5062ee537a4..ab06ea4dcc5 100644 --- a/modules/vaos/app/services/eps/provider_service.rb +++ b/modules/vaos/app/services/eps/provider_service.rb @@ -35,6 +35,24 @@ def get_networks OpenStruct.new(response.body) end + ## + # 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(destinations:, origin:) + payload = { + destinations: destinations, + origin: origin + } + + 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 diff --git a/modules/vaos/spec/services/eps/provider_service_spec.rb b/modules/vaos/spec/services/eps/provider_service_spec.rb index c67ae661063..c3d81c5aef1 100644 --- a/modules/vaos/spec/services/eps/provider_service_spec.rb +++ b/modules/vaos/spec/services/eps/provider_service_spec.rb @@ -126,6 +126,70 @@ end end + describe 'get_drive_times' 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(response) + end + + it 'returns the calculated drive times' do + result = service.get_drive_times(destinations:, origin:) + + expect(result).to eq(OpenStruct.new(response.body)) + end + 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, {}, response.status, response.body) + 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