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(
9 "city" => "Toronto", "prov" => "ON", "latt" => "43.7", "longt" => "-79.4"
10 )
11 assert_equal "Toronto", geo.locality
12 end
13
14 def test_state_from_top_level
15 geo = GeoCode.for(
16 "city" => "Toronto", "prov" => "ON", "latt" => "43.7", "longt" => "-79.4"
17 )
18 assert_equal "ON", geo.region
19 end
20
21 def test_city_prefers_usa_object
22 geo = GeoCode.for(
23 "city" => "New York",
24 "prov" => "NY",
25 "latt" => "40.7",
26 "longt" => "-74.0",
27 "usa" => { "uscity" => "Manhattan", "state" => "NY" }
28 )
29 assert_equal "Manhattan", geo.locality
30 end
31
32 def test_state_prefers_usa_object
33 geo = GeoCode.for(
34 "city" => "New York",
35 "prov" => "NY",
36 "latt" => "40.7",
37 "longt" => "-74.0",
38 "usa" => { "uscity" => "Manhattan", "state" => "NY" }
39 )
40 assert_equal "NY", geo.region
41 end
42end