test/google_lookup_test.rb in timezone-0.3.11 vs test/google_lookup_test.rb in timezone-0.4.0

- old
+ new

@@ -1,15 +1,16 @@ require 'timezone/configure' require 'timezone/lookup/google' require 'minitest/autorun' +require 'timecop' require_relative 'http_test_client' class GoogleLookupTest < ::Minitest::Unit::TestCase def setup Timezone::Configure.begin do |c| c.http_client = HTTPTestClient - c.google_api_key = '123abc' + c.google_api_key = 'MTIzYWJj' end end def coordinates [-34.92771808058, 138.477041423321] @@ -21,11 +22,11 @@ def test_missing_api_key Timezone::Configure.begin{ |c| c.google_api_key = nil } assert_raises(::Timezone::Error::InvalidConfig){ lookup } ensure - Timezone::Configure.begin{ |c| c.google_api_key = '123abc' } + Timezone::Configure.begin{ |c| c.google_api_key = 'MTIzYWJj' } end def test_google_using_lat_lon_coordinates HTTPTestClient.body = File.open(mock_path + '/google_lat_lon_coords.txt').read @@ -34,9 +35,32 @@ def test_google_request_denied_read_lat_lon_coordinates HTTPTestClient.body = nil assert_raises Timezone::Error::Google, 'The provided API key is invalid.' do lookup.lookup(*coordinates) + end + end + + def test_url_non_enterprise + Timecop.freeze(Time.at(1433347661)) do + result = lookup.send(:url, '123', '123') + assert_equal "/maps/api/timezone/json?location=123%2C123&timestamp=1433347661&key=MTIzYWJj", result + end + end + + def test_url_enterprise + Timezone::Configure.begin do |c| + c.google_client_id = '123&asdf' + end + + Timecop.freeze(Time.at(1433347661)) do + result = lookup.send(:url, '123', '123') + assert_equal '/maps/api/timezone/json?location=123%2C123&timestamp=1433347661&client=123%26asdf&signature=B1TNSSvIw9Wvf_ZjjW5uRzGm4F4=', result + end + + ensure + Timezone::Configure.begin do |c| + c.google_client_id = nil end end private