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,257 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class UPSTest < Minitest::Test
|
4
|
+
include ActiveShipping::Test::Credentials
|
5
|
+
include ActiveShipping::Test::Fixtures
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@options = credentials(:ups).merge(:test => true)
|
9
|
+
@carrier = UPS.new(@options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_tracking
|
13
|
+
response = @carrier.find_tracking_info('1Z12345E0291980793')
|
14
|
+
assert response.success?
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_tracking_with_bad_number
|
18
|
+
assert_raises ResponseError do
|
19
|
+
@carrier.find_tracking_info('1Z12345E029198079')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_tracking_with_another_number
|
24
|
+
response = @carrier.find_tracking_info('1Z12345E6692804405')
|
25
|
+
assert response.success?
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_us_to_uk
|
29
|
+
response = @carrier.find_rates(
|
30
|
+
location_fixtures[:beverly_hills],
|
31
|
+
location_fixtures[:london],
|
32
|
+
package_fixtures.values_at(:big_half_pound),
|
33
|
+
:test => true
|
34
|
+
)
|
35
|
+
|
36
|
+
assert response.success?
|
37
|
+
refute response.rates.empty?
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_puerto_rico
|
41
|
+
response = @carrier.find_rates(
|
42
|
+
location_fixtures[:beverly_hills],
|
43
|
+
Location.new(:city => 'Ponce', :country => 'PR', :zip => '00733-1283'),
|
44
|
+
package_fixtures.values_at(:big_half_pound),
|
45
|
+
:test => true
|
46
|
+
)
|
47
|
+
|
48
|
+
assert response.success?
|
49
|
+
refute response.rates.empty?
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_just_country_given
|
53
|
+
skip if @options[:origin_account]
|
54
|
+
|
55
|
+
response = @carrier.find_rates(
|
56
|
+
location_fixtures[:beverly_hills],
|
57
|
+
Location.new(:country => 'CA'),
|
58
|
+
Package.new(100, [5, 10, 20])
|
59
|
+
)
|
60
|
+
|
61
|
+
refute response.rates.empty?
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_just_country_given_with_origin_account_fails
|
65
|
+
skip unless @options[:origin_account]
|
66
|
+
assert_raises(ResponseError) do
|
67
|
+
@carrier.find_rates(
|
68
|
+
location_fixtures[:beverly_hills],
|
69
|
+
Location.new(:country => 'CA'),
|
70
|
+
Package.new(100, [5, 10, 20])
|
71
|
+
)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_ottawa_to_beverly_hills
|
76
|
+
response = @carrier.find_rates(
|
77
|
+
location_fixtures[:ottawa],
|
78
|
+
location_fixtures[:beverly_hills],
|
79
|
+
package_fixtures.values_at(:book, :wii),
|
80
|
+
:test => true
|
81
|
+
)
|
82
|
+
|
83
|
+
assert response.success?, response.message
|
84
|
+
assert_instance_of Hash, response.params
|
85
|
+
assert_instance_of String, response.xml
|
86
|
+
assert_instance_of Array, response.rates
|
87
|
+
refute response.rates.empty?
|
88
|
+
|
89
|
+
rate = response.rates.first
|
90
|
+
assert_equal 'UPS', rate.carrier
|
91
|
+
assert_equal 'CAD', rate.currency
|
92
|
+
if @options[:origin_account]
|
93
|
+
assert_instance_of Fixnum, rate.negotiated_rate
|
94
|
+
else
|
95
|
+
assert_equal rate.negotiated_rate, 0
|
96
|
+
end
|
97
|
+
assert_instance_of Fixnum, rate.total_price
|
98
|
+
assert_instance_of Fixnum, rate.price
|
99
|
+
assert_instance_of String, rate.service_name
|
100
|
+
assert_instance_of String, rate.service_code
|
101
|
+
assert_instance_of Array, rate.package_rates
|
102
|
+
assert_equal package_fixtures.values_at(:book, :wii), rate.packages
|
103
|
+
|
104
|
+
package_rate = rate.package_rates.first
|
105
|
+
assert_instance_of Hash, package_rate
|
106
|
+
assert_instance_of Package, package_rate[:package]
|
107
|
+
assert_nil package_rate[:rate]
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_ottawa_to_us_fails_with_only_zip_and_origin_account
|
111
|
+
skip unless @options[:origin_account]
|
112
|
+
|
113
|
+
assert_raises ResponseError do
|
114
|
+
@carrier.find_rates(
|
115
|
+
location_fixtures[:ottawa],
|
116
|
+
Location.new(:country => 'US', :zip => 90210),
|
117
|
+
package_fixtures.values_at(:book, :wii),
|
118
|
+
:test => true
|
119
|
+
)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_ottawa_to_us_fails_without_zip
|
124
|
+
assert_raises(ResponseError) do
|
125
|
+
response = @carrier.find_rates(
|
126
|
+
location_fixtures[:ottawa],
|
127
|
+
Location.new(:country => 'US'),
|
128
|
+
package_fixtures.values_at(:book, :wii),
|
129
|
+
:test => true
|
130
|
+
)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_ottawa_to_us_succeeds_with_only_zip
|
135
|
+
skip if @options[:origin_account]
|
136
|
+
|
137
|
+
response = @carrier.find_rates(
|
138
|
+
location_fixtures[:ottawa],
|
139
|
+
Location.new(:country => 'US', :zip => 90210),
|
140
|
+
package_fixtures.values_at(:book, :wii),
|
141
|
+
:test => true
|
142
|
+
)
|
143
|
+
|
144
|
+
assert response.success?, response.message
|
145
|
+
refute response.rates.empty?
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_us_to_uk_with_different_pickup_types
|
149
|
+
daily_response = @carrier.find_rates(
|
150
|
+
location_fixtures[:beverly_hills],
|
151
|
+
location_fixtures[:london],
|
152
|
+
package_fixtures.values_at(:book, :wii),
|
153
|
+
:pickup_type => :daily_pickup,
|
154
|
+
:test => true
|
155
|
+
)
|
156
|
+
one_time_response = @carrier.find_rates(
|
157
|
+
location_fixtures[:beverly_hills],
|
158
|
+
location_fixtures[:london],
|
159
|
+
package_fixtures.values_at(:book, :wii),
|
160
|
+
:pickup_type => :one_time_pickup,
|
161
|
+
:test => true
|
162
|
+
)
|
163
|
+
|
164
|
+
refute_equal daily_response.rates.map(&:price), one_time_response.rates.map(&:price)
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_bare_packages
|
168
|
+
p = Package.new(0, 0)
|
169
|
+
|
170
|
+
response = @carrier.find_rates(
|
171
|
+
location_fixtures[:beverly_hills], # imperial (U.S. origin)
|
172
|
+
location_fixtures[:ottawa],
|
173
|
+
p,
|
174
|
+
:test => true
|
175
|
+
)
|
176
|
+
|
177
|
+
assert response.success?, response.message
|
178
|
+
refute response.rates.empty?
|
179
|
+
|
180
|
+
response = @carrier.find_rates(
|
181
|
+
location_fixtures[:ottawa],
|
182
|
+
location_fixtures[:beverly_hills], # metric
|
183
|
+
p,
|
184
|
+
:test => true
|
185
|
+
)
|
186
|
+
|
187
|
+
assert response.success?, response.message
|
188
|
+
refute response.rates.empty?
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_different_rates_based_on_address_type
|
192
|
+
responses = {}
|
193
|
+
locations = [
|
194
|
+
:fake_home_as_residential, :fake_home_as_commercial,
|
195
|
+
:fake_google_as_residential, :fake_google_as_commercial
|
196
|
+
]
|
197
|
+
|
198
|
+
locations.each do |location|
|
199
|
+
responses[location] = @carrier.find_rates(
|
200
|
+
location_fixtures[:beverly_hills],
|
201
|
+
location_fixtures[location],
|
202
|
+
package_fixtures.values_at(:chocolate_stuff)
|
203
|
+
)
|
204
|
+
end
|
205
|
+
|
206
|
+
prices_of = lambda { |sym| responses[sym].rates.map(&:price) }
|
207
|
+
|
208
|
+
refute_equal prices_of.call(:fake_home_as_residential), prices_of.call(:fake_home_as_commercial)
|
209
|
+
refute_equal prices_of.call(:fake_google_as_commercial), prices_of.call(:fake_google_as_residential)
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_obtain_shipping_label
|
213
|
+
skip '<#<RuntimeError: Could not obtain shipping label. Invalid Access License number.>>.'
|
214
|
+
|
215
|
+
# I want to provide some helpful information if this test fails.
|
216
|
+
# Perhaps it is better to skip and warn than to make an *assertion*
|
217
|
+
# about configuration?
|
218
|
+
assert @options[:origin_name].present?, "test/fixtures.yml must have a valid ups/origin_name for this test to run"
|
219
|
+
assert @options[:origin_account].present?, "test/fixtures.yml must have a valid ups/origin_account for this test to run"
|
220
|
+
|
221
|
+
|
222
|
+
response = @carrier.create_shipment(
|
223
|
+
location_fixtures[:beverly_hills],
|
224
|
+
location_fixtures[:new_york_with_name],
|
225
|
+
package_fixtures.values_at(:chocolate_stuff, :book, :american_wii),
|
226
|
+
:test => true,
|
227
|
+
:reference_number => { :value => "FOO-123", :code => "PO" }
|
228
|
+
)
|
229
|
+
|
230
|
+
assert response.success?
|
231
|
+
|
232
|
+
# All behavior specific to how a LabelResponse behaves in the
|
233
|
+
# context of UPS label data is a matter for unit tests. If
|
234
|
+
# the data changes substantially, the create_shipment
|
235
|
+
# ought to raise an exception and this test will fail.
|
236
|
+
assert_instance_of ActiveShipping::LabelResponse, response
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_obtain_shipping_label_without_dimensions
|
240
|
+
skip '<#<RuntimeError: Could not obtain shipping label. Invalid Access License number.>>.'
|
241
|
+
|
242
|
+
response = @carrier.create_shipment(
|
243
|
+
location_fixtures[:beverly_hills],
|
244
|
+
location_fixtures[:new_york_with_name],
|
245
|
+
package_fixtures.values_at(:tshirts),
|
246
|
+
:test => true
|
247
|
+
)
|
248
|
+
|
249
|
+
assert response.success?
|
250
|
+
|
251
|
+
# All behavior specific to how a LabelResponse behaves in the
|
252
|
+
# context of UPS label data is a matter for unit tests. If
|
253
|
+
# the data changes substantially, the create_shipment
|
254
|
+
# ought to raise an exception and this test will fail.
|
255
|
+
assert_instance_of ActiveShipping::LabelResponse, response
|
256
|
+
end
|
257
|
+
end
|
@@ -0,0 +1,235 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class USPSTest < Minitest::Test
|
4
|
+
include ActiveShipping::Test::Credentials
|
5
|
+
include ActiveShipping::Test::Fixtures
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@carrier = USPS.new(credentials(:usps))
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_tracking
|
12
|
+
skip '<#<ActiveShipping::ResponseError: There is no record of that mail item. If it was mailed recently, it may not yet be tracked. Please try again later.>>.'
|
13
|
+
|
14
|
+
@carrier.find_tracking_info('EJ958083578US', :test => true)
|
15
|
+
assert response.success?, response.message
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_tracking_with_bad_number
|
19
|
+
assert_raises(ResponseError) do
|
20
|
+
@carrier.find_tracking_info('abc123xyz')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_zip_to_zip
|
25
|
+
response = @carrier.find_rates(
|
26
|
+
Location.new(:zip => 40524),
|
27
|
+
Location.new(:zip => 40515),
|
28
|
+
Package.new(16, [12, 6, 2], :units => :imperial)
|
29
|
+
)
|
30
|
+
|
31
|
+
assert response.success?, response.message
|
32
|
+
refute response.rates.empty?
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_just_country_given
|
36
|
+
response = @carrier.find_rates(
|
37
|
+
location_fixtures[:beverly_hills],
|
38
|
+
Location.new(:country => 'CZ'),
|
39
|
+
Package.new(100, [5, 10, 20])
|
40
|
+
)
|
41
|
+
assert response.success?, response.message
|
42
|
+
refute response.rates.empty?
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_us_to_canada
|
46
|
+
response = @carrier.find_rates(
|
47
|
+
location_fixtures[:beverly_hills],
|
48
|
+
location_fixtures[:ottawa],
|
49
|
+
package_fixtures.values_at(:american_wii),
|
50
|
+
:test => true
|
51
|
+
)
|
52
|
+
|
53
|
+
assert response.success?, response.message
|
54
|
+
refute response.rates.empty?
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_domestic_rates
|
58
|
+
response = @carrier.find_rates(
|
59
|
+
location_fixtures[:new_york],
|
60
|
+
location_fixtures[:beverly_hills],
|
61
|
+
package_fixtures.values_at(:book, :american_wii),
|
62
|
+
:test => true
|
63
|
+
)
|
64
|
+
|
65
|
+
assert response.success?, response.message
|
66
|
+
assert_instance_of Hash, response.params
|
67
|
+
assert_instance_of String, response.xml
|
68
|
+
assert_instance_of Array, response.rates
|
69
|
+
refute response.rates.empty?
|
70
|
+
|
71
|
+
rate = response.rates.first
|
72
|
+
assert_equal 'USPS', rate.carrier
|
73
|
+
assert_equal 'USD', rate.currency
|
74
|
+
assert_instance_of Fixnum, rate.total_price
|
75
|
+
assert_instance_of Fixnum, rate.price
|
76
|
+
assert_instance_of String, rate.service_name
|
77
|
+
assert_instance_of String, rate.service_code
|
78
|
+
assert_instance_of Array, rate.package_rates
|
79
|
+
assert_equal package_fixtures.values_at(:book, :american_wii), rate.packages
|
80
|
+
|
81
|
+
package_rate = rate.package_rates.first
|
82
|
+
assert_instance_of Hash, package_rate
|
83
|
+
assert_instance_of Package, package_rate[:package]
|
84
|
+
refute_nil package_rate[:rate]
|
85
|
+
|
86
|
+
other_than_two = response.rates.map(&:package_count).reject { |n| n == 2 }
|
87
|
+
assert_equal [], other_than_two, "Some RateEstimates do not refer to the right number of packages (#{other_than_two.inspect})"
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_international_rates
|
91
|
+
response = @carrier.find_rates(
|
92
|
+
location_fixtures[:beverly_hills],
|
93
|
+
location_fixtures[:ottawa],
|
94
|
+
package_fixtures.values_at(:book, :american_wii),
|
95
|
+
:test => true
|
96
|
+
)
|
97
|
+
|
98
|
+
assert response.success?, response.message
|
99
|
+
assert_instance_of Hash, response.params
|
100
|
+
assert_instance_of String, response.xml
|
101
|
+
assert_instance_of Array, response.rates
|
102
|
+
refute response.rates.empty?
|
103
|
+
|
104
|
+
rate = response.rates.first
|
105
|
+
assert_equal 'USPS', rate.carrier
|
106
|
+
assert_equal 'USD', rate.currency
|
107
|
+
assert_instance_of Fixnum, rate.total_price
|
108
|
+
assert_instance_of Fixnum, rate.price
|
109
|
+
assert_instance_of String, rate.service_name
|
110
|
+
assert_instance_of String, rate.service_code
|
111
|
+
assert_instance_of Array, rate.package_rates
|
112
|
+
assert_equal package_fixtures.values_at(:book, :american_wii), rate.packages
|
113
|
+
|
114
|
+
package_rate = rate.package_rates.first
|
115
|
+
assert_instance_of Hash, package_rate
|
116
|
+
assert_instance_of Package, package_rate[:package]
|
117
|
+
refute_nil package_rate[:rate]
|
118
|
+
|
119
|
+
other_than_two = response.rates.map(&:package_count).reject { |n| n == 2 }
|
120
|
+
assert_equal [], other_than_two, "Some RateEstimates do not refer to the right number of packages (#{other_than_two.inspect})"
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_us_to_us_possession
|
124
|
+
response = @carrier.find_rates(
|
125
|
+
location_fixtures[:beverly_hills],
|
126
|
+
location_fixtures[:puerto_rico],
|
127
|
+
package_fixtures.values_at(:american_wii),
|
128
|
+
:test => true
|
129
|
+
)
|
130
|
+
|
131
|
+
assert response.success?, response.message
|
132
|
+
refute response.rates.empty?
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_bare_packages_domestic
|
136
|
+
response = @carrier.find_rates(
|
137
|
+
location_fixtures[:beverly_hills], # imperial (U.S. origin)
|
138
|
+
location_fixtures[:new_york],
|
139
|
+
Package.new(0, 0),
|
140
|
+
:test => true
|
141
|
+
)
|
142
|
+
|
143
|
+
assert response.success?, response.message
|
144
|
+
refute response.rates.empty?
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_bare_packages_international
|
148
|
+
response = @carrier.find_rates(
|
149
|
+
location_fixtures[:beverly_hills], # imperial (U.S. origin)
|
150
|
+
location_fixtures[:ottawa],
|
151
|
+
Package.new(0, 0),
|
152
|
+
:test => true
|
153
|
+
)
|
154
|
+
|
155
|
+
assert response.success?, response.message
|
156
|
+
refute response.rates.empty?
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_first_class_packages_with_mail_type
|
160
|
+
response = @carrier.find_rates(
|
161
|
+
location_fixtures[:beverly_hills], # imperial (U.S. origin)
|
162
|
+
location_fixtures[:new_york],
|
163
|
+
Package.new(0, 0),
|
164
|
+
|
165
|
+
:test => true,
|
166
|
+
:service => :first_class,
|
167
|
+
:first_class_mail_type => :parcel
|
168
|
+
)
|
169
|
+
|
170
|
+
assert response.success?, response.message
|
171
|
+
refute response.rates.empty?
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_first_class_packages_without_mail_type
|
175
|
+
assert_raises(ResponseError, "Invalid First Class Mail Type.") do
|
176
|
+
@carrier.find_rates(
|
177
|
+
location_fixtures[:beverly_hills], # imperial (U.S. origin)
|
178
|
+
location_fixtures[:new_york],
|
179
|
+
Package.new(0, 0),
|
180
|
+
|
181
|
+
:test => true,
|
182
|
+
:service => :first_class
|
183
|
+
)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_first_class_packages_with_invalid_mail_type
|
188
|
+
assert_raises(ResponseError, "Invalid First Class Mail Type.") do
|
189
|
+
@carrier.find_rates(
|
190
|
+
location_fixtures[:beverly_hills], # imperial (U.S. origin)
|
191
|
+
location_fixtures[:new_york],
|
192
|
+
Package.new(0, 0),
|
193
|
+
|
194
|
+
:test => true,
|
195
|
+
:service => :first_class,
|
196
|
+
:first_class_mail_tpe => :invalid
|
197
|
+
)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_valid_credentials
|
202
|
+
assert USPS.new(credentials(:usps).merge(:test => true)).valid_credentials?
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_must_provide_login_creds_when_instantiating
|
206
|
+
assert_raises ArgumentError do
|
207
|
+
USPS.new(:test => true)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
# Uncomment and switch out SPECIAL_COUNTRIES with some other batch to see which
|
212
|
+
# countries are currently working. Commented out here just because it's a lot of
|
213
|
+
# hits to their server at once:
|
214
|
+
|
215
|
+
# ALL_COUNTRIES = ActiveUtils::Country.const_get('COUNTRIES').map {|c| c[:alpha2]}
|
216
|
+
# SPECIAL_COUNTRIES = USPS.const_get('COUNTRY_NAME_CONVERSIONS').keys.sort
|
217
|
+
# NORMAL_COUNTRIES = (ALL_COUNTRIES - SPECIAL_COUNTRIES)
|
218
|
+
#
|
219
|
+
# SPECIAL_COUNTRIES.each do |code|
|
220
|
+
# unless ActiveUtils::Country.find(code).name == USPS.const_get('COUNTRY_NAME_CONVERSIONS')[code]
|
221
|
+
# define_method("test_country_#{code}") do
|
222
|
+
# response = nil
|
223
|
+
# begin
|
224
|
+
# response = @carrier.find_rates( location_fixtures[:beverly_hills],
|
225
|
+
# Location.new(:country => code),
|
226
|
+
# package_fixtures.values_at(:american_wii),
|
227
|
+
# :test => true)
|
228
|
+
# rescue Exception => e
|
229
|
+
# flunk(e.inspect + "\nrequest: " + @carrier.last_request)
|
230
|
+
# end
|
231
|
+
# assert_not_equal [], response.rates.length
|
232
|
+
# end
|
233
|
+
# end
|
234
|
+
# end
|
235
|
+
end
|