Skip to content

Commit

Permalink
feat: error handling for missing location
Browse files Browse the repository at this point in the history
  • Loading branch information
noahdurbin committed Aug 6, 2024
1 parent e30d1f7 commit 5e4f940
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 6 deletions.
16 changes: 10 additions & 6 deletions app/facades/road_trip_facade.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
class RoadTripFacade
def new_trip(params)
trip = MapquestService.new.trip(params[:origin], params[:destination])
if (params[:origin] != "") && (params[:destination] != "")
trip = MapquestService.new.trip(params[:origin], params[:destination])

if trip.nil?
impossible_trip_response(params[:origin], params[:destination])
if trip.nil?
impossible_trip_response(params[:origin], params[:destination])
else
weather = WeatherFacade.new.get_weather(params[:destination])
weather_on_arrival = weather.future_weather(trip.time)
RoadTripSerializer.new(trip, weather_on_arrival).serialize_json
end
else
weather = WeatherFacade.new.get_weather(params[:destination])
weather_on_arrival = weather.future_weather(trip.time)
RoadTripSerializer.new(trip, weather_on_arrival).serialize_json
ErrorSerializer.new(ErrorMessage.new("Must Provide Location", 404))
end
end

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions spec/requests/api/v1/road_trip_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,25 @@

expect(response).to be_successful
end

it 'requires user to provide a location', :vcr do
user1 = User.create!(email: '[email protected]', password: 'password', password_confirmation: 'password', api_key: SecureRandom.hex)
road_trip_body = {
origin: "New York,NY",
destination: "",
api_key: user1.api_key
}
post '/api/v1/road_trip', params: road_trip_body

json_response = JSON.parse(response.body, symbolize_names: true)
expect(json_response).to eq(
{
"error": {
"message": "Must Provide Location",
"status": 404
}
}
)
end
end
end

0 comments on commit 5e4f940

Please sign in to comment.