reactive_shipping 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.travis.yml +33 -0
- data/.yardopts +13 -0
- data/CHANGELOG.md +225 -0
- data/CONTRIBUTING.md +23 -0
- data/Gemfile +3 -0
- data/MIT-LICENSE +21 -0
- data/README.md +158 -0
- data/Rakefile +35 -0
- data/dev.yml +17 -0
- data/gemfiles/activesupport42.gemfile +5 -0
- data/gemfiles/activesupport50.gemfile +6 -0
- data/gemfiles/activesupport51.gemfile +5 -0
- data/gemfiles/activesupport52.gemfile +5 -0
- data/gemfiles/activesupport_master.gemfile +5 -0
- data/lib/certs/eParcel.dtd +111 -0
- data/lib/reactive_shipping.rb +26 -0
- data/lib/reactive_shipping/address_validation_response.rb +30 -0
- data/lib/reactive_shipping/carrier.rb +184 -0
- data/lib/reactive_shipping/carriers.rb +35 -0
- data/lib/reactive_shipping/carriers/australia_post.rb +248 -0
- data/lib/reactive_shipping/carriers/benchmark_carrier.rb +31 -0
- data/lib/reactive_shipping/carriers/bogus_carrier.rb +12 -0
- data/lib/reactive_shipping/carriers/canada_post.rb +263 -0
- data/lib/reactive_shipping/carriers/canada_post_pws.rb +908 -0
- data/lib/reactive_shipping/carriers/fedex.rb +797 -0
- data/lib/reactive_shipping/carriers/kunaki.rb +155 -0
- data/lib/reactive_shipping/carriers/new_zealand_post.rb +260 -0
- data/lib/reactive_shipping/carriers/shipwire.rb +178 -0
- data/lib/reactive_shipping/carriers/stamps.rb +860 -0
- data/lib/reactive_shipping/carriers/ups.rb +1060 -0
- data/lib/reactive_shipping/carriers/usps.rb +708 -0
- data/lib/reactive_shipping/carriers/usps_returns.rb +86 -0
- data/lib/reactive_shipping/delivery_date_estimate.rb +20 -0
- data/lib/reactive_shipping/delivery_date_estimates_response.rb +11 -0
- data/lib/reactive_shipping/errors.rb +35 -0
- data/lib/reactive_shipping/external_return_label_request.rb +417 -0
- data/lib/reactive_shipping/external_return_label_response.rb +26 -0
- data/lib/reactive_shipping/label.rb +10 -0
- data/lib/reactive_shipping/label_response.rb +10 -0
- data/lib/reactive_shipping/location.rb +166 -0
- data/lib/reactive_shipping/package.rb +165 -0
- data/lib/reactive_shipping/package_item.rb +60 -0
- data/lib/reactive_shipping/rate_estimate.rb +197 -0
- data/lib/reactive_shipping/rate_response.rb +33 -0
- data/lib/reactive_shipping/response.rb +44 -0
- data/lib/reactive_shipping/shipment_event.rb +22 -0
- data/lib/reactive_shipping/shipment_packer.rb +108 -0
- data/lib/reactive_shipping/shipping_response.rb +34 -0
- data/lib/reactive_shipping/tracking_response.rb +120 -0
- data/lib/reactive_shipping/version.rb +3 -0
- data/reactive_shipping.gemspec +38 -0
- data/shipit.rubygems.yml +1 -0
- data/test/console.rb +39 -0
- data/test/credentials.yml +76 -0
- data/test/fixtures/files/label1.pdf +0 -0
- data/test/fixtures/files/ups-shipping-label.gif +0 -0
- data/test/fixtures/json/australia_post/calculate_domestic.json +13 -0
- data/test/fixtures/json/australia_post/calculate_domestic_2.json +19 -0
- data/test/fixtures/json/australia_post/calculate_international.json +12 -0
- data/test/fixtures/json/australia_post/calculate_international_2.json +15 -0
- data/test/fixtures/json/australia_post/error_message.json +5 -0
- data/test/fixtures/json/australia_post/service_domestic.json +117 -0
- data/test/fixtures/json/australia_post/service_domestic_2.json +117 -0
- data/test/fixtures/json/australia_post/service_international.json +76 -0
- data/test/fixtures/json/australia_post/service_international_2.json +59 -0
- data/test/fixtures/json/newzealandpost/domestic_book.json +1 -0
- data/test/fixtures/json/newzealandpost/domestic_default.json +1 -0
- data/test/fixtures/json/newzealandpost/domestic_error.json +1 -0
- data/test/fixtures/json/newzealandpost/domestic_poster.json +1 -0
- data/test/fixtures/json/newzealandpost/domestic_small_half_pound.json +1 -0
- data/test/fixtures/json/newzealandpost/international_book.json +1 -0
- data/test/fixtures/json/newzealandpost/international_new_zealand_wii.json +1 -0
- data/test/fixtures/json/newzealandpost/international_small_half_pound.json +1 -0
- data/test/fixtures/json/newzealandpost/international_wii.json +1 -0
- data/test/fixtures/xml/canadapost/example_request.xml +25 -0
- data/test/fixtures/xml/canadapost/example_response.xml +130 -0
- data/test/fixtures/xml/canadapost/example_response_error.xml +16 -0
- data/test/fixtures/xml/canadapost/example_response_french.xml +122 -0
- data/test/fixtures/xml/canadapost/example_response_with_nil_value.xml +164 -0
- data/test/fixtures/xml/canadapost/example_response_with_postal_outlet.xml +155 -0
- data/test/fixtures/xml/canadapost/example_response_with_postal_outlet_french.xml +274 -0
- data/test/fixtures/xml/canadapost/example_response_with_strange_delivery_date.xml +130 -0
- data/test/fixtures/xml/canadapost_pws/dnc_tracking_details_en.xml +112 -0
- data/test/fixtures/xml/canadapost_pws/merchant_details_error.xml +7 -0
- data/test/fixtures/xml/canadapost_pws/merchant_details_response.xml +7 -0
- data/test/fixtures/xml/canadapost_pws/option_response.xml +13 -0
- data/test/fixtures/xml/canadapost_pws/option_response_no_conflicts.xml +7 -0
- data/test/fixtures/xml/canadapost_pws/rates_info.xml +190 -0
- data/test/fixtures/xml/canadapost_pws/rates_info_error.xml +7 -0
- data/test/fixtures/xml/canadapost_pws/receipt_response.xml +42 -0
- data/test/fixtures/xml/canadapost_pws/receipt_response_no_priced_options.xml +36 -0
- data/test/fixtures/xml/canadapost_pws/register_token_error.xml +7 -0
- data/test/fixtures/xml/canadapost_pws/register_token_response.xml +3 -0
- data/test/fixtures/xml/canadapost_pws/service_options_response.xml +42 -0
- data/test/fixtures/xml/canadapost_pws/services_error.xml +6 -0
- data/test/fixtures/xml/canadapost_pws/services_response.xml +32 -0
- data/test/fixtures/xml/canadapost_pws/shipment_domestic.xml +69 -0
- data/test/fixtures/xml/canadapost_pws/shipment_response.xml +20 -0
- data/test/fixtures/xml/canadapost_pws/shipment_us.xml +69 -0
- data/test/fixtures/xml/canadapost_pws/tracking_details_en.xml +152 -0
- data/test/fixtures/xml/canadapost_pws/tracking_details_en_error.xml +7 -0
- data/test/fixtures/xml/canadapost_pws/tracking_details_en_undelivered.xml +116 -0
- data/test/fixtures/xml/canadapost_pws/tracking_details_fr.xml +156 -0
- data/test/fixtures/xml/canadapost_pws/tracking_details_no_expected_delivery_date.xml +40 -0
- data/test/fixtures/xml/fedex/create_shipment_response.xml +2 -0
- data/test/fixtures/xml/fedex/freight_rate_request.xml +82 -0
- data/test/fixtures/xml/fedex/freight_rate_response.xml +506 -0
- data/test/fixtures/xml/fedex/invalid_fedex_reply.xml +27 -0
- data/test/fixtures/xml/fedex/ottawa_to_beverly_hills_commercial_rate_request.xml +79 -0
- data/test/fixtures/xml/fedex/ottawa_to_beverly_hills_no_saturday_rate_request.xml +79 -0
- data/test/fixtures/xml/fedex/ottawa_to_beverly_hills_rate_request.xml +80 -0
- data/test/fixtures/xml/fedex/ottawa_to_beverly_hills_rate_response.xml +214 -0
- data/test/fixtures/xml/fedex/raterequest_reply.xml +213 -0
- data/test/fixtures/xml/fedex/raterequest_response_with_ground_home_delivery.xml +206 -0
- data/test/fixtures/xml/fedex/reply_without_notifications.xml +185 -0
- data/test/fixtures/xml/fedex/tracking_request.xml +29 -0
- data/test/fixtures/xml/fedex/tracking_response_bad_tracking_number.xml +20 -0
- data/test/fixtures/xml/fedex/tracking_response_delivered_at_door.xml +254 -0
- data/test/fixtures/xml/fedex/tracking_response_delivered_at_facility.xml +403 -0
- data/test/fixtures/xml/fedex/tracking_response_delivered_with_signature.xml +269 -0
- data/test/fixtures/xml/fedex/tracking_response_empty_status_detail.xml +84 -0
- data/test/fixtures/xml/fedex/tracking_response_failure_code_9045.xml +52 -0
- data/test/fixtures/xml/fedex/tracking_response_failure_code_9080.xml +51 -0
- data/test/fixtures/xml/fedex/tracking_response_in_transit.xml +127 -0
- data/test/fixtures/xml/fedex/tracking_response_invalid_tracking_number.xml +52 -0
- data/test/fixtures/xml/fedex/tracking_response_missing_status_code.xml +89 -0
- data/test/fixtures/xml/fedex/tracking_response_multiple_results.xml +100 -0
- data/test/fixtures/xml/fedex/tracking_response_not_found.xml +52 -0
- data/test/fixtures/xml/fedex/tracking_response_shipment_exception.xml +209 -0
- data/test/fixtures/xml/fedex/tracking_response_unable_to_process.xml +32 -0
- data/test/fixtures/xml/fedex/tracking_response_with_blank_state.xml +107 -0
- data/test/fixtures/xml/fedex/unknown_fedex_document_reply.xml +3 -0
- data/test/fixtures/xml/kunaki/invalid_state_response.xml +3 -0
- data/test/fixtures/xml/kunaki/no_valid_items_response.xml +3 -0
- data/test/fixtures/xml/kunaki/successful_rates_response.xml +3 -0
- data/test/fixtures/xml/kunaki/unsuccessful_rates_response.xml +9 -0
- data/test/fixtures/xml/shipwire/international_rates_response.xml +17 -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/shipwire/rates_response_no_estimate.xml +14 -0
- data/test/fixtures/xml/stamps/authenticate_user_request.xml +15 -0
- data/test/fixtures/xml/stamps/authenticate_user_response.xml +10 -0
- data/test/fixtures/xml/stamps/cleanse_address_request.xml +19 -0
- data/test/fixtures/xml/stamps/cleanse_address_response.xml +27 -0
- data/test/fixtures/xml/stamps/create_indicium_request.xml +69 -0
- data/test/fixtures/xml/stamps/create_indicium_response.xml +40 -0
- data/test/fixtures/xml/stamps/expired_authenticator_response.xml +15 -0
- data/test/fixtures/xml/stamps/get_account_info_request.xml +11 -0
- data/test/fixtures/xml/stamps/get_account_info_response.xml +36 -0
- data/test/fixtures/xml/stamps/get_purchase_status_request.xml +12 -0
- data/test/fixtures/xml/stamps/get_purchase_status_response.xml +16 -0
- data/test/fixtures/xml/stamps/get_rates_request.xml +19 -0
- data/test/fixtures/xml/stamps/get_rates_response.xml +351 -0
- data/test/fixtures/xml/stamps/purchase_postage_request.xml +13 -0
- data/test/fixtures/xml/stamps/purchase_postage_response.xml +17 -0
- data/test/fixtures/xml/stamps/track_shipment_request.xml +12 -0
- data/test/fixtures/xml/stamps/track_shipment_response.xml +45 -0
- data/test/fixtures/xml/ups/access_request.xml +6 -0
- data/test/fixtures/xml/ups/delivered_shipment_with_refund.xml +290 -0
- data/test/fixtures/xml/ups/delivered_shipment_without_events_tracking_response.xml +62 -0
- data/test/fixtures/xml/ups/delivery_dates_response.xml +140 -0
- data/test/fixtures/xml/ups/example_tracking_response.xml +53 -0
- data/test/fixtures/xml/ups/in_transit_shipment.xml +183 -0
- data/test/fixtures/xml/ups/out_for_delivery_shipment.xml +165 -0
- data/test/fixtures/xml/ups/package_exceeds_maximum_length.xml +12 -0
- data/test/fixtures/xml/ups/rate_single_service.xml +54 -0
- data/test/fixtures/xml/ups/rescheduled_shipment.xml +204 -0
- data/test/fixtures/xml/ups/shipment_accept_response.xml +42 -0
- data/test/fixtures/xml/ups/shipment_confirm_response.xml +33 -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 +290 -0
- data/test/fixtures/xml/ups/test_real_home_as_residential_destination_response_with_insured.xml +289 -0
- data/test/fixtures/xml/ups/test_real_home_as_residential_destination_with_origin_account_response.xml +311 -0
- data/test/fixtures/xml/ups/tracking_request.xml +9 -0
- data/test/fixtures/xml/ups/triple_accept_response.xml +72 -0
- data/test/fixtures/xml/ups/triple_confirm_response.xml +32 -0
- data/test/fixtures/xml/ups/void_shipment_response.xml +11 -0
- data/test/fixtures/xml/usps/api_error_rate_response.xml +53 -0
- data/test/fixtures/xml/usps/beverly_hills_to_new_york_book_commercial_base_rate_response.xml +2 -0
- data/test/fixtures/xml/usps/beverly_hills_to_new_york_book_commercial_plus_rate_response.xml +258 -0
- data/test/fixtures/xml/usps/beverly_hills_to_new_york_book_rate_response.xml +108 -0
- data/test/fixtures/xml/usps/beverly_hills_to_ottawa_american_wii_commercial_base_rate_response.xml +84 -0
- data/test/fixtures/xml/usps/beverly_hills_to_ottawa_american_wii_commercial_plus_rate_response.xml +212 -0
- data/test/fixtures/xml/usps/beverly_hills_to_ottawa_american_wii_rate_response.xml +230 -0
- data/test/fixtures/xml/usps/first_class_packages_with_invalid_mail_type_response.xml +12 -0
- data/test/fixtures/xml/usps/first_class_packages_with_mail_type_response.xml +16 -0
- data/test/fixtures/xml/usps/first_class_packages_without_mail_type_response.xml +12 -0
- data/test/fixtures/xml/usps/invalid_xml_response.xml +10 -0
- data/test/fixtures/xml/usps/invalid_xml_tracking_response_error.xml +2 -0
- data/test/fixtures/xml/usps/tracking_request.xml +10 -0
- data/test/fixtures/xml/usps/tracking_request_batch.xml +12 -0
- data/test/fixtures/xml/usps/tracking_response.xml +162 -0
- data/test/fixtures/xml/usps/tracking_response_alt.xml +53 -0
- data/test/fixtures/xml/usps/tracking_response_batch.xml +231 -0
- data/test/fixtures/xml/usps/tracking_response_failure.xml +11 -0
- data/test/fixtures/xml/usps/tracking_response_not_available.xml +12 -0
- data/test/fixtures/xml/usps/tracking_response_test_error.xml +8 -0
- data/test/fixtures/xml/usps/us_rate_request.xml +18 -0
- data/test/fixtures/xml/usps/us_rate_request_large.xml +18 -0
- data/test/fixtures/xml/usps/world_rate_request_only_country.xml +22 -0
- data/test/fixtures/xml/usps/world_rate_request_with_value.xml +24 -0
- data/test/fixtures/xml/usps/world_rate_request_without_value.xml +24 -0
- data/test/fixtures/xml/usps_returns/external_return_label_response.xml +2 -0
- data/test/fixtures/xml/usps_returns/external_return_label_response_failure.xml +10 -0
- data/test/remote/australia_post_test.rb +140 -0
- data/test/remote/canada_post_pws_platform_test.rb +259 -0
- data/test/remote/canada_post_pws_test.rb +169 -0
- data/test/remote/canada_post_test.rb +55 -0
- data/test/remote/fedex_test.rb +400 -0
- data/test/remote/kunaki_test.rb +37 -0
- data/test/remote/new_zealand_post_test.rb +149 -0
- data/test/remote/shipwire_test.rb +84 -0
- data/test/remote/stamps_test.rb +396 -0
- data/test/remote/usps_returns_test.rb +72 -0
- data/test/remote/usps_test.rb +243 -0
- data/test/test_helper.rb +296 -0
- data/test/unit/carrier_test.rb +130 -0
- data/test/unit/carriers/australia_post_test.rb +181 -0
- data/test/unit/carriers/benchmark_test.rb +18 -0
- data/test/unit/carriers/canada_post_pws_rating_test.rb +379 -0
- data/test/unit/carriers/canada_post_pws_register_test.rb +76 -0
- data/test/unit/carriers/canada_post_pws_shipping_test.rb +258 -0
- data/test/unit/carriers/canada_post_pws_test.rb +59 -0
- data/test/unit/carriers/canada_post_pws_tracking_test.rb +154 -0
- data/test/unit/carriers/canada_post_test.rb +148 -0
- data/test/unit/carriers/fedex_test.rb +693 -0
- data/test/unit/carriers/kunaki_test.rb +56 -0
- data/test/unit/carriers/new_zealand_post_test.rb +177 -0
- data/test/unit/carriers/shipwire_test.rb +188 -0
- data/test/unit/carriers/stamps_test.rb +245 -0
- data/test/unit/carriers/ups_test.rb +580 -0
- data/test/unit/carriers/usps_returns_test.rb +45 -0
- data/test/unit/carriers/usps_test.rb +633 -0
- data/test/unit/carriers_test.rb +16 -0
- data/test/unit/external_return_label_request_test.rb +258 -0
- data/test/unit/location_test.rb +234 -0
- data/test/unit/package_item_test.rb +232 -0
- data/test/unit/package_test.rb +404 -0
- data/test/unit/rate_estimate_test.rb +93 -0
- data/test/unit/response_test.rb +38 -0
- data/test/unit/shipment_event_test.rb +20 -0
- data/test/unit/shipment_packer_test.rb +212 -0
- data/test/unit/tracking_response_test.rb +41 -0
- metadata +684 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class USPSReturnsTest < ActiveSupport::TestCase
|
4
|
+
include ReactiveShipping::Test::Fixtures
|
5
|
+
|
6
|
+
attr_reader :carrier
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@carrier = USPSReturns.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_external_return_label_response_failure_should_raise_exception
|
13
|
+
@carrier.expects(:commit).returns(xml_fixture('usps_returns/external_return_label_response_failure'))
|
14
|
+
assert_raises ResponseError do
|
15
|
+
@carrier.external_return_label_request(Nokogiri::XML({}))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_external_return_label_errors
|
20
|
+
response = Nokogiri::XML(xml_fixture('usps_returns/external_return_label_response_failure'))
|
21
|
+
errors = @carrier.send(:external_return_label_errors, response)
|
22
|
+
assert_equal errors.length > 0, true
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_parse_external_return_label_response_raises_error
|
26
|
+
response = xml_fixture('usps_returns/external_return_label_response_failure')
|
27
|
+
assert_raises ResponseError do
|
28
|
+
@carrier.send(:parse_external_return_label_response, response)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_parse_external_return_label_response_returns_object
|
33
|
+
response = xml_fixture('usps_returns/external_return_label_response')
|
34
|
+
|
35
|
+
assert_equal @carrier.send(:parse_external_return_label_response, response).is_a?(ExternalReturnLabelResponse), true
|
36
|
+
assert_equal @carrier.send(:parse_external_return_label_response, response).tracking_number, "9202090140694100000410"
|
37
|
+
assert_equal @carrier.send(:parse_external_return_label_response, response).postal_routing, "420770739921"
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_external_return_label_response_should_return_external_label_response
|
41
|
+
@carrier.expects(:commit).returns(xml_fixture('usps_returns/external_return_label_response'))
|
42
|
+
assert_equal @carrier.external_return_label_request(Nokogiri::XML({})).tracking_number, "9202090140694100000410"
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,633 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class USPSTest < ActiveSupport::TestCase
|
4
|
+
include ReactiveShipping::Test::Fixtures
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@carrier = USPS.new(:login => 'login')
|
8
|
+
@tracking_response = xml_fixture('usps/tracking_response')
|
9
|
+
@batch_tracking_response = xml_fixture('usps/tracking_response_batch')
|
10
|
+
@tracking_response_failure = xml_fixture('usps/tracking_response_failure')
|
11
|
+
@tracking_infos_array = [
|
12
|
+
{number: '9102901000462189604217', :destination_zip => '12345', :mailing_date => Date.new(2010,1,30)},
|
13
|
+
{number: '5555555555555555555555'},
|
14
|
+
{number: '9405510ee200828613653750'}
|
15
|
+
]
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_using_tls_and_not_ssl_v3
|
19
|
+
refute_equal :SSLv3, @carrier.ssl_version, 'SSLv3 is no longer supported by USPS Web Tools'
|
20
|
+
assert_equal :TLSv1_2, @carrier.ssl_version
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_tracking_request_should_create_correct_xml
|
24
|
+
@carrier.expects(:commit).with(:track, xml_fixture('usps/tracking_request'),false).returns(@tracking_response)
|
25
|
+
@carrier.find_tracking_info('9102901000462189604217', :destination_zip => '12345', :mailing_date => Date.new(2010,1,30))
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_tracking_request_should_handle_9_digit_zip
|
29
|
+
@carrier.expects(:commit).with(:track, xml_fixture('usps/tracking_request'),false).returns(@tracking_response)
|
30
|
+
@carrier.find_tracking_info('9102901000462189604217', :destination_zip => '12345-4444', :mailing_date => Date.new(2010,1,30))
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_tracking_failure_should_raise_exception
|
34
|
+
@carrier.expects(:commit).returns(@tracking_response_failure)
|
35
|
+
e = assert_raises ResponseError do
|
36
|
+
@carrier.find_tracking_info('abc123xyz', :test => true)
|
37
|
+
end
|
38
|
+
assert_equal "The Postal Service could not locate the tracking information for your request. Please verify your tracking number and try again later.", e.message
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_find_tracking_info_should_handle_not_found_error
|
42
|
+
@carrier.expects(:commit).returns(xml_fixture('usps/tracking_response_test_error'))
|
43
|
+
e = assert_raises ResponseError do
|
44
|
+
@carrier.find_tracking_info('9102901000462189604217', :test => true)
|
45
|
+
end
|
46
|
+
assert_equal "This Information has not been included in this Test Server.", e.message
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_find_tracking_info_should_handle_not_available_error
|
50
|
+
@carrier.expects(:commit).returns(xml_fixture('usps/tracking_response_not_available'))
|
51
|
+
assert_raises ResponseError do
|
52
|
+
@carrier.find_tracking_info('9574211957289221353248', :test => true)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_find_tracking_info_should_handle_invalid_xml_error
|
57
|
+
@carrier.expects(:commit).returns(xml_fixture('usps/invalid_xml_tracking_response_error'))
|
58
|
+
assert_raises ResponseError do
|
59
|
+
@carrier.find_tracking_info('9102901000462189604217,9102901000462189604214', :test => true)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_find_tracking_info_should_return_a_tracking_response
|
64
|
+
@carrier.expects(:commit).returns(@tracking_response)
|
65
|
+
assert_instance_of ReactiveShipping::TrackingResponse, @carrier.find_tracking_info('9102901000462189604217', :test => true)
|
66
|
+
@carrier.expects(:commit).returns(@tracking_response)
|
67
|
+
assert_equal 'ReactiveShipping::TrackingResponse', @carrier.find_tracking_info('EJ958083578US').class.name
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_find_tracking_info_should_have_correct_fields
|
71
|
+
@carrier.expects(:commit).returns(@tracking_response)
|
72
|
+
response = @carrier.find_tracking_info('9102901000462189604217', :test => true)
|
73
|
+
assert_equal 10, response.shipment_events.size
|
74
|
+
assert_equal Time.parse('April 28, 2015'), response.scheduled_delivery_date
|
75
|
+
assert_equal Time.parse('2015-04-28 09:01:00 UTC'), response.actual_delivery_date
|
76
|
+
assert_equal '9102901000462189604217', response.tracking_number
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_find_tracking_info_should_return_shipment_events_in_ascending_chronological_order
|
80
|
+
@carrier.expects(:commit).returns(@tracking_response)
|
81
|
+
response = @carrier.find_tracking_info('9102901000462189604217', :test => true)
|
82
|
+
assert_equal response.shipment_events.map(&:time).sort, response.shipment_events.map(&:time)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_find_tracking_info_should_have_correct_timestamps_for_shipment_events
|
86
|
+
@carrier.expects(:commit).returns(@tracking_response)
|
87
|
+
response = @carrier.find_tracking_info('9102901000462189604217', :test => true)
|
88
|
+
assert_equal [
|
89
|
+
"2015-04-23 23:36:00 UTC",
|
90
|
+
"2015-04-25 18:04:00 UTC",
|
91
|
+
"2015-04-25 19:19:00 UTC",
|
92
|
+
"2015-04-26 00:18:00 UTC",
|
93
|
+
"2015-04-27 16:04:00 UTC",
|
94
|
+
"2015-04-28 04:05:00 UTC",
|
95
|
+
"2015-04-28 07:03:00 UTC",
|
96
|
+
"2015-04-28 08:19:00 UTC",
|
97
|
+
"2015-04-28 08:29:00 UTC",
|
98
|
+
"2015-04-28 09:01:00 UTC"], response.shipment_events.map { |e| e.time.strftime('%Y-%m-%d %H:%M:00 %Z') }
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_find_tracking_info_should_have_correct_names_for_shipment_events
|
102
|
+
@carrier.expects(:commit).returns(@tracking_response)
|
103
|
+
response = @carrier.find_tracking_info('9102901000462189604217')
|
104
|
+
assert_equal [
|
105
|
+
"SHIPPING LABEL CREATED",
|
106
|
+
"ACCEPTED AT USPS ORIGIN SORT FACILITY",
|
107
|
+
"ARRIVED AT USPS ORIGIN FACILITY",
|
108
|
+
"DEPARTED USPS FACILITY",
|
109
|
+
"ARRIVED AT USPS FACILITY",
|
110
|
+
"DEPARTED USPS FACILITY",
|
111
|
+
"ARRIVED AT POST OFFICE",
|
112
|
+
"SORTING COMPLETE",
|
113
|
+
"OUT FOR DELIVERY",
|
114
|
+
"DELIVERED"], response.shipment_events.map(&:name)
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_find_tracking_info_should_have_correct_locations_for_shipment_events
|
118
|
+
@carrier.expects(:commit).returns(@tracking_response)
|
119
|
+
response = @carrier.find_tracking_info('9102901000462189604217', :test => true)
|
120
|
+
assert_equal [
|
121
|
+
"ARGYLE, TX, 76226",
|
122
|
+
"ARGYLE, TX, 76226",
|
123
|
+
"COPPELL, TX, 75099",
|
124
|
+
"COPPELL, TX, 75099",
|
125
|
+
"HAZELWOOD, MO, 63042",
|
126
|
+
"HAZELWOOD, MO, 63042",
|
127
|
+
"HANNA CITY, IL, 61536",
|
128
|
+
"HANNA CITY, IL, 61536",
|
129
|
+
"HANNA CITY, IL, 61536",
|
130
|
+
"HANNA CITY, IL, 61536"], response.shipment_events.map(&:location).map { |l| "#{l.city}, #{l.state}, #{l.postal_code}" }
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_find_tracking_info_should_have_correct_event_codes_for_shipment_events
|
134
|
+
@carrier.expects(:commit).returns(@tracking_response)
|
135
|
+
response = @carrier.find_tracking_info('9102901000462189604217', :test => true)
|
136
|
+
assert_equal ["GX", "OA", "10", "EF", "10", "EF", "07", "PC", "OF", "01"], response.shipment_events.map(&:type_code)
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_find_tracking_info_should_handle_special_cases
|
140
|
+
@carrier.expects(:commit).returns(xml_fixture('usps/tracking_response_alt'))
|
141
|
+
response = @carrier.find_tracking_info('9102901000462189604217', :test => true)
|
142
|
+
assert_equal 'Canada', response.shipment_events.last.location.country.name
|
143
|
+
assert_equal :out_for_delivery, response.status
|
144
|
+
assert_nil response.scheduled_delivery_date
|
145
|
+
assert_nil response.shipment_events.last.location.city
|
146
|
+
|
147
|
+
time = Time.at(0)
|
148
|
+
expected_utc_time = Time.utc(time.year, time.month, time.mday, time.hour, time.min, time.sec)
|
149
|
+
|
150
|
+
assert_equal 'NP', response.shipment_events.first.type_code
|
151
|
+
assert_equal expected_utc_time, response.shipment_events.first.time
|
152
|
+
|
153
|
+
special_country = xml_fixture('usps/tracking_response_alt').gsub('CANADA','TAIWAN')
|
154
|
+
@carrier.expects(:commit).returns(special_country)
|
155
|
+
response = @carrier.find_tracking_info('9102901000462189604217', :test => true)
|
156
|
+
assert_equal 'Taiwan, Province of China', response.shipment_events.last.location.country.name
|
157
|
+
|
158
|
+
special_country = xml_fixture('usps/tracking_response_alt').gsub('CANADA','KOREA REPUBLIC OF')
|
159
|
+
@carrier.expects(:commit).returns(special_country)
|
160
|
+
response = @carrier.find_tracking_info('9102901000462189604217', :test => true)
|
161
|
+
assert_equal 'Korea, Republic of', response.shipment_events.last.location.country.name
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_find_tracking_info_destination
|
165
|
+
# USPS API doesn't tell where it's going
|
166
|
+
@carrier.expects(:commit).returns(@tracking_response)
|
167
|
+
response = @carrier.find_tracking_info('9102901000462189604217', :test => true)
|
168
|
+
assert_nil response.destination
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_find_tracking_info_tracking_number
|
172
|
+
@carrier.expects(:commit).returns(@tracking_response)
|
173
|
+
response = @carrier.find_tracking_info('9102901000462189604217', :test => true)
|
174
|
+
assert_equal '9102901000462189604217', response.tracking_number
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_find_tracking_info_should_have_correct_status
|
178
|
+
@carrier.expects(:commit).returns(@tracking_response)
|
179
|
+
response = @carrier.find_tracking_info('9102901000462189604217')
|
180
|
+
assert_equal :delivered, response.status
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_find_tracking_info_should_have_correct_delivered
|
184
|
+
@carrier.expects(:commit).returns(@tracking_response)
|
185
|
+
response = @carrier.find_tracking_info('9102901000462189604217')
|
186
|
+
assert_equal true, response.delivered?
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_tracking_batch_request_should_create_correct_xml
|
190
|
+
@carrier.expects(:commit).with(:track, xml_fixture('usps/tracking_request_batch'),false).returns(@batch_tracking_response)
|
191
|
+
@carrier.batch_find_tracking_info(@tracking_infos_array)
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_batch_find_tracking_info_should_return_a_tracking_response_array
|
195
|
+
@carrier.expects(:commit).returns(@batch_tracking_response)
|
196
|
+
responses = @carrier.batch_find_tracking_info(@tracking_infos_array, :test => true)
|
197
|
+
assert_equal 4, responses.length
|
198
|
+
assert responses.all? { |x| x.instance_of? ReactiveShipping::TrackingResponse}
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_batch_find_tracking_info_should_have_correct_data
|
202
|
+
@carrier.expects(:commit).returns(@batch_tracking_response)
|
203
|
+
responses = @carrier.batch_find_tracking_info(@tracking_infos_array, :test => true)
|
204
|
+
response = responses[0]
|
205
|
+
assert_equal ["GX", "OA", "10", "EF", "10", "EF", "07", "PC", "OF", "01"], response.shipment_events.map(&:type_code)
|
206
|
+
assert_equal Time.parse('April 28, 2015'), response.scheduled_delivery_date
|
207
|
+
assert_equal Time.parse('2015-04-28 09:01:00 UTC'), response.actual_delivery_date
|
208
|
+
assert_equal '9102901000462189604217', response.tracking_number
|
209
|
+
end
|
210
|
+
|
211
|
+
def test_batch_find_tracking_info_should_tolerate_failure
|
212
|
+
@carrier.expects(:commit).returns(@batch_tracking_response)
|
213
|
+
responses = @carrier.batch_find_tracking_info(@tracking_infos_array, :test => true)
|
214
|
+
response = responses[2]
|
215
|
+
refute response.success?
|
216
|
+
assert_equal "The Postal Service could not locate the tracking information for your request. Please verify your tracking number and try again later.",
|
217
|
+
response.message
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_batch_find_tracking_info_should_handle_not_found_error
|
221
|
+
@carrier.expects(:commit).returns(xml_fixture('usps/tracking_response_test_error'))
|
222
|
+
e = assert_raises ResponseError do
|
223
|
+
@carrier.find_tracking_info(@batch_tracking_response, :test => true)
|
224
|
+
end
|
225
|
+
assert_equal "This Information has not been included in this Test Server.", e.message
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_size_codes
|
229
|
+
assert_equal 'REGULAR', USPS.size_code_for(Package.new(2, [1, 12, 1], :units => :imperial))
|
230
|
+
assert_equal 'LARGE', USPS.size_code_for(Package.new(2, [12.1, 1, 1], :units => :imperial))
|
231
|
+
assert_equal 'LARGE', USPS.size_code_for(Package.new(2, [1000, 1000, 1000], :units => :imperial))
|
232
|
+
end
|
233
|
+
|
234
|
+
# TODO: test_parse_domestic_rate_response
|
235
|
+
|
236
|
+
def test_build_us_rate_request_uses_proper_container
|
237
|
+
expected_request = xml_fixture('usps/us_rate_request')
|
238
|
+
expected_request.gsub!('<Container/>','<Container>RECTANGULAR</Container>')
|
239
|
+
@carrier.expects(:commit).with(:us_rates, expected_request, false).returns(expected_request)
|
240
|
+
@carrier.expects(:parse_rate_response)
|
241
|
+
package = package_fixtures[:book]
|
242
|
+
package.options[:container] = :rectangular
|
243
|
+
@carrier.find_rates(location_fixtures[:beverly_hills], location_fixtures[:new_york], package, :test => true, :container => :rectangular)
|
244
|
+
end
|
245
|
+
|
246
|
+
def test_build_us_rate_request_uses_no_container_on_small_packages
|
247
|
+
expected_request = xml_fixture('usps/us_rate_request')
|
248
|
+
@carrier.expects(:commit).with(:us_rates, expected_request, false).returns(expected_request)
|
249
|
+
@carrier.expects(:parse_rate_response)
|
250
|
+
package = package_fixtures[:book]
|
251
|
+
@carrier.find_rates(location_fixtures[:beverly_hills], location_fixtures[:new_york], package, :test => true)
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_build_us_rate_request_uses_proper_container_when_none_is_specified
|
255
|
+
expected_request = xml_fixture('usps/us_rate_request_large')
|
256
|
+
@carrier.expects(:commit).with(:us_rates, expected_request, false).returns(expected_request)
|
257
|
+
@carrier.expects(:parse_rate_response)
|
258
|
+
package = package_fixtures[:big_half_pound]
|
259
|
+
@carrier.find_rates(location_fixtures[:beverly_hills], location_fixtures[:new_york], package, :test => true)
|
260
|
+
end
|
261
|
+
|
262
|
+
def test_build_world_rate_request
|
263
|
+
expected_request = xml_fixture('usps/world_rate_request_without_value')
|
264
|
+
@carrier.expects(:commit).with(:world_rates, expected_request, false).returns(expected_request)
|
265
|
+
@carrier.expects(:parse_rate_response)
|
266
|
+
@carrier.find_rates(location_fixtures[:beverly_hills], location_fixtures[:ottawa], package_fixtures[:book], :test => true, :acceptance_time => Time.parse("2015-06-01T20:34:29Z"))
|
267
|
+
end
|
268
|
+
|
269
|
+
def test_build_world_rate_request_with_package_value
|
270
|
+
expected_request = xml_fixture('usps/world_rate_request_with_value')
|
271
|
+
@carrier.expects(:commit).with(:world_rates, expected_request, false).returns(expected_request)
|
272
|
+
@carrier.expects(:parse_rate_response)
|
273
|
+
@carrier.find_rates(location_fixtures[:beverly_hills], location_fixtures[:ottawa], package_fixtures[:american_wii], :test => true, :acceptance_time => Time.parse("2015-06-01T20:34:29Z"))
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_build_world_rate_request_only_country
|
277
|
+
expected_request = xml_fixture('usps/world_rate_request_only_country')
|
278
|
+
@carrier.expects(:commit).with(:world_rates, expected_request, false).returns(expected_request)
|
279
|
+
@carrier.expects(:parse_rate_response)
|
280
|
+
@carrier.find_rates(location_fixtures[:beverly_hills], Location.new(:country => 'CZ'), package_fixtures[:american_wii], :test => true)
|
281
|
+
end
|
282
|
+
|
283
|
+
def test_initialize_options_requirements
|
284
|
+
assert_raises(ArgumentError) { USPS.new }
|
285
|
+
assert USPS.new(:login => 'blah')
|
286
|
+
end
|
287
|
+
|
288
|
+
def test_parse_international_rate_response
|
289
|
+
fixture_xml = xml_fixture('usps/beverly_hills_to_ottawa_american_wii_rate_response')
|
290
|
+
@carrier.expects(:commit).returns(fixture_xml)
|
291
|
+
|
292
|
+
response = begin
|
293
|
+
@carrier.find_rates(
|
294
|
+
location_fixtures[:beverly_hills], # imperial (U.S. origin)
|
295
|
+
location_fixtures[:ottawa],
|
296
|
+
package_fixtures[:american_wii],
|
297
|
+
:test => true
|
298
|
+
)
|
299
|
+
rescue ResponseError => e
|
300
|
+
e.response
|
301
|
+
end
|
302
|
+
|
303
|
+
expected_xml_hash = Hash.from_xml(fixture_xml)
|
304
|
+
actual_xml_hash = Hash.from_xml(response.xml)
|
305
|
+
|
306
|
+
assert_equal expected_xml_hash, actual_xml_hash
|
307
|
+
|
308
|
+
refute response.rates.empty?
|
309
|
+
|
310
|
+
assert_equal [1795, 3420, 5835, 8525, 8525], response.rates.map(&:price)
|
311
|
+
assert_equal [1, 2, 4, 12, 15], response.rates.map(&:service_code).map(&:to_i).sort
|
312
|
+
|
313
|
+
ordered_service_names = ["USPS Express Mail International",
|
314
|
+
"USPS First-Class Package International Service",
|
315
|
+
"USPS GXG Envelopes",
|
316
|
+
"USPS Global Express Guaranteed (GXG)",
|
317
|
+
"USPS Priority Mail International"]
|
318
|
+
assert_equal ordered_service_names, response.rates.map(&:service_name).sort
|
319
|
+
end
|
320
|
+
|
321
|
+
def test_parse_international_rate_response_errors
|
322
|
+
fixture_xml = xml_fixture('usps/api_error_rate_response')
|
323
|
+
@carrier.expects(:commit).returns(fixture_xml)
|
324
|
+
|
325
|
+
error = assert_raises(ResponseError) do
|
326
|
+
@carrier.find_rates(
|
327
|
+
location_fixtures[:beverly_hills], # imperial (U.S. origin)
|
328
|
+
location_fixtures[:ottawa],
|
329
|
+
package_fixtures[:american_wii],
|
330
|
+
:test => true
|
331
|
+
)
|
332
|
+
end
|
333
|
+
assert_equal 'This is a test response with the format of a real error.', error.message
|
334
|
+
end
|
335
|
+
|
336
|
+
def test_parse_max_dimension_sentences
|
337
|
+
limits = {
|
338
|
+
"Max. length 46\", width 35\", height 46\" and max. length plus girth 108\"" =>
|
339
|
+
[{:length => 46.0, :width => 46.0, :height => 35.0, :length_plus_girth => 108.0}],
|
340
|
+
"Max.length 42\", max. length plus girth 79\"" =>
|
341
|
+
[{:length => 42.0, :length_plus_girth => 79.0}],
|
342
|
+
"9 1/2\" X 12 1/2\"" =>
|
343
|
+
[{:length => 12.5, :width => 9.5, :height => 0.75}, "Flat Rate Envelope"],
|
344
|
+
"Maximum length and girth combined 108\"" =>
|
345
|
+
[{:length_plus_girth => 108.0}],
|
346
|
+
"USPS-supplied Priority Mail flat-rate envelope 9 1/2\" x 12 1/2.\" Maximum weight 4 pounds." =>
|
347
|
+
[{:length => 12.5, :width => 9.5, :height => 0.75}, "Flat Rate Envelope"],
|
348
|
+
"Max. length 24\", Max. length, height, depth combined 36\"" =>
|
349
|
+
[{:length => 24.0, :length_plus_width_plus_height => 36.0}]
|
350
|
+
}
|
351
|
+
p = package_fixtures[:book]
|
352
|
+
limits.each do |sentence, hashes|
|
353
|
+
dimensions = hashes[0].update(:weight => 50.0)
|
354
|
+
service_node = build_service_node(
|
355
|
+
:name => hashes[1],
|
356
|
+
:max_weight => 50,
|
357
|
+
:max_dimensions => sentence )
|
358
|
+
@carrier.expects(:package_valid_for_max_dimensions).with(p, dimensions)
|
359
|
+
@carrier.send(:package_valid_for_service, p, service_node)
|
360
|
+
end
|
361
|
+
|
362
|
+
service_node = build_service_node(
|
363
|
+
:name => "flat-rate box",
|
364
|
+
:max_weight => 50,
|
365
|
+
:max_dimensions => "USPS-supplied Priority Mail flat-rate box. Maximum weight 20 pounds." )
|
366
|
+
|
367
|
+
# should test against either kind of flat rate box:
|
368
|
+
dimensions = [{:weight => 50.0, :length => 11.0, :width => 8.5, :height => 5.5}, # or...
|
369
|
+
{:weight => 50.0, :length => 13.625, :width => 11.875, :height => 3.375}]
|
370
|
+
@carrier.expects(:package_valid_for_max_dimensions).with(p, dimensions[0])
|
371
|
+
@carrier.expects(:package_valid_for_max_dimensions).with(p, dimensions[1])
|
372
|
+
@carrier.send(:package_valid_for_service, p, service_node)
|
373
|
+
end
|
374
|
+
|
375
|
+
def test_package_valid_for_max_dimensions
|
376
|
+
p = Package.new(70 * 16, [10, 10, 10], :units => :imperial)
|
377
|
+
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}
|
378
|
+
assert_equal true, @carrier.send(:package_valid_for_max_dimensions, p, limits)
|
379
|
+
|
380
|
+
limits.keys.each do |key|
|
381
|
+
dimensions = {key => (limits[key] - 1)}
|
382
|
+
assert_equal false, @carrier.send(:package_valid_for_max_dimensions, p, dimensions)
|
383
|
+
end
|
384
|
+
end
|
385
|
+
|
386
|
+
def test_strip_9_digit_zip_codes
|
387
|
+
request = URI.decode(@carrier.send(:build_us_rate_request, package_fixtures[:book], "90210-1234", "123456789"))
|
388
|
+
assert !(request =~ /\>90210-1234\</)
|
389
|
+
assert request =~ /\>90210\</
|
390
|
+
assert !(request =~ /\>123456789\</)
|
391
|
+
assert request =~ /\>12345\</
|
392
|
+
end
|
393
|
+
|
394
|
+
def test_strip_9_digit_zip_codes_world_rates
|
395
|
+
request = URI.decode(@carrier.send(:build_world_rate_request, location_fixtures[:beverly_hills_9_zip],
|
396
|
+
package_fixtures[:book], location_fixtures[:auckland], {}))
|
397
|
+
refute_match /\<OriginZip\>90210-1234/, request
|
398
|
+
assert_match /\<OriginZip\>90210/, request
|
399
|
+
end
|
400
|
+
|
401
|
+
def test_maximum_weight
|
402
|
+
assert Package.new(70 * 16, [5, 5, 5], :units => :imperial).mass == @carrier.maximum_weight
|
403
|
+
assert Package.new((70 * 16) + 0.01, [5, 5, 5], :units => :imperial).mass > @carrier.maximum_weight
|
404
|
+
assert Package.new((70 * 16) - 0.01, [5, 5, 5], :units => :imperial).mass < @carrier.maximum_weight
|
405
|
+
end
|
406
|
+
|
407
|
+
def test_updated_domestic_rate_name_format_with_unescaped_html
|
408
|
+
mock_response = xml_fixture('usps/beverly_hills_to_new_york_book_rate_response')
|
409
|
+
@carrier.expects(:commit).returns(mock_response)
|
410
|
+
rates_response = @carrier.find_rates(
|
411
|
+
location_fixtures[:beverly_hills],
|
412
|
+
location_fixtures[:new_york],
|
413
|
+
package_fixtures[:book],
|
414
|
+
:test => true
|
415
|
+
)
|
416
|
+
rate_names = [
|
417
|
+
'USPS Express Mail',
|
418
|
+
'USPS Express Mail Flat Rate Envelope',
|
419
|
+
'USPS Express Mail Flat Rate Envelope Hold For Pickup',
|
420
|
+
'USPS Express Mail Hold For Pickup',
|
421
|
+
'USPS Express Mail Legal Flat Rate Envelope',
|
422
|
+
'USPS Express Mail Legal Flat Rate Envelope Hold For Pickup',
|
423
|
+
'USPS Express Mail Sunday/Holiday Delivery',
|
424
|
+
'USPS Express Mail Sunday/Holiday Delivery Flat Rate Envelope',
|
425
|
+
'USPS Express Mail Sunday/Holiday Delivery Legal Flat Rate Envelope',
|
426
|
+
'USPS First-Class Mail Large Envelope',
|
427
|
+
'USPS First-Class Mail Package',
|
428
|
+
'USPS Library Mail',
|
429
|
+
'USPS Media Mail',
|
430
|
+
'USPS Parcel Post',
|
431
|
+
'USPS Priority Mail',
|
432
|
+
'USPS Priority Mail Flat Rate Envelope',
|
433
|
+
'USPS Priority Mail Gift Card Flat Rate Envelope',
|
434
|
+
'USPS Priority Mail Large Flat Rate Box',
|
435
|
+
'USPS Priority Mail Legal Flat Rate Envelope',
|
436
|
+
'USPS Priority Mail Medium Flat Rate Box',
|
437
|
+
'USPS Priority Mail Padded Flat Rate Envelope',
|
438
|
+
'USPS Priority Mail Small Flat Rate Box',
|
439
|
+
'USPS Priority Mail Small Flat Rate Envelope',
|
440
|
+
'USPS Priority Mail Window Flat Rate Envelope'
|
441
|
+
]
|
442
|
+
assert_equal rate_names, rates_response.rates.collect(&:service_name).sort
|
443
|
+
end
|
444
|
+
|
445
|
+
def test_first_class_packages_with_mail_type
|
446
|
+
@carrier.expects(:commit).returns(xml_fixture('usps/first_class_packages_with_mail_type_response'))
|
447
|
+
|
448
|
+
response = begin
|
449
|
+
@carrier.find_rates(
|
450
|
+
location_fixtures[:beverly_hills], # imperial (U.S. origin)
|
451
|
+
location_fixtures[:new_york],
|
452
|
+
Package.new(0, 0),
|
453
|
+
|
454
|
+
:test => true,
|
455
|
+
:service => :first_class,
|
456
|
+
:first_class_mail_type => :parcel
|
457
|
+
|
458
|
+
)
|
459
|
+
rescue ResponseError => e
|
460
|
+
e.response
|
461
|
+
end
|
462
|
+
assert response.success?, response.message
|
463
|
+
end
|
464
|
+
|
465
|
+
def test_first_class_packages_without_mail_type
|
466
|
+
@carrier.expects(:commit).returns(xml_fixture('usps/first_class_packages_without_mail_type_response'))
|
467
|
+
|
468
|
+
begin
|
469
|
+
@carrier.find_rates(
|
470
|
+
location_fixtures[:beverly_hills], # imperial (U.S. origin)
|
471
|
+
location_fixtures[:new_york],
|
472
|
+
Package.new(0, 0),
|
473
|
+
|
474
|
+
:test => true,
|
475
|
+
:service => :first_class
|
476
|
+
|
477
|
+
)
|
478
|
+
rescue ResponseError => e
|
479
|
+
assert_equal "Invalid First Class Mail Type.", e.message
|
480
|
+
end
|
481
|
+
end
|
482
|
+
|
483
|
+
def test_first_class_packages_with_invalid_mail_type
|
484
|
+
@carrier.expects(:commit).returns(xml_fixture('usps/first_class_packages_with_invalid_mail_type_response'))
|
485
|
+
|
486
|
+
begin
|
487
|
+
@carrier.find_rates(
|
488
|
+
location_fixtures[:beverly_hills], # imperial (U.S. origin)
|
489
|
+
location_fixtures[:new_york],
|
490
|
+
Package.new(0, 0),
|
491
|
+
|
492
|
+
:test => true,
|
493
|
+
:service => :first_class,
|
494
|
+
:first_class_mail_tpe => :invalid
|
495
|
+
|
496
|
+
)
|
497
|
+
rescue ResponseError => e
|
498
|
+
assert_equal "Invalid First Class Mail Type.", e.message
|
499
|
+
end
|
500
|
+
end
|
501
|
+
|
502
|
+
def test_domestic_retail_rates
|
503
|
+
mock_response = xml_fixture('usps/beverly_hills_to_new_york_book_commercial_base_rate_response')
|
504
|
+
@carrier.expects(:commit).returns(mock_response)
|
505
|
+
|
506
|
+
response = @carrier.find_rates(
|
507
|
+
location_fixtures[:beverly_hills],
|
508
|
+
location_fixtures[:new_york],
|
509
|
+
package_fixtures.values_at(:book),
|
510
|
+
:test => true
|
511
|
+
)
|
512
|
+
|
513
|
+
rates = Hash[response.rates.map { |rate| [rate.service_name, rate.price] }]
|
514
|
+
|
515
|
+
assert_equal 0, rates["USPS First-Class Package Service"] # the "first class package service" is only available for commercial base shippers
|
516
|
+
assert_equal 309, rates["USPS First-Class Mail Parcel"] # 2013 retail 9oz first class parcel is $3.09
|
517
|
+
assert_equal 695, rates["USPS Priority Mail"] # 2013 1lb zone 8 priority retail is $6.95
|
518
|
+
end
|
519
|
+
|
520
|
+
def test_domestic_commercial_base_rates
|
521
|
+
commercial_base_credentials = { key: "123", login: "user", password: "pass", commercial_base: true }
|
522
|
+
carrier = USPS.new(commercial_base_credentials)
|
523
|
+
|
524
|
+
mock_response = xml_fixture('usps/beverly_hills_to_new_york_book_commercial_base_rate_response')
|
525
|
+
carrier.expects(:commit).returns(mock_response)
|
526
|
+
|
527
|
+
response = carrier.find_rates(
|
528
|
+
location_fixtures[:beverly_hills],
|
529
|
+
location_fixtures[:new_york],
|
530
|
+
package_fixtures.values_at(:book),
|
531
|
+
:test => true
|
532
|
+
)
|
533
|
+
|
534
|
+
rates = Hash[response.rates.map { |rate| [rate.service_name, rate.price] }]
|
535
|
+
|
536
|
+
assert_equal 0, rates["USPS First-Class Mail Parcel"] # commercial base prices retail first class is unavailable. must ship as package service
|
537
|
+
assert_equal 273, rates["USPS First-Class Package Service"] # the "first class package service" should be present for commerical base (instead of USPS First-Class Mail Parcel for retail rates)
|
538
|
+
assert_equal 651, rates["USPS Priority Mail"] # 2013 zone 8 commercial base price is 6.51, retail is 6.95
|
539
|
+
end
|
540
|
+
|
541
|
+
def test_intl_commercial_base_rates
|
542
|
+
commercial_base_credentials = { key: "123", login: "user", password: "pass", commercial_base: true }
|
543
|
+
carrier = USPS.new(commercial_base_credentials)
|
544
|
+
|
545
|
+
mock_response = xml_fixture('usps/beverly_hills_to_ottawa_american_wii_commercial_base_rate_response')
|
546
|
+
carrier.expects(:commit).returns(mock_response)
|
547
|
+
|
548
|
+
response = carrier.find_rates(
|
549
|
+
location_fixtures[:beverly_hills],
|
550
|
+
location_fixtures[:ottawa],
|
551
|
+
package_fixtures.values_at(:american_wii),
|
552
|
+
:test => true
|
553
|
+
)
|
554
|
+
|
555
|
+
assert_equal [4112, 6047, 7744, 7744], response.rates.map(&:price) # note these prices are higher than the normal/retail unit tests because the rates from that test is years older than from this test
|
556
|
+
end
|
557
|
+
|
558
|
+
def test_domestic_commercial_plus_rates
|
559
|
+
commercial_plus_credentials = { key: "123", login: "user", password: "pass", commercial_plus: true }
|
560
|
+
carrier = USPS.new(commercial_plus_credentials)
|
561
|
+
|
562
|
+
mock_response = xml_fixture('usps/beverly_hills_to_new_york_book_commercial_plus_rate_response')
|
563
|
+
carrier.expects(:commit).returns(mock_response)
|
564
|
+
|
565
|
+
response = carrier.find_rates(
|
566
|
+
location_fixtures[:beverly_hills],
|
567
|
+
location_fixtures[:new_york],
|
568
|
+
package_fixtures.values_at(:book),
|
569
|
+
:test => true
|
570
|
+
)
|
571
|
+
|
572
|
+
rates = Hash[response.rates.map { |rate| [rate.service_name, rate.price] }]
|
573
|
+
|
574
|
+
assert_equal 0, rates["USPS First-Class Mail Parcel"]
|
575
|
+
assert_equal 405, rates["USPS First-Class Package Service"]
|
576
|
+
assert_equal 625, rates["USPS Priority Mail 2-Day"]
|
577
|
+
end
|
578
|
+
|
579
|
+
def test_intl_commercial_plus_rates
|
580
|
+
commercial_plus_credentials = { key: "123", login: "user", password: "pass", commercial_plus: true }
|
581
|
+
carrier = USPS.new(commercial_plus_credentials)
|
582
|
+
|
583
|
+
mock_response = xml_fixture('usps/beverly_hills_to_ottawa_american_wii_commercial_plus_rate_response')
|
584
|
+
carrier.expects(:commit).returns(mock_response)
|
585
|
+
|
586
|
+
response = carrier.find_rates(
|
587
|
+
location_fixtures[:beverly_hills],
|
588
|
+
location_fixtures[:ottawa],
|
589
|
+
package_fixtures.values_at(:american_wii),
|
590
|
+
:test => true
|
591
|
+
)
|
592
|
+
|
593
|
+
assert_equal [3767, 5526, 7231, 7231], response.rates.map(&:price)
|
594
|
+
end
|
595
|
+
|
596
|
+
def test_maximum_address_field_length
|
597
|
+
assert_equal 38, @carrier.maximum_address_field_length
|
598
|
+
end
|
599
|
+
|
600
|
+
private
|
601
|
+
|
602
|
+
def build_service_node(options = {})
|
603
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
604
|
+
xml.Service do
|
605
|
+
xml.Pounds(options[:pounds] || "0")
|
606
|
+
xml.SvcCommitments(options[:svc_commitments] || "Varies")
|
607
|
+
xml.Country(options[:country] || "CANADA")
|
608
|
+
xml.ID(options[:id] || "3")
|
609
|
+
xml.MaxWeight(options[:max_weight] || "64")
|
610
|
+
xml.SvcDescription(options[:name] || "First-Class Mail International")
|
611
|
+
xml.MailType(options[:mail_type] || "Package")
|
612
|
+
xml.Postage(options[:postage] || "3.76")
|
613
|
+
xml.Ounces(options[:ounces] || "9")
|
614
|
+
xml.MaxDimensions(options[:max_dimensions].dup || "Max. length 24\", Max. length, height, depth combined 36\"")
|
615
|
+
end
|
616
|
+
end
|
617
|
+
builder.doc.root
|
618
|
+
end
|
619
|
+
|
620
|
+
def build_service_hash(options = {})
|
621
|
+
{"Pounds" => options[:pounds] || "0",
|
622
|
+
"SvcCommitments" => options[:svc_commitments] || "Varies",
|
623
|
+
"Country" => options[:country] || "CANADA",
|
624
|
+
"ID" => options[:id] || "3",
|
625
|
+
"MaxWeight" => options[:max_weight] || "64",
|
626
|
+
"SvcDescription" => options[:name] || "First-Class Mail International",
|
627
|
+
"MailType" => options[:mail_type] || "Package",
|
628
|
+
"Postage" => options[:postage] || "3.76",
|
629
|
+
"Ounces" => options[:ounces] || "9",
|
630
|
+
"MaxDimensions" => options[:max_dimensions] ||
|
631
|
+
"Max. length 24\", Max. length, height, depth combined 36\""}
|
632
|
+
end
|
633
|
+
end
|