Skip to content

Commit

Permalink
Fix test and return format
Browse files Browse the repository at this point in the history
  • Loading branch information
renatolond committed Nov 5, 2024
1 parent fed9787 commit d9e2393
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/objects/nominatim_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ def search(query:, limit: 10, language: "en")
query_params = params.map { |k, v| "#{k}=#{v}" }.join("&")
Sync do
response = client.get("/search?#{query_params}", headers: base_headers)
JSON.parse(response.read)
# TODO: (renatolond, 2024-11-05) I'm not too sure of the result format, but it will do for now
JSON.parse(response.read, symbolize_names: true)
.map do |loc|
loc.slice(:lat, :lon, :display_name)
end
ensure
response&.close
end
Expand Down
4 changes: 3 additions & 1 deletion test/app/objects/nominatim_client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

describe NominatimClient do
it "calls nominatim and gets a response" do
expected_response = []
expected_response = [
{ lat: "-22.90173", lon: "-43.2797093", display_name: "Méier, Rio de Janeiro, Região Geográfica Imediata do Rio de Janeiro, Região Metropolitana do Rio de Janeiro, Região Geográfica Intermediária do Rio de Janeiro, Rio de Janeiro, Região Sudeste, Brasil" }
]
stub_request(:get, "https://nominatim.openstreetmap.org/search?featureType=settlement&format=jsonv2&language=en&layer=address&limit=10&q=M%C3%A9ier,%20Rio%20de%20Janeiro")
.to_return(webfixture_json_file("nominatim.meier"))

Expand Down

0 comments on commit d9e2393

Please sign in to comment.