|
126 | 126 | end
|
127 | 127 | end
|
128 | 128 |
|
| 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 | + |
129 | 193 | describe '#get_provider_slots' do
|
130 | 194 | let(:provider_id) { '9mN718pH' }
|
131 | 195 | let(:required_params) do
|
|
0 commit comments