# frozen_string_literal: true

require "test_helper"
require "geo_code"

class GeoCodeTest < Minitest::Test
	def test_city_from_top_level
		geo = GeoCode.for(
			"city" => "Toronto", "prov" => "ON", "latt" => "43.7", "longt" => "-79.4"
		)
		assert_equal "Toronto", geo.locality
	end

	def test_state_from_top_level
		geo = GeoCode.for(
			"city" => "Toronto", "prov" => "ON", "latt" => "43.7", "longt" => "-79.4"
		)
		assert_equal "ON", geo.region
	end

	def test_city_prefers_usa_object
		geo = GeoCode.for(
			"city" => "New York",
			"prov" => "NY",
			"latt" => "40.7",
			"longt" => "-74.0",
			"usa" => { "uscity" => "Manhattan", "state" => "NY" }
		)
		assert_equal "Manhattan", geo.locality
	end

	def test_state_prefers_usa_object
		geo = GeoCode.for(
			"city" => "New York",
			"prov" => "NY",
			"latt" => "40.7",
			"longt" => "-74.0",
			"usa" => { "uscity" => "Manhattan", "state" => "NY" }
		)
		assert_equal "NY", geo.region
	end
end
