require File.dirname(__FILE__) + '/../test_helper' class FedExTest < Test::Unit::TestCase def setup @packages = TestFixtures.packages @locations = TestFixtures.locations @carrier = FedEx.new(fixtures(:fedex)) FedEx.logger = Logger.new('/Users/james/.active_merchant/fedex.log') end def test_us_to_canada response = nil assert_nothing_raised do response = @carrier.find_rates( @locations[:beverly_hills], @locations[:ottawa], @packages.values_at(:wii), :test => true ) assert !response.rates.blank? response.rates.each do |rate| assert_instance_of String, rate.service_name assert_instance_of Fixnum, rate.price end end end def test_zip_to_zip_fails begin @carrier.find_rates( Location.new(:zip => 40524), Location.new(:zip => 40515), @packages[:wii], :test => true ) rescue ResponseError => e assert_match /country\s?code/i, e.message assert_match /(missing|invalid)/, e.message end end # FedEx requires a valid origin and destination postal code def test_rates_for_locations_with_only_zip_and_country response = @carrier.find_rates( @locations[:bare_beverly_hills], @locations[:bare_ottawa], @packages.values_at(:wii), :test => true ) assert response.rates.size > 0 end def test_rates_for_location_with_only_country_code begin response = @carrier.find_rates( @locations[:bare_beverly_hills], Location.new(:country => 'CA'), @packages.values_at(:wii), :test => true ) rescue ResponseError => e assert_match /postal code/i, e.message assert_match /(missing|invalid)/i, e.message end end def test_invalid_recipient_country begin response = @carrier.find_rates( @locations[:bare_beverly_hills], Location.new(:country => 'JP', :zip => '108-8361'), @packages.values_at(:wii), :test => true ) rescue ResponseError => e assert_match /postal code/i, e.message assert_match /(missing|invalid)/i, e.message end end def test_ottawa_to_beverly_hills response = nil assert_nothing_raised do response = @carrier.find_rates( @locations[:ottawa], @locations[:beverly_hills], @packages.values_at(:book, :wii), :test => true ) assert !response.rates.blank? response.rates.each do |rate| assert_instance_of String, rate.service_name assert_instance_of Fixnum, rate.price end end end def test_ottawa_to_london response = nil assert_nothing_raised do response = @carrier.find_rates( @locations[:ottawa], @locations[:london], @packages.values_at(:book, :wii), :test => true ) assert !response.rates.blank? response.rates.each do |rate| assert_instance_of String, rate.service_name assert_instance_of Fixnum, rate.price end end end def test_beverly_hills_to_london response = nil assert_nothing_raised do response = @carrier.find_rates( @locations[:beverly_hills], @locations[:london], @packages.values_at(:book, :wii), :test => true ) assert !response.rates.blank? response.rates.each do |rate| assert_instance_of String, rate.service_name assert_instance_of Fixnum, rate.price end end end def test_tracking assert_nothing_raised do @carrier.find_tracking_info('077973360403984', :test => true) end end end