active_shipping 1.0.0.pre2 → 1.0.0.pre3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.gitignore +12 -0
- data/.travis.yml +14 -0
- data/.yardopts +14 -0
- data/Gemfile +3 -0
- data/Gemfile.activesupport32 +4 -0
- data/Gemfile.activesupport40 +4 -0
- data/Gemfile.activesupport41 +4 -0
- data/Gemfile.activesupport42 +4 -0
- data/Rakefile +23 -0
- data/active_shipping.gemspec +32 -0
- data/lib/active_shipping.rb +1 -1
- data/lib/active_shipping/carrier.rb +1 -1
- data/lib/active_shipping/carriers/shipwire.rb +32 -35
- data/lib/active_shipping/carriers/ups.rb +2 -2
- data/lib/active_shipping/carriers/usps.rb +103 -101
- data/lib/active_shipping/label_response.rb +1 -1
- data/lib/active_shipping/rate_estimate.rb +76 -15
- data/lib/active_shipping/rate_response.rb +20 -0
- data/lib/active_shipping/response.rb +17 -0
- data/lib/active_shipping/shipment_packer.rb +2 -2
- data/lib/active_shipping/shipping_response.rb +24 -2
- data/lib/active_shipping/tracking_response.rb +65 -17
- data/lib/active_shipping/version.rb +1 -1
- data/shipit.rubygems.yml +1 -0
- data/test/credentials.yml +47 -0
- data/test/fixtures/files/label1.pdf +0 -0
- data/test/fixtures/files/ups-shipping-label.gif +0 -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/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_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/reply_without_notifications.xml +185 -0
- data/test/fixtures/xml/fedex/tracking_request.xml +27 -0
- data/test/fixtures/xml/fedex/tracking_response.xml +151 -0
- data/test/fixtures/xml/fedex/tracking_response_empty_destination.xml +76 -0
- data/test/fixtures/xml/fedex/tracking_response_no_destination.xml +139 -0
- data/test/fixtures/xml/fedex/tracking_response_no_ship_time.xml +150 -0
- data/test/fixtures/xml/fedex/tracking_response_with_estimated_delivery_date.xml +95 -0
- data/test/fixtures/xml/fedex/tracking_response_with_shipper_address.xml +71 -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/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/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/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 +1 -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/triple_accept_response.xml +72 -0
- data/test/fixtures/xml/ups/triple_confirm_response.xml +32 -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/delivered_tracking_response.xml +11 -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_tracking_response_error.xml +2 -0
- data/test/fixtures/xml/usps/tracking_request.xml +3 -0
- data/test/fixtures/xml/usps/tracking_response.xml +13 -0
- data/test/fixtures/xml/usps/tracking_response_failure.xml +3 -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/world_rate_request_with_value.xml +20 -0
- data/test/fixtures/xml/usps/world_rate_request_without_value.xml +20 -0
- data/test/remote/canada_post_pws_platform_test.rb +246 -0
- data/test/remote/canada_post_pws_test.rb +171 -0
- data/test/remote/canada_post_test.rb +53 -0
- data/test/remote/fedex_test.rb +216 -0
- data/test/remote/kunaki_test.rb +36 -0
- data/test/remote/new_zealand_post_test.rb +147 -0
- data/test/remote/shipwire_test.rb +82 -0
- data/test/remote/stamps_test.rb +394 -0
- data/test/remote/ups_test.rb +257 -0
- data/test/remote/usps_test.rb +235 -0
- data/test/test_helper.rb +220 -0
- data/test/unit/carriers/benchmark_test.rb +18 -0
- data/test/unit/carriers/canada_post_pws_rating_test.rb +349 -0
- data/test/unit/carriers/canada_post_pws_register_test.rb +75 -0
- data/test/unit/carriers/canada_post_pws_shipping_test.rb +244 -0
- data/test/unit/carriers/canada_post_pws_tracking_test.rb +154 -0
- data/test/unit/carriers/canada_post_test.rb +145 -0
- data/test/unit/carriers/fedex_test.rb +408 -0
- data/test/unit/carriers/kunaki_test.rb +52 -0
- data/test/unit/carriers/new_zealand_post_test.rb +174 -0
- data/test/unit/carriers/shipwire_test.rb +187 -0
- data/test/unit/carriers/stamps_test.rb +241 -0
- data/test/unit/carriers/ups_test.rb +311 -0
- data/test/unit/carriers/usps_test.rb +484 -0
- data/test/unit/carriers_test.rb +17 -0
- data/test/unit/label_response_test.rb +15 -0
- data/test/unit/location_test.rb +138 -0
- data/test/unit/package_test.rb +68 -0
- data/test/unit/rate_estimate_test.rb +34 -0
- data/test/unit/response_test.rb +14 -0
- data/test/unit/shipment_packer_test.rb +174 -0
- metadata +331 -35
- metadata.gz.sig +0 -0
- data/lib/vendor/quantified/MIT-LICENSE +0 -22
- data/lib/vendor/quantified/README.markdown +0 -49
- data/lib/vendor/quantified/Rakefile +0 -13
- data/lib/vendor/quantified/init.rb +0 -0
- data/lib/vendor/quantified/lib/quantified.rb +0 -6
- data/lib/vendor/quantified/lib/quantified/attribute.rb +0 -211
- data/lib/vendor/quantified/lib/quantified/length.rb +0 -20
- data/lib/vendor/quantified/lib/quantified/mass.rb +0 -19
- data/lib/vendor/quantified/test/length_test.rb +0 -94
- data/lib/vendor/quantified/test/mass_test.rb +0 -96
- data/lib/vendor/quantified/test/test_helper.rb +0 -19
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class KunakiTest < Minitest::Test
|
4
|
+
include ActiveShipping::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_equal 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
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class NewZealandPostTest < Minitest::Test
|
4
|
+
include ActiveShipping::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&length=190&postcode_dest=1010&postcode_src=6011&thickness=140&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&format=json&length=930&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&length=190&postcode_dest=1010&postcode_src=6011&thickness=140&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 ActiveShipping::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&length=0&postcode_dest=1010&postcode_src=6011&thickness=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&length=190&postcode_dest=1010&postcode_src=6011&thickness=140&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&length=190&thickness=140&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&length=190&thickness=140&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&length=190&thickness=140&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 ActiveShipping::ResponseError, error.class
|
148
|
+
assert_equal "A JSON text must at least contain two octets!", error.message
|
149
|
+
assert_equal [""], error.response.raw_responses
|
150
|
+
response_params = { "responses" => [] }
|
151
|
+
assert_equal response_params, error.response.params
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_international_invalid_json_response_error
|
155
|
+
@carrier.expects(:commit).returns(["<>"])
|
156
|
+
error = @carrier.find_rates(@wellington, @ottawa, package_fixtures[:book]) rescue $!
|
157
|
+
assert_equal ActiveShipping::ResponseError, error.class
|
158
|
+
assert error.message.include?("unexpected token")
|
159
|
+
assert_equal ["<>"], error.response.raw_responses
|
160
|
+
response_params = { "responses" => [] }
|
161
|
+
assert_equal response_params, error.response.params
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_international_invalid_origin_country_response
|
165
|
+
error = @carrier.find_rates(@ottawa, @wellington, package_fixtures[:book]) rescue $!
|
166
|
+
assert_equal ActiveShipping::ResponseError, error.class
|
167
|
+
assert_equal "New Zealand Post packages must originate in New Zealand", error.message
|
168
|
+
assert_equal [], error.response.raw_responses
|
169
|
+
assert_equal Array, error.response.request.class
|
170
|
+
assert_equal 1, error.response.request.size
|
171
|
+
response_params = { "responses" => [] }
|
172
|
+
assert_equal response_params, error.response.params
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ShipwireTest < Minitest::Test
|
4
|
+
include ActiveShipping::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.new(2011, 8, 1)
|
27
|
+
DateTime.expects(:now).returns(date).at_least_once
|
28
|
+
@carrier.expects(:ssl_post).returns(xml_fixture('shipwire/international_rates_response'))
|
29
|
+
|
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 + 7, international.delivery_date
|
48
|
+
assert_equal [date + 1, date + 7], international.delivery_range
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_successfully_get_domestic_rates
|
52
|
+
date = DateTime.new(2011, 8, 1)
|
53
|
+
DateTime.expects(:now).returns(date).at_least_once
|
54
|
+
@carrier.expects(:ssl_post).returns(xml_fixture('shipwire/rates_response'))
|
55
|
+
|
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 + 7, ground.delivery_date
|
73
|
+
assert_equal [date + 1, date + 7], ground.delivery_range
|
74
|
+
|
75
|
+
assert two_day = response.rates.find { |r| r.service_code == "2D" }
|
76
|
+
assert_equal "UPS", two_day.carrier
|
77
|
+
assert_equal "UPS Second Day Air", two_day.service_name
|
78
|
+
assert_equal 1364, two_day.total_price
|
79
|
+
assert_equal date + 2, two_day.delivery_date
|
80
|
+
assert_equal [date + 2, date + 2], two_day.delivery_range
|
81
|
+
|
82
|
+
assert one_day = response.rates.find { |r| r.service_code == "1D" }
|
83
|
+
assert_equal "USPS", one_day.carrier
|
84
|
+
assert_equal "USPS Express Mail", one_day.service_name
|
85
|
+
assert_equal 2525, one_day.total_price
|
86
|
+
assert_equal date + 1, one_day.delivery_date
|
87
|
+
assert_equal [date + 1, date + 1], one_day.delivery_range
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_gracefully_handle_new_carrier
|
91
|
+
@carrier.expects(:ssl_post).returns(xml_fixture('shipwire/new_carrier_rate_response'))
|
92
|
+
|
93
|
+
response = @carrier.find_rates(
|
94
|
+
location_fixtures[:ottawa],
|
95
|
+
location_fixtures[:beverly_hills],
|
96
|
+
package_fixtures.values_at(:book, :wii),
|
97
|
+
:order_id => '#1000',
|
98
|
+
:items => @items
|
99
|
+
)
|
100
|
+
assert response.success?
|
101
|
+
assert_equal 1, response.rates.size
|
102
|
+
assert ground = response.rates.first
|
103
|
+
assert_equal "FESCO", ground.carrier
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_find_rates_requires_items_option
|
107
|
+
assert_raises(ArgumentError) do
|
108
|
+
@carrier.find_rates(
|
109
|
+
location_fixtures[:ottawa],
|
110
|
+
location_fixtures[:beverly_hills],
|
111
|
+
package_fixtures.values_at(:book, :wii)
|
112
|
+
)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_validate_credentials_with_valid_credentials
|
117
|
+
@carrier.expects(:ssl_post).returns(xml_fixture('shipwire/no_rates_response'))
|
118
|
+
assert @carrier.valid_credentials?
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_validate_credentials_with_invalid_credentials
|
122
|
+
response = stub(:code => '401', :body => 'Could not verify Username/EmailAddress and Password combination')
|
123
|
+
|
124
|
+
@carrier.expects(:ssl_post).raises(ActiveUtils::ResponseError.new(response))
|
125
|
+
assert !@carrier.valid_credentials?
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_rate_request_includes_address_name_if_provided
|
129
|
+
name = CGI.escape("<Full>Bob Bobsen</Full>")
|
130
|
+
@carrier.expects(:ssl_post).with(anything, includes(name)).returns(xml_fixture('shipwire/rates_response'))
|
131
|
+
|
132
|
+
response = @carrier.find_rates(
|
133
|
+
location_fixtures[:ottawa],
|
134
|
+
location_fixtures[:new_york_with_name],
|
135
|
+
package_fixtures.values_at(:book, :wii),
|
136
|
+
:order_id => '#1000',
|
137
|
+
:items => @items
|
138
|
+
)
|
139
|
+
|
140
|
+
assert response.success?
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_rate_request_does_not_include_address_name_element_if_not_provided
|
144
|
+
name = CGI.escape("<Name>")
|
145
|
+
@carrier.expects(:ssl_post).with(anything, Not(regexp_matches(Regexp.new(name)))).returns(xml_fixture('shipwire/rates_response'))
|
146
|
+
|
147
|
+
response = @carrier.find_rates(
|
148
|
+
location_fixtures[:ottawa],
|
149
|
+
location_fixtures[:new_york],
|
150
|
+
package_fixtures.values_at(:book, :wii),
|
151
|
+
:order_id => '#1000',
|
152
|
+
:items => @items
|
153
|
+
)
|
154
|
+
|
155
|
+
assert response.success?
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_rate_request_without_delivery_estimate
|
159
|
+
@carrier.expects(:ssl_post).returns(xml_fixture('shipwire/rates_response_no_estimate'))
|
160
|
+
response = @carrier.find_rates(
|
161
|
+
location_fixtures[:ottawa],
|
162
|
+
location_fixtures[:new_york],
|
163
|
+
package_fixtures.values_at(:book, :wii),
|
164
|
+
:order_id => '#1000',
|
165
|
+
:items => @items
|
166
|
+
)
|
167
|
+
|
168
|
+
assert response.success?
|
169
|
+
assert_equal [], response.rates[0].delivery_range
|
170
|
+
assert_nil response.rates[0].delivery_date
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_rate_request_includes_company_if_provided
|
174
|
+
company = CGI.escape("<Company>Tampa Company</Company>")
|
175
|
+
@carrier.expects(:ssl_post).with(anything, includes(company)).returns(xml_fixture('shipwire/rates_response'))
|
176
|
+
|
177
|
+
response = @carrier.find_rates(
|
178
|
+
location_fixtures[:ottawa],
|
179
|
+
location_fixtures[:real_home_as_commercial],
|
180
|
+
package_fixtures.values_at(:book, :wii),
|
181
|
+
:order_id => '#1000',
|
182
|
+
:items => @items
|
183
|
+
)
|
184
|
+
|
185
|
+
assert response.success?
|
186
|
+
end
|
187
|
+
end
|
@@ -0,0 +1,241 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class StampsTest < Minitest::Test
|
4
|
+
include ActiveShipping::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 'ActiveShipping::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 'ActiveShipping::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 'ActiveShipping::StampsPurchasePostageResponse', purchase_status.class.name
|
69
|
+
|
70
|
+
assert_equal 'Success', purchase_status.purchase_status
|
71
|
+
assert_equal 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 'ActiveShipping::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 'ActiveShipping::RateResponse', rates.class.name
|
111
|
+
|
112
|
+
assert_equal 2, rates.rates.length
|
113
|
+
|
114
|
+
assert_equal 'ActiveShipping::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 'ActiveShipping::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 'ActiveShipping::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 'ActiveShipping::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
|
+
end
|