active_shipping 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/CHANGELOG +23 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +173 -0
- data/Rakefile +55 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/lib/active_shipping.rb +50 -0
- data/lib/active_shipping/lib/connection.rb +170 -0
- data/lib/active_shipping/lib/country.rb +319 -0
- data/lib/active_shipping/lib/error.rb +4 -0
- data/lib/active_shipping/lib/post_data.rb +22 -0
- data/lib/active_shipping/lib/posts_data.rb +47 -0
- data/lib/active_shipping/lib/requires_parameters.rb +16 -0
- data/lib/active_shipping/lib/utils.rb +18 -0
- data/lib/active_shipping/lib/validateable.rb +76 -0
- data/lib/active_shipping/shipping/base.rb +15 -0
- data/lib/active_shipping/shipping/carrier.rb +75 -0
- data/lib/active_shipping/shipping/carriers.rb +17 -0
- data/lib/active_shipping/shipping/carriers/bogus_carrier.rb +16 -0
- data/lib/active_shipping/shipping/carriers/fedex.rb +315 -0
- data/lib/active_shipping/shipping/carriers/shipwire.rb +167 -0
- data/lib/active_shipping/shipping/carriers/ups.rb +368 -0
- data/lib/active_shipping/shipping/carriers/usps.rb +496 -0
- data/lib/active_shipping/shipping/location.rb +100 -0
- data/lib/active_shipping/shipping/package.rb +144 -0
- data/lib/active_shipping/shipping/rate_estimate.rb +54 -0
- data/lib/active_shipping/shipping/rate_response.rb +19 -0
- data/lib/active_shipping/shipping/response.rb +49 -0
- data/lib/active_shipping/shipping/shipment_event.rb +14 -0
- data/lib/active_shipping/shipping/tracking_response.rb +22 -0
- data/lib/certs/cacert.pem +7815 -0
- data/lib/vendor/quantified/MIT-LICENSE +22 -0
- data/lib/vendor/quantified/README.markdown +49 -0
- data/lib/vendor/quantified/Rakefile +21 -0
- data/lib/vendor/quantified/init.rb +0 -0
- data/lib/vendor/quantified/lib/quantified.rb +6 -0
- data/lib/vendor/quantified/lib/quantified/attribute.rb +208 -0
- data/lib/vendor/quantified/lib/quantified/length.rb +20 -0
- data/lib/vendor/quantified/lib/quantified/mass.rb +19 -0
- data/lib/vendor/quantified/test/length_test.rb +92 -0
- data/lib/vendor/quantified/test/mass_test.rb +88 -0
- data/lib/vendor/quantified/test/test_helper.rb +2 -0
- data/lib/vendor/test_helper.rb +13 -0
- data/lib/vendor/xml_node/README +36 -0
- data/lib/vendor/xml_node/Rakefile +21 -0
- data/lib/vendor/xml_node/benchmark/bench_generation.rb +32 -0
- data/lib/vendor/xml_node/init.rb +1 -0
- data/lib/vendor/xml_node/lib/xml_node.rb +222 -0
- data/lib/vendor/xml_node/test/test_generating.rb +94 -0
- data/lib/vendor/xml_node/test/test_parsing.rb +43 -0
- data/test/fixtures.yml +13 -0
- data/test/fixtures/xml/fedex/ottawa_to_beverly_hills_rate_request.xml +67 -0
- data/test/fixtures/xml/fedex/ottawa_to_beverly_hills_rate_response.xml +213 -0
- data/test/fixtures/xml/fedex/tracking_request.xml +27 -0
- data/test/fixtures/xml/fedex/tracking_response.xml +153 -0
- data/test/fixtures/xml/shipwire/international_rates_response.xml +17 -0
- data/test/fixtures/xml/shipwire/invalid_credentials_response.xml +4 -0
- data/test/fixtures/xml/shipwire/new_carrier_rate_response.xml +18 -0
- data/test/fixtures/xml/shipwire/no_rates_response.xml +7 -0
- data/test/fixtures/xml/shipwire/rates_response.xml +36 -0
- data/test/fixtures/xml/ups/example_tracking_response.xml +53 -0
- data/test/fixtures/xml/ups/shipment_from_tiger_direct.xml +222 -0
- data/test/fixtures/xml/ups/test_real_home_as_residential_destination_response.xml +1 -0
- data/test/fixtures/xml/usps/beverly_hills_to_ottawa_book_rate_response.xml +85 -0
- data/test/fixtures/xml/usps/beverly_hills_to_ottawa_book_wii_rate_response.xml +168 -0
- data/test/fixtures/xml/usps/beverly_hills_to_ottawa_wii_rate_response.xml +85 -0
- data/test/remote/fedex_test.rb +140 -0
- data/test/remote/shipwire_test.rb +88 -0
- data/test/remote/ups_test.rb +187 -0
- data/test/remote/usps_test.rb +184 -0
- data/test/test_helper.rb +167 -0
- data/test/unit/base_test.rb +18 -0
- data/test/unit/carriers/fedex_test.rb +78 -0
- data/test/unit/carriers/shipwire_test.rb +130 -0
- data/test/unit/carriers/ups_test.rb +81 -0
- data/test/unit/carriers/usps_test.rb +206 -0
- data/test/unit/location_test.rb +46 -0
- data/test/unit/package_test.rb +65 -0
- data/test/unit/response_test.rb +10 -0
- metadata +158 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class BaseTest < Test::Unit::TestCase
|
4
|
+
include ActiveMerchant::Shipping
|
5
|
+
|
6
|
+
def test_get_usps_by_string
|
7
|
+
assert_equal USPS, Base.carrier('usps')
|
8
|
+
assert_equal USPS, Base.carrier('USPS')
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_get_usps_by_name
|
12
|
+
assert_equal USPS, Base.carrier(:usps)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_get_unknown_carrier
|
16
|
+
assert_raise(NameError){ Base.carrier(:polar_north) }
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
|
3
|
+
class FedExTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@packages = TestFixtures.packages
|
6
|
+
@locations = TestFixtures.locations
|
7
|
+
@carrier = FedEx.new(:key => '1111', :password => '2222', :account => '3333', :login => '4444')
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_initialize_options_requirements
|
11
|
+
assert_raises ArgumentError do FedEx.new end
|
12
|
+
assert_raises ArgumentError do FedEx.new(:login => '999999999') end
|
13
|
+
assert_raises ArgumentError do FedEx.new(:password => '7777777') end
|
14
|
+
assert_nothing_raised { FedEx.new(:key => '999999999', :password => '7777777', :account => '123', :login => '123')}
|
15
|
+
end
|
16
|
+
|
17
|
+
# def test_no_rates_response
|
18
|
+
# @carrier.expects(:commit).returns(xml_fixture('fedex/empty_response'))
|
19
|
+
#
|
20
|
+
# response = @carrier.find_rates(
|
21
|
+
# @locations[:ottawa],
|
22
|
+
# @locations[:beverly_hills],
|
23
|
+
# @packages.values_at(:book, :wii)
|
24
|
+
# )
|
25
|
+
# assert_equal "WARNING - 556: There are no valid services available. ", response.message
|
26
|
+
# end
|
27
|
+
|
28
|
+
def test_find_tracking_info_should_return_a_tracking_response
|
29
|
+
@carrier.expects(:commit).returns(xml_fixture('fedex/tracking_response'))
|
30
|
+
assert_instance_of ActiveMerchant::Shipping::TrackingResponse, @carrier.find_tracking_info('077973360403984', :test => true)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_find_tracking_info_should_parse_response_into_correct_number_of_shipment_events
|
34
|
+
@carrier.expects(:commit).returns(xml_fixture('fedex/tracking_response'))
|
35
|
+
response = @carrier.find_tracking_info('077973360403984', :test => true)
|
36
|
+
assert_equal 7, response.shipment_events.size
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_find_tracking_info_should_return_shipment_events_in_ascending_chronological_order
|
40
|
+
@carrier.expects(:commit).returns(xml_fixture('fedex/tracking_response'))
|
41
|
+
response = @carrier.find_tracking_info('077973360403984', :test => true)
|
42
|
+
assert_equal response.shipment_events.map(&:time).sort, response.shipment_events.map(&:time)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_building_request_and_parsing_response
|
46
|
+
expected_request = xml_fixture('fedex/ottawa_to_beverly_hills_rate_request')
|
47
|
+
mock_response = xml_fixture('fedex/ottawa_to_beverly_hills_rate_response')
|
48
|
+
Time.any_instance.expects(:to_xml_value).returns("2009-07-20T12:01:55-04:00")
|
49
|
+
|
50
|
+
@carrier.expects(:commit).with {|request, test_mode| Hash.from_xml(request) == Hash.from_xml(expected_request) && test_mode}.returns(mock_response)
|
51
|
+
response = @carrier.find_rates( @locations[:ottawa],
|
52
|
+
@locations[:beverly_hills],
|
53
|
+
@packages.values_at(:book, :wii), :test => true)
|
54
|
+
assert_equal ["FedEx Ground"], response.rates.map(&:service_name)
|
55
|
+
assert_equal [3836], response.rates.map(&:price)
|
56
|
+
|
57
|
+
assert response.success?, response.message
|
58
|
+
assert_instance_of Hash, response.params
|
59
|
+
assert_instance_of String, response.xml
|
60
|
+
assert_instance_of Array, response.rates
|
61
|
+
assert_not_equal [], response.rates
|
62
|
+
|
63
|
+
rate = response.rates.first
|
64
|
+
assert_equal 'FedEx', rate.carrier
|
65
|
+
assert_equal 'CAD', rate.currency
|
66
|
+
assert_instance_of Fixnum, rate.total_price
|
67
|
+
assert_instance_of Fixnum, rate.price
|
68
|
+
assert_instance_of String, rate.service_name
|
69
|
+
assert_instance_of String, rate.service_code
|
70
|
+
assert_instance_of Array, rate.package_rates
|
71
|
+
assert_equal @packages.values_at(:book, :wii), rate.packages
|
72
|
+
|
73
|
+
package_rate = rate.package_rates.first
|
74
|
+
assert_instance_of Hash, package_rate
|
75
|
+
assert_instance_of Package, package_rate[:package]
|
76
|
+
assert_nil package_rate[:rate]
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
|
3
|
+
class ShipwireTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@packages = TestFixtures.packages
|
7
|
+
@locations = TestFixtures.locations
|
8
|
+
@carrier = Shipwire.new(:login => 'l', :password => 'p')
|
9
|
+
@items = [ { :sku => 'AF0001', :quantity => 1 }, { :sku => 'AF0002', :quantity => 2 } ]
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_invalid_credentials
|
13
|
+
@carrier.expects(:ssl_post).returns(xml_fixture('shipwire/invalid_credentials_response'))
|
14
|
+
|
15
|
+
begin
|
16
|
+
@carrier.find_rates(
|
17
|
+
@locations[:ottawa],
|
18
|
+
@locations[:beverly_hills],
|
19
|
+
@packages.values_at(:book, :wii),
|
20
|
+
:order_id => '#1000',
|
21
|
+
:items => @items
|
22
|
+
)
|
23
|
+
rescue ResponseError => e
|
24
|
+
assert_equal "Could not verify e-mail/password combination", e.message
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_response_with_no_rates_is_unsuccessful
|
29
|
+
@carrier.expects(:ssl_post).returns(xml_fixture('shipwire/no_rates_response'))
|
30
|
+
|
31
|
+
assert_raises(ResponseError) do
|
32
|
+
response = @carrier.find_rates(
|
33
|
+
@locations[:ottawa],
|
34
|
+
@locations[:beverly_hills],
|
35
|
+
@packages.values_at(:book, :wii),
|
36
|
+
:order_id => '#1000',
|
37
|
+
:items => @items
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_successfully_get_international_rates
|
43
|
+
@carrier.expects(:ssl_post).returns(xml_fixture('shipwire/international_rates_response'))
|
44
|
+
|
45
|
+
response = @carrier.find_rates(
|
46
|
+
@locations[:ottawa],
|
47
|
+
@locations[:london],
|
48
|
+
@packages.values_at(:book, :wii),
|
49
|
+
:order_id => '#1000',
|
50
|
+
:items => @items
|
51
|
+
)
|
52
|
+
|
53
|
+
assert response.success?
|
54
|
+
|
55
|
+
assert_equal 1, response.rates.size
|
56
|
+
|
57
|
+
assert international = response.rates.first
|
58
|
+
assert_equal "INTL", international.service_code
|
59
|
+
assert_equal "UPS", international.carrier
|
60
|
+
assert_equal "UPS Standard", international.service_name
|
61
|
+
assert_equal 2806, international.total_price
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_successfully_get_domestic_rates
|
65
|
+
@carrier.expects(:ssl_post).returns(xml_fixture('shipwire/rates_response'))
|
66
|
+
|
67
|
+
response = @carrier.find_rates(
|
68
|
+
@locations[:ottawa],
|
69
|
+
@locations[:beverly_hills],
|
70
|
+
@packages.values_at(:book, :wii),
|
71
|
+
:order_id => '#1000',
|
72
|
+
:items => @items
|
73
|
+
)
|
74
|
+
|
75
|
+
assert response.success?
|
76
|
+
|
77
|
+
assert_equal 3, response.rates.size
|
78
|
+
|
79
|
+
assert ground = response.rates.find{|r| r.service_code == "GD" }
|
80
|
+
assert_equal "UPS", ground.carrier
|
81
|
+
assert_equal "UPS Ground", ground.service_name
|
82
|
+
assert_equal 773, ground.total_price
|
83
|
+
|
84
|
+
assert two_day = response.rates.find{|r| r.service_code == "2D" }
|
85
|
+
assert_equal "UPS", two_day.carrier
|
86
|
+
assert_equal "UPS Second Day Air", two_day.service_name
|
87
|
+
assert_equal 1364, two_day.total_price
|
88
|
+
|
89
|
+
assert one_day = response.rates.find{|r| r.service_code == "1D" }
|
90
|
+
assert_equal "USPS", one_day.carrier
|
91
|
+
assert_equal "USPS Express Mail", one_day.service_name
|
92
|
+
assert_equal 2525, one_day.total_price
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_gracefully_handle_new_carrier
|
96
|
+
@carrier.expects(:ssl_post).returns(xml_fixture('shipwire/new_carrier_rate_response'))
|
97
|
+
|
98
|
+
response = @carrier.find_rates(
|
99
|
+
@locations[:ottawa],
|
100
|
+
@locations[:beverly_hills],
|
101
|
+
@packages.values_at(:book, :wii),
|
102
|
+
:order_id => '#1000',
|
103
|
+
:items => @items
|
104
|
+
)
|
105
|
+
assert response.success?
|
106
|
+
assert_equal 1, response.rates.size
|
107
|
+
assert ground = response.rates.first
|
108
|
+
assert_equal "FESCO", ground.carrier
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_find_rates_requires_items_option
|
112
|
+
assert_raises(ArgumentError) do
|
113
|
+
@carrier.find_rates(
|
114
|
+
@locations[:ottawa],
|
115
|
+
@locations[:beverly_hills],
|
116
|
+
@packages.values_at(:book, :wii)
|
117
|
+
)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_validate_credentials_with_valid_credentials
|
122
|
+
@carrier.expects(:ssl_post).returns(xml_fixture('shipwire/no_rates_response'))
|
123
|
+
assert @carrier.valid_credentials?
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_validate_credentials_with_invalid_credentials
|
127
|
+
@carrier.expects(:ssl_post).returns(xml_fixture('shipwire/invalid_credentials_response'))
|
128
|
+
assert !@carrier.valid_credentials?
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
|
3
|
+
class UPSTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@packages = TestFixtures.packages
|
7
|
+
@locations = TestFixtures.locations
|
8
|
+
@carrier = UPS.new(
|
9
|
+
:key => 'key',
|
10
|
+
:login => 'login',
|
11
|
+
:password => 'password'
|
12
|
+
)
|
13
|
+
@tracking_response = xml_fixture('ups/shipment_from_tiger_direct')
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_initialize_options_requirements
|
17
|
+
assert_raises(ArgumentError) { UPS.new }
|
18
|
+
assert_raises(ArgumentError) { UPS.new(:login => 'blah', :password => 'bloo') }
|
19
|
+
assert_raises(ArgumentError) { UPS.new(:login => 'blah', :key => 'kee') }
|
20
|
+
assert_raises(ArgumentError) { UPS.new(:password => 'bloo', :key => 'kee') }
|
21
|
+
assert_nothing_raised { UPS.new(:login => 'blah', :password => 'bloo', :key => 'kee') }
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_find_tracking_info_should_return_a_tracking_response
|
25
|
+
@carrier.expects(:commit).returns(@tracking_response)
|
26
|
+
assert_equal 'ActiveMerchant::Shipping::TrackingResponse', @carrier.find_tracking_info('1Z5FX0076803466397').class.name
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_find_tracking_info_should_parse_response_into_correct_number_of_shipment_events
|
30
|
+
@carrier.expects(:commit).returns(@tracking_response)
|
31
|
+
response = @carrier.find_tracking_info('1Z5FX0076803466397')
|
32
|
+
assert_equal 8, response.shipment_events.size
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_find_tracking_info_should_return_shipment_events_in_ascending_chronological_order
|
36
|
+
@carrier.expects(:commit).returns(@tracking_response)
|
37
|
+
response = @carrier.find_tracking_info('1Z5FX0076803466397')
|
38
|
+
assert_equal response.shipment_events.map(&:time).sort, response.shipment_events.map(&:time)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_find_tracking_info_should_have_correct_names_for_shipment_events
|
42
|
+
@carrier.expects(:commit).returns(@tracking_response)
|
43
|
+
response = @carrier.find_tracking_info('1Z5FX0076803466397')
|
44
|
+
assert_equal [ "BILLING INFORMATION RECEIVED",
|
45
|
+
"IMPORT SCAN",
|
46
|
+
"LOCATION SCAN",
|
47
|
+
"LOCATION SCAN",
|
48
|
+
"DEPARTURE SCAN",
|
49
|
+
"ARRIVAL SCAN",
|
50
|
+
"OUT FOR DELIVERY",
|
51
|
+
"DELIVERED" ], response.shipment_events.map(&:name)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_add_origin_and_destination_data_to_shipment_events_where_appropriate
|
55
|
+
@carrier.expects(:commit).returns(@tracking_response)
|
56
|
+
response = @carrier.find_tracking_info('1Z5FX0076803466397')
|
57
|
+
assert_equal '175 AMBASSADOR', response.shipment_events.first.location.address1
|
58
|
+
assert_equal 'K1N5X8', response.shipment_events.last.location.postal_code
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_response_parsing
|
62
|
+
mock_response = xml_fixture('ups/test_real_home_as_residential_destination_response')
|
63
|
+
@carrier.expects(:commit).returns(mock_response)
|
64
|
+
response = @carrier.find_rates( @locations[:beverly_hills],
|
65
|
+
@locations[:real_home_as_residential],
|
66
|
+
@packages.values_at(:chocolate_stuff))
|
67
|
+
assert_equal [ "UPS Ground",
|
68
|
+
"UPS Three-Day Select",
|
69
|
+
"UPS Second Day Air",
|
70
|
+
"UPS Next Day Air Saver",
|
71
|
+
"UPS Next Day Air Early A.M.",
|
72
|
+
"UPS Next Day Air"], response.rates.map(&:service_name)
|
73
|
+
assert_equal [992, 2191, 3007, 5509, 9401, 6124], response.rates.map(&:price)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_maximum_weight
|
77
|
+
assert Package.new(150 * 16, [5,5,5], :units => :imperial).mass == @carrier.maximum_weight
|
78
|
+
assert Package.new((150 * 16) + 0.01, [5,5,5], :units => :imperial).mass > @carrier.maximum_weight
|
79
|
+
assert Package.new((150 * 16) - 0.01, [5,5,5], :units => :imperial).mass < @carrier.maximum_weight
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,206 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
|
3
|
+
class USPSTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@packages = TestFixtures.packages
|
7
|
+
@locations = TestFixtures.locations
|
8
|
+
@carrier = USPS.new(:login => 'login')
|
9
|
+
@international_rate_responses = {
|
10
|
+
:vanilla => xml_fixture('usps/beverly_hills_to_ottawa_book_rate_response')
|
11
|
+
}
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
# TODO: test_parse_domestic_rate_response
|
16
|
+
# TODO: test_build_us_rate_request
|
17
|
+
# TODO: test_build_world_rate_request
|
18
|
+
|
19
|
+
def test_initialize_options_requirements
|
20
|
+
assert_raises ArgumentError do USPS.new end
|
21
|
+
assert_nothing_raised { USPS.new(:login => 'blah')}
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_find_tracking_info_should_return_a_tracking_response
|
25
|
+
@carrier.expects(:commit).returns(xml_fixture('usps/example_tracking_response'))
|
26
|
+
assert_instance_of ActiveMerchant::Shipping::TrackingResponse,
|
27
|
+
@carrier.find_tracking_info(['EJ958083578US'], :test => true)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_find_tracking_info_should_return_a_tracking_number
|
31
|
+
@carrier.expects(:commit).returns(xml_fixture('usps/example_tracking_response'))
|
32
|
+
info = @carrier.find_tracking_info(['EJ958083578US'], :test => true)
|
33
|
+
|
34
|
+
assert_equal 'EJ958083578US', info.tracking_number
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_find_tracking_info_should_return_correct_number_of_shipment_events
|
38
|
+
@carrier.expects(:commit).returns(xml_fixture('usps/example_tracking_response'))
|
39
|
+
info = @carrier.find_tracking_info(['EJ958083578US'], :test => true)
|
40
|
+
|
41
|
+
assert_equal 3, info.shipment_events.size
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_find_tracking_info_should_return_proper_order
|
45
|
+
@carrier.expects(:commit).returns(xml_fixture('usps/example_tracking_response'))
|
46
|
+
info = @carrier.find_tracking_info(['EJ958083578US'], :test => true)
|
47
|
+
|
48
|
+
assert_equal "NOTICE LEFT", info.shipment_events.first.name
|
49
|
+
assert_equal "ACCEPTANCE", info.shipment_events.last.name
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_find_multiple_returns_two_seperate_tracking_responses
|
53
|
+
@carrier.expects(:commit).returns(xml_fixture('usps/multi_tracking_example'))
|
54
|
+
info = @carrier.find_tracking_info(['EJ958083578US', 'EJ958088694US'], :test => true)
|
55
|
+
assert_equal 2, info.size
|
56
|
+
assert_equal 'EJ958083578US', info.first.tracking_number
|
57
|
+
assert_equal 'EJ958088694US', info.last.tracking_number
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_parse_international_rate_response
|
61
|
+
fixture_xml = @international_rate_responses[:vanilla]
|
62
|
+
@carrier.expects(:commit).returns(fixture_xml)
|
63
|
+
|
64
|
+
response = begin
|
65
|
+
@carrier.find_rates(
|
66
|
+
@locations[:beverly_hills], # imperial (U.S. origin)
|
67
|
+
@locations[:ottawa],
|
68
|
+
@packages[:book],
|
69
|
+
:test => true
|
70
|
+
)
|
71
|
+
rescue ResponseError => e
|
72
|
+
e.response
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
expected_xml_hash = Hash.from_xml(fixture_xml)
|
77
|
+
actual_xml_hash = Hash.from_xml(response.xml)
|
78
|
+
|
79
|
+
assert_equal expected_xml_hash, actual_xml_hash
|
80
|
+
|
81
|
+
assert_not_equal [],response.rates
|
82
|
+
assert_equal response.rates.sort_by(&:price), response.rates
|
83
|
+
assert_equal ["1", "2", "3", "4", "6", "7", "9"], response.rates.map(&:service_code).sort
|
84
|
+
|
85
|
+
ordered_service_names = ["USPS Express Mail International (EMS)", "USPS First-Class Mail International", "USPS Global Express Guaranteed", "USPS Global Express Guaranteed Non-Document Non-Rectangular", "USPS Global Express Guaranteed Non-Document Rectangular", "USPS Priority Mail International", "USPS Priority Mail International Flat Rate Box"]
|
86
|
+
assert_equal ordered_service_names, response.rates.map(&:service_name).sort
|
87
|
+
|
88
|
+
|
89
|
+
assert_equal [376, 1600, 2300, 2325, 4100, 4100, 4100], response.rates.map(&:total_price)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_parse_max_dimension_sentences
|
93
|
+
limits = {
|
94
|
+
"Max. length 46\", width 35\", height 46\" and max. length plus girth 108\"" =>
|
95
|
+
[{:length => 46.0, :width => 46.0, :height => 35.0, :length_plus_girth => 108.0}],
|
96
|
+
"Max.length 42\", max. length plus girth 79\"" =>
|
97
|
+
[{:length => 42.0, :length_plus_girth => 79.0}],
|
98
|
+
"9 1/2\" X 12 1/2\"" =>
|
99
|
+
[{:length => 12.5, :width => 9.5, :height => 0.75}, "Flat Rate Envelope"],
|
100
|
+
"Maximum length and girth combined 108\"" =>
|
101
|
+
[{:length_plus_girth => 108.0}],
|
102
|
+
"USPS-supplied Priority Mail flat-rate envelope 9 1/2\" x 12 1/2.\" Maximum weight 4 pounds." =>
|
103
|
+
[{:length => 12.5, :width => 9.5, :height => 0.75}, "Flat Rate Envelope"],
|
104
|
+
"Max. length 24\", Max. length, height, depth combined 36\"" =>
|
105
|
+
[{:length => 24.0, :length_plus_width_plus_height => 36.0}]
|
106
|
+
}
|
107
|
+
p = @packages[:book]
|
108
|
+
limits.each do |sentence,hashes|
|
109
|
+
dimensions = hashes[0].update(:weight => 50.0)
|
110
|
+
service_node = build_service_node(
|
111
|
+
:name => hashes[1],
|
112
|
+
:max_weight => 50,
|
113
|
+
:max_dimensions => sentence )
|
114
|
+
@carrier.expects(:package_valid_for_max_dimensions).with(p, dimensions)
|
115
|
+
@carrier.send(:package_valid_for_service, p, service_node)
|
116
|
+
end
|
117
|
+
|
118
|
+
service_node = build_service_node(
|
119
|
+
:name => "flat-rate box",
|
120
|
+
:max_weight => 50,
|
121
|
+
:max_dimensions => "USPS-supplied Priority Mail flat-rate box. Maximum weight 20 pounds." )
|
122
|
+
|
123
|
+
# should test against either kind of flat rate box:
|
124
|
+
dimensions = [{:weight => 50.0, :length => 11.0, :width => 8.5, :height => 5.5}, # or...
|
125
|
+
{:weight => 50.0, :length => 13.625, :width => 11.875, :height => 3.375}]
|
126
|
+
@carrier.expects(:package_valid_for_max_dimensions).with(p, dimensions[0])
|
127
|
+
@carrier.expects(:package_valid_for_max_dimensions).with(p, dimensions[1])
|
128
|
+
@carrier.send(:package_valid_for_service, p, service_node)
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_package_valid_for_max_dimensions
|
133
|
+
p = Package.new(70 * 16, [10,10,10], :units => :imperial)
|
134
|
+
limits = {:weight => 70.0, :length => 10.0, :width => 10.0, :height => 10.0, :length_plus_girth => 50.0, :length_plus_width_plus_height => 30.0}
|
135
|
+
assert_equal true, @carrier.send(:package_valid_for_max_dimensions, p, limits)
|
136
|
+
|
137
|
+
limits.keys.each do |key|
|
138
|
+
dimensions = {key => (limits[key] - 1)}
|
139
|
+
assert_equal false, @carrier.send(:package_valid_for_max_dimensions, p, dimensions)
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_strip_9_digit_zip_codes
|
145
|
+
request = URI.decode(@carrier.send(:build_us_rate_request, @packages[:book], "90210-1234", "123456789"))
|
146
|
+
assert !(request =~ /\>90210-1234\</)
|
147
|
+
assert request =~ /\>90210\</
|
148
|
+
assert !(request =~ /\>123456789\</)
|
149
|
+
assert request =~ /\>12345\</
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_xml_logging_to_file
|
153
|
+
mock_response = @international_rate_responses[:vanilla]
|
154
|
+
@carrier.expects(:commit).times(2).returns(mock_response)
|
155
|
+
@carrier.find_rates(
|
156
|
+
@locations[:beverly_hills],
|
157
|
+
@locations[:ottawa],
|
158
|
+
@packages[:book],
|
159
|
+
:test => true
|
160
|
+
)
|
161
|
+
@carrier.find_rates(
|
162
|
+
@locations[:beverly_hills],
|
163
|
+
@locations[:ottawa],
|
164
|
+
@packages[:book],
|
165
|
+
:test => true
|
166
|
+
)
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_maximum_weight
|
170
|
+
assert Package.new(70 * 16, [5,5,5], :units => :imperial).mass == @carrier.maximum_weight
|
171
|
+
assert Package.new((70 * 16) + 0.01, [5,5,5], :units => :imperial).mass > @carrier.maximum_weight
|
172
|
+
assert Package.new((70 * 16) - 0.01, [5,5,5], :units => :imperial).mass < @carrier.maximum_weight
|
173
|
+
end
|
174
|
+
|
175
|
+
private
|
176
|
+
|
177
|
+
def build_service_node(options = {})
|
178
|
+
XmlNode.new('Service') do |service_node|
|
179
|
+
service_node << XmlNode.new('Pounds', options[:pounds] || "0")
|
180
|
+
service_node << XmlNode.new('SvcCommitments', options[:svc_commitments] || "Varies")
|
181
|
+
service_node << XmlNode.new('Country', options[:country] || "CANADA")
|
182
|
+
service_node << XmlNode.new('ID', options[:id] || "3")
|
183
|
+
service_node << XmlNode.new('MaxWeight', options[:max_weight] || "64")
|
184
|
+
service_node << XmlNode.new('SvcDescription', options[:name] || "First-Class Mail International")
|
185
|
+
service_node << XmlNode.new('MailType', options[:mail_type] || "Package")
|
186
|
+
service_node << XmlNode.new('Postage', options[:postage] || "3.76")
|
187
|
+
service_node << XmlNode.new('Ounces', options[:ounces] || "9")
|
188
|
+
service_node << XmlNode.new('MaxDimensions', options[:max_dimensions] ||
|
189
|
+
"Max. length 24\", Max. length, height, depth combined 36\"")
|
190
|
+
end.to_xml_element
|
191
|
+
end
|
192
|
+
|
193
|
+
def build_service_hash(options = {})
|
194
|
+
{"Pounds"=> options[:pounds] || "0", # 8
|
195
|
+
"SvcCommitments"=> options[:svc_commitments] || "Varies",
|
196
|
+
"Country"=> options[:country] || "CANADA",
|
197
|
+
"ID"=> options[:id] || "3",
|
198
|
+
"MaxWeight"=> options[:max_weight] || "64",
|
199
|
+
"SvcDescription"=> options[:name] || "First-Class Mail International",
|
200
|
+
"MailType"=> options[:mail_type] || "Package",
|
201
|
+
"Postage"=> options[:postage] || "3.76",
|
202
|
+
"Ounces"=> options[:ounces] || "9",
|
203
|
+
"MaxDimensions"=> options[:max_dimensions] ||
|
204
|
+
"Max. length 24\", Max. length, height, depth combined 36\""}
|
205
|
+
end
|
206
|
+
end
|