1# frozen_string_literal: true
2
3require "test_helper"
4require "geo_code"
5
6class GeoCodeTest < Minitest::Test
7 def test_city_from_top_level
8 geo = GeoCode.for("city" => "Toronto", "prov" => "ON", "latt" => "43.7", "longt" => "-79.4")
9 assert_equal "Toronto", geo.city
10 end
11
12 def test_state_from_top_level
13 geo = GeoCode.for("city" => "Toronto", "prov" => "ON", "latt" => "43.7", "longt" => "-79.4")
14 assert_equal "ON", geo.state
15 end
16
17 def test_city_prefers_usa_object
18 geo = GeoCode.for(
19 "city" => "New York",
20 "prov" => "NY",
21 "latt" => "40.7",
22 "longt" => "-74.0",
23 "usa" => { "uscity" => "Manhattan", "state" => "NY" }
24 )
25 assert_equal "Manhattan", geo.city
26 end
27
28 def test_state_prefers_usa_object
29 geo = GeoCode.for(
30 "city" => "New York",
31 "prov" => "NY",
32 "latt" => "40.7",
33 "longt" => "-74.0",
34 "usa" => { "uscity" => "Manhattan", "state" => "NY" }
35 )
36 assert_equal "NY", geo.state
37 end
38end