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,56 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class KunakiTest < ActiveSupport::TestCase
|
4
|
+
include ReactiveShipping::Test::Fixtures
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@carrier = Kunaki.new
|
8
|
+
@items = [{ :sku => 'AF0001', :quantity => 1 }, { :sku => 'AF0002', :quantity => 2 }]
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_unsuccessful_rate_request
|
12
|
+
@carrier.expects(:ssl_post).returns(xml_fixture('kunaki/unsuccessful_rates_response'))
|
13
|
+
|
14
|
+
assert_raises(ResponseError) do
|
15
|
+
begin
|
16
|
+
@carrier.find_rates(
|
17
|
+
location_fixtures[:ottawa],
|
18
|
+
location_fixtures[:beverly_hills],
|
19
|
+
package_fixtures.values_at(:book, :wii),
|
20
|
+
:items => @items
|
21
|
+
)
|
22
|
+
rescue ResponseError => e
|
23
|
+
assert_equal "Request contains invalid XML syntax", e.response.message
|
24
|
+
assert_equal "100", e.response.params["ErrorCode"]
|
25
|
+
raise
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_successfully_get_rates
|
31
|
+
@carrier.expects(:ssl_post).returns(xml_fixture('kunaki/successful_rates_response'))
|
32
|
+
|
33
|
+
response = @carrier.find_rates(
|
34
|
+
location_fixtures[:ottawa],
|
35
|
+
location_fixtures[:london],
|
36
|
+
package_fixtures.values_at(:book, :wii),
|
37
|
+
:items => @items
|
38
|
+
)
|
39
|
+
|
40
|
+
assert response.success?
|
41
|
+
|
42
|
+
assert_equal 4, response.rates.size
|
43
|
+
|
44
|
+
assert rate = response.rates.first
|
45
|
+
assert_equal "USPS Priority Mail", rate.service_name
|
46
|
+
assert_nil rate.service_code
|
47
|
+
assert_equal "USPS", rate.carrier
|
48
|
+
assert_equal 800, rate.total_price
|
49
|
+
assert_equal ["UPS 2nd Day Air", "UPS Ground", "UPS Next Day Air Saver", "USPS Priority Mail"], response.rates.collect(&:service_name).sort
|
50
|
+
assert_equal [800, 1234, 2186, 3605], response.rates.collect(&:total_price).sort
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_maximum_address_field_length
|
54
|
+
assert_equal 255, @carrier.maximum_address_field_length
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,177 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class NewZealandPostTest < ActiveSupport::TestCase
|
4
|
+
include ReactiveShipping::Test::Fixtures
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@carrier = NewZealandPost.new(:key => "4d9dc0f0-dda0-012e-066f-000c29b44ac0")
|
8
|
+
@wellington = location_fixtures[:wellington]
|
9
|
+
@auckland = location_fixtures[:auckland]
|
10
|
+
@ottawa = location_fixtures[:ottawa]
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_domestic_book_request
|
14
|
+
url = "http://api.nzpost.co.nz/ratefinder/domestic?api_key=4d9dc0f0-dda0-012e-066f-000c29b44ac0&carrier=all&format=json&height=20.0&length=190.0&postcode_dest=1010&postcode_src=6011&thickness=140.0&weight=0.25"
|
15
|
+
@carrier.expects(:commit).with([url]).returns([json_fixture("newzealandpost/domestic_book")])
|
16
|
+
@carrier.find_rates(@wellington, @auckland, package_fixtures[:book])
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_domestic_poster_request
|
20
|
+
url = "http://api.nzpost.co.nz/ratefinder/domestic?api_key=4d9dc0f0-dda0-012e-066f-000c29b44ac0&carrier=all&diameter=100.0&format=json&length=930.0&postcode_dest=1010&postcode_src=6011&weight=0.1"
|
21
|
+
@carrier.expects(:commit).with([url]).returns([json_fixture("newzealandpost/domestic_poster")])
|
22
|
+
@carrier.find_rates(@wellington, @auckland, package_fixtures[:poster])
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_domestic_combined_request
|
26
|
+
urls = [
|
27
|
+
"http://api.nzpost.co.nz/ratefinder/domestic?api_key=4d9dc0f0-dda0-012e-066f-000c29b44ac0&carrier=all&format=json&height=20.0&length=190.0&postcode_dest=1010&postcode_src=6011&thickness=140.0&weight=0.25",
|
28
|
+
"http://api.nzpost.co.nz/ratefinder/domestic?api_key=4d9dc0f0-dda0-012e-066f-000c29b44ac0&carrier=all&format=json&height=25.4&length=25.4&postcode_dest=1010&postcode_src=6011&thickness=25.4&weight=0.226796185"
|
29
|
+
]
|
30
|
+
@carrier.expects(:commit).with(urls).returns([json_fixture("newzealandpost/domestic_book"), json_fixture("newzealandpost/domestic_small_half_pound")])
|
31
|
+
@carrier.find_rates(@wellington, @auckland, package_fixtures.values_at(:book, :small_half_pound))
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_domestic_book_response
|
35
|
+
@carrier.expects(:commit).returns([json_fixture("newzealandpost/domestic_book")])
|
36
|
+
response = @carrier.find_rates(@wellington, @auckland, package_fixtures[:book])
|
37
|
+
assert_equal 13, response.rates.size
|
38
|
+
assert_equal [300, 360, 400, 420, 450, 450, 500, 500, 550, 655, 715, 880, 890], response.rates.map(&:price)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_domestic_poster_response
|
42
|
+
@carrier.expects(:commit).returns([json_fixture("newzealandpost/domestic_poster")])
|
43
|
+
response = @carrier.find_rates(@wellington, @auckland, package_fixtures[:poster])
|
44
|
+
assert_equal 1, response.rates.size
|
45
|
+
assert_equal [750], response.rates.map(&:price)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_domestic_combined_response_parsing
|
49
|
+
@carrier.expects(:commit).returns([json_fixture("newzealandpost/domestic_book"), json_fixture("newzealandpost/domestic_small_half_pound")])
|
50
|
+
response = @carrier.find_rates(@wellington, @auckland, package_fixtures.values_at(:book, :small_half_pound))
|
51
|
+
assert_equal 8, response.rates.size
|
52
|
+
assert_equal [800, 840, 900, 900, 1000, 1100, 1430, 1780], response.rates.map(&:price)
|
53
|
+
assert_equal %w(PIKFC5 PCB3C5 PIFFC5 PIKBC5 PIFBC5 PICBC5 NZPRBA5 NZSRBA5), response.rates.map(&:service_code)
|
54
|
+
names = [
|
55
|
+
"ParcelPost C5 Flat Bag",
|
56
|
+
"ParcelPost Tracked C5 Postage Only - Tracked",
|
57
|
+
"ParcelPost Fast C5 Flat Bag",
|
58
|
+
"ParcelPost C5 Bubble Bag",
|
59
|
+
"ParcelPost Fast C5 Bubble Bag",
|
60
|
+
"ParcelPost Tracked C5 Bubble Bag - Tracked",
|
61
|
+
"Courier C5 Ready To Go Courier Bubble Bag",
|
62
|
+
"Courier C5 Ready To Go Courier Bubble Bag S/R"
|
63
|
+
]
|
64
|
+
assert_equal names, response.rates.map(&:service_name)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_domestic_shipping_container_response_error
|
68
|
+
@carrier.expects(:commit).returns([json_fixture("newzealandpost/domestic_error")])
|
69
|
+
error = @carrier.find_rates(@wellington, @auckland, package_fixtures[:shipping_container]) rescue $!
|
70
|
+
assert_equal ReactiveShipping::ResponseError, error.class
|
71
|
+
assert_equal "Weight can only be between 0 and 25kg", error.message
|
72
|
+
assert_equal [json_fixture("newzealandpost/domestic_error")], error.response.raw_responses
|
73
|
+
response_params = { "responses" => [JSON.parse(json_fixture("newzealandpost/domestic_error"))] }
|
74
|
+
assert_equal response_params, error.response.params
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_domestic_blank_package_response
|
78
|
+
url = "http://api.nzpost.co.nz/ratefinder/domestic?api_key=4d9dc0f0-dda0-012e-066f-000c29b44ac0&carrier=all&format=json&height=0.0&length=0.0&postcode_dest=1010&postcode_src=6011&thickness=0.0&weight=0.0"
|
79
|
+
@carrier.expects(:commit).with([url]).returns([json_fixture("newzealandpost/domestic_default")])
|
80
|
+
response = @carrier.find_rates(@wellington, @auckland, package_fixtures[:just_zero_grams])
|
81
|
+
assert_equal [240, 300, 400, 420, 450, 450, 450, 500, 550, 589, 715, 830, 890], response.rates.map(&:price)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_domestic_book_response_params
|
85
|
+
url = "http://api.nzpost.co.nz/ratefinder/domestic?api_key=4d9dc0f0-dda0-012e-066f-000c29b44ac0&carrier=all&format=json&height=20.0&length=190.0&postcode_dest=1010&postcode_src=6011&thickness=140.0&weight=0.25"
|
86
|
+
@carrier.expects(:commit).with([url]).returns([json_fixture("newzealandpost/domestic_book")])
|
87
|
+
response = @carrier.find_rates(@wellington, @auckland, package_fixtures[:book])
|
88
|
+
assert_equal [url], response.request
|
89
|
+
assert_equal [json_fixture("newzealandpost/domestic_book")], response.raw_responses
|
90
|
+
assert_equal [JSON.parse(json_fixture("newzealandpost/domestic_book"))], response.params["responses"]
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_international_book_request
|
94
|
+
url = "http://api.nzpost.co.nz/ratefinder/international?api_key=4d9dc0f0-dda0-012e-066f-000c29b44ac0&country_code=CA&format=json&height=20.0&length=190.0&thickness=140.0&value=0&weight=0.25"
|
95
|
+
@carrier.expects(:commit).with([url]).returns([json_fixture("newzealandpost/international_book")])
|
96
|
+
@carrier.find_rates(@wellington, @ottawa, package_fixtures[:book])
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_international_wii_request
|
100
|
+
url = "http://api.nzpost.co.nz/ratefinder/international?api_key=4d9dc0f0-dda0-012e-066f-000c29b44ac0&country_code=CA&format=json&height=114.3&length=381.0&thickness=254.0&value=269&weight=3.401942775"
|
101
|
+
@carrier.expects(:commit).with([url]).returns([json_fixture("newzealandpost/international_new_zealand_wii")])
|
102
|
+
@carrier.find_rates(@wellington, @ottawa, package_fixtures[:new_zealand_wii])
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_international_uk_wii_request
|
106
|
+
url = "http://api.nzpost.co.nz/ratefinder/international?api_key=4d9dc0f0-dda0-012e-066f-000c29b44ac0&country_code=CA&format=json&height=114.3&length=381.0&thickness=254.0&value=0&weight=3.401942775"
|
107
|
+
@carrier.expects(:commit).with([url]).returns([json_fixture("newzealandpost/international_wii")])
|
108
|
+
@carrier.find_rates(@wellington, @ottawa, package_fixtures[:wii])
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_international_book_response_params
|
112
|
+
url = "http://api.nzpost.co.nz/ratefinder/international?api_key=4d9dc0f0-dda0-012e-066f-000c29b44ac0&country_code=CA&format=json&height=20.0&length=190.0&thickness=140.0&value=0&weight=0.25"
|
113
|
+
@carrier.expects(:commit).with([url]).returns([json_fixture("newzealandpost/international_book")])
|
114
|
+
response = @carrier.find_rates(@wellington, @ottawa, package_fixtures[:book])
|
115
|
+
assert_equal [url], response.request
|
116
|
+
assert_equal [json_fixture("newzealandpost/international_book")], response.raw_responses
|
117
|
+
assert_equal [JSON.parse(json_fixture("newzealandpost/international_book"))], response.params["responses"]
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_international_combined_request
|
121
|
+
urls = [
|
122
|
+
"http://api.nzpost.co.nz/ratefinder/international?api_key=4d9dc0f0-dda0-012e-066f-000c29b44ac0&country_code=CA&format=json&height=20.0&length=190.0&thickness=140.0&value=0&weight=0.25",
|
123
|
+
"http://api.nzpost.co.nz/ratefinder/international?api_key=4d9dc0f0-dda0-012e-066f-000c29b44ac0&country_code=CA&format=json&height=25.4&length=25.4&thickness=25.4&value=0&weight=0.226796185"
|
124
|
+
]
|
125
|
+
@carrier.expects(:commit).with(urls).returns([json_fixture("newzealandpost/international_book"), json_fixture("newzealandpost/international_wii")])
|
126
|
+
@carrier.find_rates(@wellington, @ottawa, package_fixtures.values_at(:book, :small_half_pound))
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_international_combined_response_parsing
|
130
|
+
@carrier.expects(:commit).returns([json_fixture("newzealandpost/international_book"), json_fixture("newzealandpost/international_small_half_pound")])
|
131
|
+
response = @carrier.find_rates(@wellington, @ottawa, package_fixtures.values_at(:book, :small_half_pound))
|
132
|
+
assert_equal 4, response.rates.size
|
133
|
+
assert_equal [13050, 8500, 2460, 2214], response.rates.map(&:price)
|
134
|
+
assert_equal %w(ICPNC500 IEZPC500 IACNC500 IECNC500), response.rates.map(&:service_code)
|
135
|
+
names = [
|
136
|
+
"International Express Courier Int Express Pcl Zone C 500gm",
|
137
|
+
"International Economy Courier Int Econ Cour Pcl Zn C 500gm",
|
138
|
+
"International Air Zone C AirPost Cust Pcl 500gm",
|
139
|
+
"International Economy Zone C EconomyPost Pcl 500gm"
|
140
|
+
]
|
141
|
+
assert_equal names, response.rates.map(&:service_name)
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_international_empty_json_response_error
|
145
|
+
@carrier.expects(:commit).returns([""])
|
146
|
+
error = @carrier.find_rates(@wellington, @ottawa, package_fixtures[:book]) rescue $!
|
147
|
+
assert_equal ReactiveShipping::ResponseError, error.class
|
148
|
+
assert_equal [""], error.response.raw_responses
|
149
|
+
response_params = { "responses" => [] }
|
150
|
+
assert_equal response_params, error.response.params
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_international_invalid_json_response_error
|
154
|
+
@carrier.expects(:commit).returns(["<>"])
|
155
|
+
error = @carrier.find_rates(@wellington, @ottawa, package_fixtures[:book]) rescue $!
|
156
|
+
assert_equal ReactiveShipping::ResponseError, error.class
|
157
|
+
assert error.message.include?("unexpected token")
|
158
|
+
assert_equal ["<>"], error.response.raw_responses
|
159
|
+
response_params = { "responses" => [] }
|
160
|
+
assert_equal response_params, error.response.params
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_international_invalid_origin_country_response
|
164
|
+
error = @carrier.find_rates(@ottawa, @wellington, package_fixtures[:book]) rescue $!
|
165
|
+
assert_equal ReactiveShipping::ResponseError, error.class
|
166
|
+
assert_equal "New Zealand Post packages must originate in New Zealand", error.message
|
167
|
+
assert_equal [], error.response.raw_responses
|
168
|
+
assert_equal Array, error.response.request.class
|
169
|
+
assert_equal 1, error.response.request.size
|
170
|
+
response_params = { "responses" => [] }
|
171
|
+
assert_equal response_params, error.response.params
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_maximum_address_field_length
|
175
|
+
assert_equal 255, @carrier.maximum_address_field_length
|
176
|
+
end
|
177
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ShipwireTest < ActiveSupport::TestCase
|
4
|
+
include ReactiveShipping::Test::Fixtures
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@carrier = Shipwire.new(:login => 'l', :password => 'p')
|
8
|
+
@items = [{ :sku => 'AF0001', :quantity => 1 }, { :sku => 'AF0002', :quantity => 2 }]
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_response_with_no_rates_is_unsuccessful
|
12
|
+
@carrier.expects(:ssl_post).returns(xml_fixture('shipwire/no_rates_response'))
|
13
|
+
|
14
|
+
assert_raises(ResponseError) do
|
15
|
+
@carrier.find_rates(
|
16
|
+
location_fixtures[:ottawa],
|
17
|
+
location_fixtures[:beverly_hills],
|
18
|
+
package_fixtures.values_at(:book, :wii),
|
19
|
+
:order_id => '#1000',
|
20
|
+
:items => @items
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_successfully_get_international_rates
|
26
|
+
date = DateTime.parse("Mon 01 Aug 2011")
|
27
|
+
@carrier.expects(:ssl_post).returns(xml_fixture('shipwire/international_rates_response'))
|
28
|
+
|
29
|
+
Timecop.freeze(date) do
|
30
|
+
response = @carrier.find_rates(
|
31
|
+
location_fixtures[:ottawa],
|
32
|
+
location_fixtures[:london],
|
33
|
+
package_fixtures.values_at(:book, :wii),
|
34
|
+
:order_id => '#1000',
|
35
|
+
:items => @items
|
36
|
+
)
|
37
|
+
|
38
|
+
assert response.success?
|
39
|
+
|
40
|
+
assert_equal 1, response.rates.size
|
41
|
+
|
42
|
+
assert international = response.rates.first
|
43
|
+
assert_equal "INTL", international.service_code
|
44
|
+
assert_equal "UPS", international.carrier
|
45
|
+
assert_equal "UPS Standard", international.service_name
|
46
|
+
assert_equal 2806, international.total_price
|
47
|
+
assert_equal [date + 1.day, date + 7.days], international.delivery_range
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_successfully_get_domestic_rates
|
52
|
+
date = DateTime.parse("Mon 01 Aug 2011")
|
53
|
+
@carrier.expects(:ssl_post).returns(xml_fixture('shipwire/rates_response'))
|
54
|
+
|
55
|
+
Timecop.freeze(date) do
|
56
|
+
response = @carrier.find_rates(
|
57
|
+
location_fixtures[:ottawa],
|
58
|
+
location_fixtures[:beverly_hills],
|
59
|
+
package_fixtures.values_at(:book, :wii),
|
60
|
+
:order_id => '#1000',
|
61
|
+
:items => @items
|
62
|
+
)
|
63
|
+
|
64
|
+
assert response.success?
|
65
|
+
|
66
|
+
assert_equal 3, response.rates.size
|
67
|
+
|
68
|
+
assert ground = response.rates.find { |r| r.service_code == "GD" }
|
69
|
+
assert_equal "UPS", ground.carrier
|
70
|
+
assert_equal "UPS Ground", ground.service_name
|
71
|
+
assert_equal 773, ground.total_price
|
72
|
+
assert_equal [date + 1.day, date + 7.days], ground.delivery_range
|
73
|
+
|
74
|
+
assert two_day = response.rates.find { |r| r.service_code == "2D" }
|
75
|
+
assert_equal "UPS", two_day.carrier
|
76
|
+
assert_equal "UPS Second Day Air", two_day.service_name
|
77
|
+
assert_equal 1364, two_day.total_price
|
78
|
+
assert_equal [date + 2.days, date + 2.days], two_day.delivery_range
|
79
|
+
|
80
|
+
assert one_day = response.rates.find { |r| r.service_code == "1D" }
|
81
|
+
assert_equal "USPS", one_day.carrier
|
82
|
+
assert_equal "USPS Express Mail", one_day.service_name
|
83
|
+
assert_equal 2525, one_day.total_price
|
84
|
+
assert_equal [date + 1.day, date + 1.day], one_day.delivery_range
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_gracefully_handle_new_carrier
|
89
|
+
@carrier.expects(:ssl_post).returns(xml_fixture('shipwire/new_carrier_rate_response'))
|
90
|
+
|
91
|
+
response = @carrier.find_rates(
|
92
|
+
location_fixtures[:ottawa],
|
93
|
+
location_fixtures[:beverly_hills],
|
94
|
+
package_fixtures.values_at(:book, :wii),
|
95
|
+
:order_id => '#1000',
|
96
|
+
:items => @items
|
97
|
+
)
|
98
|
+
assert response.success?
|
99
|
+
assert_equal 1, response.rates.size
|
100
|
+
assert ground = response.rates.first
|
101
|
+
assert_equal "FESCO", ground.carrier
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_find_rates_requires_items_option
|
105
|
+
assert_raises(ArgumentError) do
|
106
|
+
@carrier.find_rates(
|
107
|
+
location_fixtures[:ottawa],
|
108
|
+
location_fixtures[:beverly_hills],
|
109
|
+
package_fixtures.values_at(:book, :wii)
|
110
|
+
)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_validate_credentials_with_valid_credentials
|
115
|
+
@carrier.expects(:ssl_post).returns(xml_fixture('shipwire/no_rates_response'))
|
116
|
+
assert @carrier.valid_credentials?
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_validate_credentials_with_invalid_credentials
|
120
|
+
response = stub(:code => '401', :body => 'Could not verify Username/EmailAddress and Password combination')
|
121
|
+
|
122
|
+
@carrier.expects(:ssl_post).raises(ActiveUtils::ResponseError.new(response))
|
123
|
+
assert !@carrier.valid_credentials?
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_rate_request_includes_address_name_if_provided
|
127
|
+
name = CGI.escape("<Full>Bob Bobsen</Full>")
|
128
|
+
@carrier.expects(:ssl_post).with(anything, includes(name)).returns(xml_fixture('shipwire/rates_response'))
|
129
|
+
|
130
|
+
response = @carrier.find_rates(
|
131
|
+
location_fixtures[:ottawa],
|
132
|
+
location_fixtures[:new_york_with_name],
|
133
|
+
package_fixtures.values_at(:book, :wii),
|
134
|
+
:order_id => '#1000',
|
135
|
+
:items => @items
|
136
|
+
)
|
137
|
+
|
138
|
+
assert response.success?
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_rate_request_does_not_include_address_name_element_if_not_provided
|
142
|
+
name = CGI.escape("<Name>")
|
143
|
+
@carrier.expects(:ssl_post).with(anything, Not(regexp_matches(Regexp.new(name)))).returns(xml_fixture('shipwire/rates_response'))
|
144
|
+
|
145
|
+
response = @carrier.find_rates(
|
146
|
+
location_fixtures[:ottawa],
|
147
|
+
location_fixtures[:new_york],
|
148
|
+
package_fixtures.values_at(:book, :wii),
|
149
|
+
:order_id => '#1000',
|
150
|
+
:items => @items
|
151
|
+
)
|
152
|
+
|
153
|
+
assert response.success?
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_rate_request_without_delivery_estimate
|
157
|
+
@carrier.expects(:ssl_post).returns(xml_fixture('shipwire/rates_response_no_estimate'))
|
158
|
+
response = @carrier.find_rates(
|
159
|
+
location_fixtures[:ottawa],
|
160
|
+
location_fixtures[:new_york],
|
161
|
+
package_fixtures.values_at(:book, :wii),
|
162
|
+
:order_id => '#1000',
|
163
|
+
:items => @items
|
164
|
+
)
|
165
|
+
|
166
|
+
assert response.success?
|
167
|
+
assert_equal [], response.rates[0].delivery_range
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_rate_request_includes_company_if_provided
|
171
|
+
company = CGI.escape("<Company>Tampa Company</Company>")
|
172
|
+
@carrier.expects(:ssl_post).with(anything, includes(company)).returns(xml_fixture('shipwire/rates_response'))
|
173
|
+
|
174
|
+
response = @carrier.find_rates(
|
175
|
+
location_fixtures[:ottawa],
|
176
|
+
location_fixtures[:real_home_as_commercial],
|
177
|
+
package_fixtures.values_at(:book, :wii),
|
178
|
+
:order_id => '#1000',
|
179
|
+
:items => @items
|
180
|
+
)
|
181
|
+
|
182
|
+
assert response.success?
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_maximum_address_field_length
|
186
|
+
assert_equal 255, @carrier.maximum_address_field_length
|
187
|
+
end
|
188
|
+
end
|
@@ -0,0 +1,245 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class StampsTest < ActiveSupport::TestCase
|
4
|
+
include ReactiveShipping::Test::Fixtures
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@carrier = Stamps.new(integration_id: 'i', username: 'u', password: 'p')
|
8
|
+
@items = [{ :sku => 'AF0001', :quantity => 1 }, { :sku => 'AF0002', :quantity => 2 }]
|
9
|
+
@authentication_response = xml_fixture('stamps/authenticate_user_response')
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_authenticate_user
|
13
|
+
response_chain(xml_fixture('stamps/get_account_info_response'))
|
14
|
+
@carrier.account_info
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_account_info
|
18
|
+
response_chain(xml_fixture('stamps/get_account_info_response'))
|
19
|
+
|
20
|
+
account_info = @carrier.account_info
|
21
|
+
|
22
|
+
assert_equal 'ReactiveShipping::StampsAccountInfoResponse', account_info.class.name
|
23
|
+
|
24
|
+
assert_equal '1234567', account_info.customer_id
|
25
|
+
assert_equal '1029384756', account_info.meter_number
|
26
|
+
assert_equal '7654321', account_info.user_id
|
27
|
+
|
28
|
+
assert_equal '123.45', account_info.available_postage
|
29
|
+
assert_equal '543.21', account_info.control_total
|
30
|
+
assert_equal '250', account_info.max_postage_balance
|
31
|
+
|
32
|
+
assert_equal 'Los Angeles', account_info.lpo.city
|
33
|
+
assert_equal 'CA', account_info.lpo.state
|
34
|
+
assert_equal '90066', account_info.lpo.zip
|
35
|
+
|
36
|
+
assert_equal true, account_info.can_print_shipping?
|
37
|
+
assert_equal true, account_info.can_use_cost_codes?
|
38
|
+
assert_equal true, account_info.can_use_hidden_postage?
|
39
|
+
assert_equal true, account_info.can_purchase_sdc_insurance?
|
40
|
+
assert_equal true, account_info.can_print_memo?
|
41
|
+
assert_equal true, account_info.can_print_international?
|
42
|
+
assert_equal true, account_info.can_purchase_postage?
|
43
|
+
assert_equal true, account_info.can_edit_cost_codes?
|
44
|
+
assert_equal false, account_info.must_use_cost_codes?
|
45
|
+
assert_equal true, account_info.can_view_online_reports?
|
46
|
+
|
47
|
+
assert_equal '987.65', account_info.per_print_limit
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_purchase_postage
|
51
|
+
response_chain(xml_fixture('stamps/purchase_postage_response'))
|
52
|
+
|
53
|
+
purchase_status = @carrier.purchase_postage('543.21', '123.45')
|
54
|
+
|
55
|
+
assert_equal 'ReactiveShipping::StampsPurchasePostageResponse', purchase_status.class.name
|
56
|
+
|
57
|
+
assert_equal 'Pending', purchase_status.purchase_status
|
58
|
+
assert_equal '1234', purchase_status.transaction_id
|
59
|
+
assert_equal '543.21', purchase_status.available_postage
|
60
|
+
assert_equal '123.45', purchase_status.control_total
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_purchase_status
|
64
|
+
response_chain(xml_fixture('stamps/get_purchase_status_response'))
|
65
|
+
|
66
|
+
purchase_status = @carrier.purchase_status('1234')
|
67
|
+
|
68
|
+
assert_equal 'ReactiveShipping::StampsPurchasePostageResponse', purchase_status.class.name
|
69
|
+
|
70
|
+
assert_equal 'Success', purchase_status.purchase_status
|
71
|
+
assert_nil purchase_status.transaction_id
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_validate_address
|
75
|
+
response_chain(xml_fixture('stamps/cleanse_address_response'))
|
76
|
+
|
77
|
+
location = Location.new(
|
78
|
+
name: 'Geoff Anton',
|
79
|
+
company: 'stamps.com',
|
80
|
+
address1: '12959 Coral Tree Pl',
|
81
|
+
city: 'Los Angeles',
|
82
|
+
state: 'CA',
|
83
|
+
zip: '90066'
|
84
|
+
)
|
85
|
+
cleansed_address = @carrier.validate_address(location)
|
86
|
+
|
87
|
+
assert_equal 'ReactiveShipping::StampsCleanseAddressResponse', cleansed_address.class.name
|
88
|
+
|
89
|
+
assert_equal true, cleansed_address.address_match?
|
90
|
+
assert_equal true, cleansed_address.city_state_zip_ok?
|
91
|
+
assert_equal 'GEOFF ANTON', cleansed_address.address.name
|
92
|
+
assert_equal 'STAMPS.COM', cleansed_address.address.company
|
93
|
+
assert_equal '12959 CORAL TREE PL', cleansed_address.address.address1
|
94
|
+
assert_equal 'LOS ANGELES', cleansed_address.address.city
|
95
|
+
assert_equal 'CA', cleansed_address.address.state
|
96
|
+
assert_equal '90066-7020', cleansed_address.address.zip
|
97
|
+
assert_equal '7SWYAzuNh82cWhIQyRFXRNa71HFkZWFkYmVlZg==20100210', cleansed_address.cleanse_hash
|
98
|
+
assert_equal 'Tdwp4JlTc02DhscYxbI7l7o08apkZWFkYmVlZg==20100210', cleansed_address.override_hash
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_get_rates
|
102
|
+
response_chain(xml_fixture('stamps/get_rates_response'))
|
103
|
+
|
104
|
+
origin = Location.new(zip: '90405')
|
105
|
+
destination = Location.new(zip: '90066')
|
106
|
+
package = Package.new((12 * 16), [1, 2, 3], value: 100.00, units: :imperial)
|
107
|
+
|
108
|
+
rates = @carrier.find_rates(origin, destination, package)
|
109
|
+
|
110
|
+
assert_equal 'ReactiveShipping::RateResponse', rates.class.name
|
111
|
+
|
112
|
+
assert_equal 2, rates.rates.length
|
113
|
+
|
114
|
+
assert_equal 'ReactiveShipping::StampsRateEstimate', rates.rates[0].class.name
|
115
|
+
|
116
|
+
rate = rates.rates.first
|
117
|
+
assert_equal '90405', rate.origin.zip
|
118
|
+
assert_equal '90066', rate.destination.zip
|
119
|
+
assert_equal 'US-PM', rate.service_code
|
120
|
+
assert_equal 'USPS Priority Mail', rate.service_name
|
121
|
+
assert_equal 'USD', rate.currency
|
122
|
+
assert_equal Date.new(2014, 1, 31), rate.shipping_date
|
123
|
+
assert_equal [Date.new(2014, 2, 1), Date.new(2014, 2, 3)], rate.delivery_range
|
124
|
+
assert_equal Date.new(2014, 2, 3), rate.delivery_date
|
125
|
+
assert_equal 1217, rate.price
|
126
|
+
assert_equal 260, rate.insurance_price
|
127
|
+
assert_equal %w(US-A-SC US-A-CM), rate.add_ons['US-A-DC'][:prohibited_with]
|
128
|
+
assert_equal '2.6', rate.add_ons['SC-A-INS'][:amount]
|
129
|
+
assert_equal %w(US-A-REG US-A-INS), rate.add_ons['SC-A-INS'][:prohibited_with]
|
130
|
+
assert_equal 17, rate.available_add_ons.length
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_create_shipment
|
134
|
+
response_chain(xml_fixture('stamps/create_indicium_response'))
|
135
|
+
|
136
|
+
origin = Location.new(
|
137
|
+
name: 'Some Body',
|
138
|
+
address1: '3420 Ocean Park Bl',
|
139
|
+
address2: 'Ste 1000',
|
140
|
+
city: 'Santa Monica',
|
141
|
+
state: 'CA',
|
142
|
+
zip: '90405'
|
143
|
+
)
|
144
|
+
|
145
|
+
destination = Location.new(
|
146
|
+
name: 'GEOFF ANTON',
|
147
|
+
compnay: 'STAMPS.COM',
|
148
|
+
address1: '12959 CORAL TREE PL',
|
149
|
+
city: 'LOS ANGELES',
|
150
|
+
state: 'CA',
|
151
|
+
zip: '90066-7020'
|
152
|
+
)
|
153
|
+
|
154
|
+
package = Package.new((12 * 16), [], units: :imperial)
|
155
|
+
|
156
|
+
options = { service: 'US-PM', insured_value: 100, add_ons: %w(US-A-DC SC-A-INS)}
|
157
|
+
|
158
|
+
indicium = @carrier.create_shipment(origin, destination, package, [], options)
|
159
|
+
|
160
|
+
assert_equal 'ReactiveShipping::StampsShippingResponse', indicium.class.name
|
161
|
+
|
162
|
+
assert_equal '1234567890ABCDEF', indicium.shipping_id
|
163
|
+
assert_equal '9101010521290895036903', indicium.tracking_number
|
164
|
+
|
165
|
+
assert_equal '90405', indicium.rate.origin.zip
|
166
|
+
assert_equal '90066', indicium.rate.destination.zip
|
167
|
+
assert_equal 'US-PM', indicium.rate.service_code
|
168
|
+
assert_equal 'USPS Priority Mail', indicium.rate.service_name
|
169
|
+
assert_equal 'USD', indicium.rate.currency
|
170
|
+
assert_equal Date.new(2009, 8, 31), indicium.rate.shipping_date
|
171
|
+
assert_equal [Date.new(2009, 9, 1), Date.new(2009, 9, 3)], indicium.rate.delivery_range
|
172
|
+
assert_equal Date.new(2009, 9, 3), indicium.rate.delivery_date
|
173
|
+
assert_equal 1036, indicium.rate.price
|
174
|
+
assert_equal 185, indicium.rate.insurance_price
|
175
|
+
assert_equal Hash.new, indicium.rate.add_ons['US-A-DC']
|
176
|
+
assert_equal '1.85', indicium.rate.add_ons['SC-A-INS'][:amount]
|
177
|
+
assert_equal %w(US-A-DC SC-A-INS), indicium.rate.available_add_ons
|
178
|
+
|
179
|
+
assert_equal '0dd49299-d89c-4997-b8ac-28db5542edc9', indicium.stamps_tx_id
|
180
|
+
|
181
|
+
assert_equal '123.45', indicium.available_postage
|
182
|
+
assert_equal '543.21', indicium.control_total
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_track_shipment
|
186
|
+
response_chain(xml_fixture('stamps/track_shipment_response'))
|
187
|
+
|
188
|
+
tracking_response = @carrier.find_tracking_info('c605aec1-322e-48d5-bf81-b0bb820f9c22', stamps_tx_id: true)
|
189
|
+
|
190
|
+
assert_equal 'ReactiveShipping::TrackingResponse', tracking_response.class.name
|
191
|
+
|
192
|
+
assert_equal 3, tracking_response.shipment_events.length
|
193
|
+
|
194
|
+
assert_equal 'Electronic Notification', tracking_response.shipment_events[0].name
|
195
|
+
assert_equal '90066', tracking_response.shipment_events[0].location.zip
|
196
|
+
assert_equal 'United States', tracking_response.shipment_events[0].location.country.name
|
197
|
+
assert_equal Time.utc(2008, 2, 13, 16, 9, 0), tracking_response.shipment_events[0].time
|
198
|
+
|
199
|
+
assert_equal 'PROCESSED', tracking_response.shipment_events[1].name
|
200
|
+
assert_equal 'INDIANAPOLIS', tracking_response.shipment_events[1].location.city
|
201
|
+
assert_equal 'IN', tracking_response.shipment_events[1].location.state
|
202
|
+
assert_equal '46206', tracking_response.shipment_events[1].location.zip
|
203
|
+
assert_equal 'United States', tracking_response.shipment_events[1].location.country.name
|
204
|
+
assert_equal Time.utc(2008, 2, 15, 16, 58, 0), tracking_response.shipment_events[1].time
|
205
|
+
|
206
|
+
assert_equal 'DELIVERED', tracking_response.shipment_events[2].name
|
207
|
+
assert_equal 'FORT WAYNE', tracking_response.shipment_events[2].location.city
|
208
|
+
assert_equal 'IN', tracking_response.shipment_events[2].location.state
|
209
|
+
assert_equal '46809', tracking_response.shipment_events[2].location.zip
|
210
|
+
assert_equal 'United States', tracking_response.shipment_events[2].location.country.name
|
211
|
+
assert_equal Time.utc(2008, 2, 19, 10, 32, 0), tracking_response.shipment_events[2].time
|
212
|
+
|
213
|
+
assert_equal :delivered, tracking_response.status
|
214
|
+
assert_equal 'Delivered', tracking_response.status_code
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_authenticator_renewal
|
218
|
+
fixtures = [
|
219
|
+
@authentication_response,
|
220
|
+
xml_fixture('stamps/get_account_info_response'),
|
221
|
+
xml_fixture('stamps/expired_authenticator_response'),
|
222
|
+
@authentication_response,
|
223
|
+
xml_fixture('stamps/get_account_info_response')
|
224
|
+
]
|
225
|
+
|
226
|
+
@carrier.expects(:ssl_post).times(5).returns(*fixtures)
|
227
|
+
|
228
|
+
# The first call gets initial authenticator, second call receives
|
229
|
+
# expired authenticator
|
230
|
+
@carrier.account_info
|
231
|
+
account_info = @carrier.account_info
|
232
|
+
|
233
|
+
assert_equal 'ReactiveShipping::StampsAccountInfoResponse', account_info.class.name
|
234
|
+
end
|
235
|
+
|
236
|
+
private
|
237
|
+
|
238
|
+
def response_chain(primary_response)
|
239
|
+
@carrier.expects(:ssl_post).twice.returns(@authentication_response, primary_response)
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_maximum_address_field_length
|
243
|
+
assert_equal 255, @carrier.maximum_address_field_length
|
244
|
+
end
|
245
|
+
end
|