active_shipping 1.0.0.pre4 → 1.0.0
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/.yardopts +0 -1
- data/CHANGELOG.md +17 -0
- data/CONTRIBUTING.md +2 -2
- data/Gemfile.activesupport32 +1 -0
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/active_shipping.gemspec +2 -2
- data/lib/active_shipping.rb +2 -3
- data/lib/active_shipping/carriers.rb +1 -0
- data/lib/active_shipping/carriers/canada_post_pws.rb +281 -266
- data/lib/active_shipping/carriers/correios.rb +285 -0
- data/lib/active_shipping/carriers/fedex.rb +205 -199
- data/lib/active_shipping/carriers/stamps.rb +218 -219
- data/lib/active_shipping/carriers/ups.rb +287 -48
- data/lib/active_shipping/carriers/usps.rb +3 -3
- data/lib/active_shipping/delivery_date_estimate.rb +21 -0
- data/lib/active_shipping/delivery_date_estimates_response.rb +11 -0
- data/lib/active_shipping/errors.rb +20 -1
- data/lib/active_shipping/location.rb +0 -5
- data/lib/active_shipping/response.rb +0 -15
- data/lib/active_shipping/version.rb +1 -1
- data/test/credentials.yml +11 -3
- data/test/fixtures/xml/correios/book_response.xml +13 -0
- data/test/fixtures/xml/correios/book_response_invalid.xml +13 -0
- data/test/fixtures/xml/correios/clothes_response.xml +43 -0
- data/test/fixtures/xml/correios/poster_response.xml +23 -0
- data/test/fixtures/xml/correios/shoes_response.xml +43 -0
- data/test/fixtures/xml/fedex/tracking_request.xml +13 -11
- 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_in_transit.xml +127 -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/ups/delivery_dates_response.xml +140 -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/test_real_home_as_residential_destination_response.xml +290 -1
- data/test/fixtures/xml/usps/delivered_extended_tracking_response.xml +11 -0
- data/test/remote/canada_post_pws_platform_test.rb +35 -22
- data/test/remote/canada_post_pws_test.rb +32 -40
- data/test/remote/correios_test.rb +83 -0
- data/test/remote/fedex_test.rb +95 -13
- data/test/remote/stamps_test.rb +1 -0
- data/test/remote/ups_test.rb +77 -40
- data/test/remote/usps_test.rb +13 -1
- data/test/test_helper.rb +12 -2
- data/test/unit/carriers/canada_post_pws_rating_test.rb +66 -59
- data/test/unit/carriers/canada_post_pws_shipping_test.rb +34 -23
- data/test/unit/carriers/correios_test.rb +244 -0
- data/test/unit/carriers/fedex_test.rb +161 -156
- data/test/unit/carriers/ups_test.rb +193 -1
- data/test/unit/carriers/usps_test.rb +14 -0
- data/test/unit/location_test.rb +0 -10
- metadata +63 -46
- metadata.gz.sig +0 -0
- data/lib/vendor/test_helper.rb +0 -6
- data/lib/vendor/xml_node/README +0 -36
- data/lib/vendor/xml_node/Rakefile +0 -21
- data/lib/vendor/xml_node/benchmark/bench_generation.rb +0 -30
- data/lib/vendor/xml_node/init.rb +0 -1
- data/lib/vendor/xml_node/lib/xml_node.rb +0 -221
- data/lib/vendor/xml_node/test/test_generating.rb +0 -89
- data/lib/vendor/xml_node/test/test_parsing.rb +0 -40
- data/test/fixtures/xml/fedex/tracking_response.xml +0 -151
- data/test/fixtures/xml/fedex/tracking_response_empty_destination.xml +0 -76
- data/test/fixtures/xml/fedex/tracking_response_no_destination.xml +0 -139
- data/test/fixtures/xml/fedex/tracking_response_no_ship_time.xml +0 -150
- data/test/fixtures/xml/fedex/tracking_response_with_estimated_delivery_date.xml +0 -95
- data/test/fixtures/xml/fedex/tracking_response_with_shipper_address.xml +0 -71
@@ -76,13 +76,15 @@ class CanadaPostPwsShippingTest < Minitest::Test
|
|
76
76
|
def test_build_shipment_customs_node
|
77
77
|
options = @default_options.dup
|
78
78
|
destination = Location.new(@us_params)
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
assert
|
84
|
-
assert_equal
|
85
|
-
|
79
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
80
|
+
response = @cp.shipment_customs_node(xml, destination, @line_item1, options)
|
81
|
+
end
|
82
|
+
doc = builder.doc
|
83
|
+
assert root_node = doc.at('customs')
|
84
|
+
assert_equal "CAD", root_node.at('currency').text
|
85
|
+
assert items_node = root_node.at('sku-list')
|
86
|
+
assert_equal 2, items_node.xpath('item').size
|
87
|
+
assert_equal 199.0, items_node.at('item/customs-value-per-unit').text.to_f
|
86
88
|
end
|
87
89
|
|
88
90
|
def test_build_shipment_request_for_domestic
|
@@ -95,12 +97,15 @@ class CanadaPostPwsShippingTest < Minitest::Test
|
|
95
97
|
options = @default_options.dup
|
96
98
|
request = @cp.build_shipment_request(@home_params, @us_params, @pkg1, @line_item1, options)
|
97
99
|
refute request.blank?
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
assert
|
103
|
-
|
100
|
+
|
101
|
+
doc = Nokogiri.XML(request)
|
102
|
+
doc.remove_namespaces!
|
103
|
+
|
104
|
+
assert root_node = doc.at('non-contract-shipment')
|
105
|
+
assert delivery_spec = root_node.at('delivery-spec')
|
106
|
+
assert destination = delivery_spec.at('destination')
|
107
|
+
assert address_details = destination.at('address-details')
|
108
|
+
assert_equal 'US', address_details.at('country-code').text
|
104
109
|
end
|
105
110
|
|
106
111
|
def test_build_shipment_request_for_international
|
@@ -119,11 +124,14 @@ class CanadaPostPwsShippingTest < Minitest::Test
|
|
119
124
|
options = @default_options.merge(@shipping_opts1)
|
120
125
|
request = @cp.build_shipment_request(@home_params, @paris_params, @pkg1, @line_item1, options)
|
121
126
|
refute request.blank?
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
+
|
128
|
+
doc = Nokogiri.XML(request)
|
129
|
+
doc.remove_namespaces!
|
130
|
+
|
131
|
+
assert root_node = doc.at('non-contract-shipment')
|
132
|
+
assert delivery_spec = root_node.at('delivery-spec')
|
133
|
+
assert options = delivery_spec.at('options')
|
134
|
+
assert_equal 5, options.xpath('*').size
|
127
135
|
end
|
128
136
|
|
129
137
|
def test_build_shipping_request_with_zero_weight
|
@@ -131,11 +139,14 @@ class CanadaPostPwsShippingTest < Minitest::Test
|
|
131
139
|
package = Package.new(0, [93, 10])
|
132
140
|
request = @cp.build_shipment_request(@home_params, @dom_params, package, @line_item1, options)
|
133
141
|
refute request.blank?
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
142
|
+
|
143
|
+
doc = Nokogiri.XML(request)
|
144
|
+
doc.remove_namespaces!
|
145
|
+
|
146
|
+
assert root_node = doc.at('non-contract-shipment')
|
147
|
+
assert delivery_spec = root_node.at('delivery-spec')
|
148
|
+
assert parcel_node = delivery_spec.at('parcel-characteristics')
|
149
|
+
assert_equal '0.001', parcel_node.at('weight').text
|
139
150
|
end
|
140
151
|
|
141
152
|
def test_create_shipment_domestic
|
@@ -0,0 +1,244 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class CorreiosTest < Minitest::Test
|
4
|
+
include ActiveShipping::Test::Fixtures
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@carrier = Correios.new
|
8
|
+
|
9
|
+
@saopaulo = Location.new(:zip => "01415000")
|
10
|
+
@patosdeminas = Location.new(:zip => "38700000")
|
11
|
+
|
12
|
+
@book = package_fixtures[:book]
|
13
|
+
@poster = package_fixtures[:poster]
|
14
|
+
|
15
|
+
@response_clothes = xml_fixture('correios/clothes_response')
|
16
|
+
@response_shoes = xml_fixture('correios/shoes_response')
|
17
|
+
@response_book_success = xml_fixture('correios/book_response')
|
18
|
+
@response_poster_success = xml_fixture('correios/poster_response')
|
19
|
+
@response_book_invalid = xml_fixture('correios/book_response_invalid')
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_book_request
|
23
|
+
@carrier.expects(:perform).returns([@response_book_success])
|
24
|
+
response = @carrier.find_rates(@saopaulo, @patosdeminas, [@book])
|
25
|
+
|
26
|
+
[
|
27
|
+
"sCepOrigem=01415000",
|
28
|
+
"sCepDestino=38700000",
|
29
|
+
"nVlPeso=0.25",
|
30
|
+
"nCdFormato=1",
|
31
|
+
"nVlComprimento=19",
|
32
|
+
"nVlAltura=2",
|
33
|
+
"nVlLargura=14",
|
34
|
+
"nVlDiametro=0"
|
35
|
+
].each do |query_param|
|
36
|
+
assert_match query_param, response.urls.first
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_poster_request
|
41
|
+
@carrier.expects(:perform).returns([@response_poster_success])
|
42
|
+
response = @carrier.find_rates(@saopaulo, @patosdeminas, [@poster])
|
43
|
+
|
44
|
+
[
|
45
|
+
"sCepOrigem=01415000",
|
46
|
+
"sCepDestino=38700000",
|
47
|
+
"nVlPeso=0.1",
|
48
|
+
"nCdFormato=1",
|
49
|
+
"nVlComprimento=93",
|
50
|
+
"nVlAltura=10",
|
51
|
+
"nVlLargura=10",
|
52
|
+
"nVlDiametro=10"
|
53
|
+
].each do |query_param|
|
54
|
+
assert_match query_param, response.urls.first
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_poster_and_book_request
|
59
|
+
@carrier.expects(:perform).returns([@response_poster_success, @response_book_success])
|
60
|
+
response = @carrier.find_rates(@saopaulo, @patosdeminas, [@poster, @book])
|
61
|
+
|
62
|
+
[
|
63
|
+
"sCepOrigem=01415000",
|
64
|
+
"sCepDestino=38700000",
|
65
|
+
"nVlPeso=0.1",
|
66
|
+
"nCdFormato=1",
|
67
|
+
"nVlComprimento=93",
|
68
|
+
"nVlAltura=10",
|
69
|
+
"nVlLargura=10",
|
70
|
+
"nVlDiametro=10"
|
71
|
+
].each do |query_param|
|
72
|
+
assert_match query_param, response.urls.first
|
73
|
+
end
|
74
|
+
|
75
|
+
[
|
76
|
+
"sCepOrigem=01415000",
|
77
|
+
"sCepDestino=38700000",
|
78
|
+
"nVlPeso=0.25",
|
79
|
+
"nCdFormato=1",
|
80
|
+
"nVlComprimento=19",
|
81
|
+
"nVlAltura=2",
|
82
|
+
"nVlLargura=14",
|
83
|
+
"nVlDiametro=0"
|
84
|
+
].each do |query_param|
|
85
|
+
assert_match query_param, response.urls.last
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_book_request_with_specific_services
|
90
|
+
@carrier.expects(:perform).returns([@response_book_success])
|
91
|
+
response = @carrier.find_rates(@saopaulo, @patosdeminas, [@book], :services => [41106, 40010, 40215])
|
92
|
+
|
93
|
+
[
|
94
|
+
"nCdServico=41106%2C40010%2C40215",
|
95
|
+
"sCepOrigem=01415000",
|
96
|
+
"sCepDestino=38700000",
|
97
|
+
"nVlPeso=0.25",
|
98
|
+
"nCdFormato=1",
|
99
|
+
"nVlComprimento=19",
|
100
|
+
"nVlAltura=2",
|
101
|
+
"nVlLargura=14",
|
102
|
+
"nVlDiametro=0"
|
103
|
+
].each do |query_param|
|
104
|
+
assert_match query_param, response.urls.first
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_book_request_with_option_params
|
109
|
+
options = {
|
110
|
+
:company_id => 1010,
|
111
|
+
:password => 123123,
|
112
|
+
:declared_value_extra => 10.50,
|
113
|
+
:delivery_notice_extra => true,
|
114
|
+
:mao_propria_extra => true
|
115
|
+
}
|
116
|
+
|
117
|
+
@carrier.expects(:perform).returns([@response_book_success])
|
118
|
+
response = @carrier.find_rates(@saopaulo, @patosdeminas, [@book], options)
|
119
|
+
|
120
|
+
[
|
121
|
+
"nCdEmpresa=1010",
|
122
|
+
"sDsSenha=123123",
|
123
|
+
"sCdMaoPropria=S",
|
124
|
+
"nVlValorDeclarado=10%2C5",
|
125
|
+
"sCdAvisoRecebimento=S",
|
126
|
+
"nCdServico=41106%2C40010",
|
127
|
+
"sCepOrigem=01415000",
|
128
|
+
"sCepDestino=38700000",
|
129
|
+
"nVlPeso=0.25",
|
130
|
+
"nCdFormato=1",
|
131
|
+
"nVlComprimento=19",
|
132
|
+
"nVlAltura=2",
|
133
|
+
"nVlLargura=14",
|
134
|
+
"nVlDiametro=0"
|
135
|
+
].each do |query_param|
|
136
|
+
assert_match query_param, response.urls.first
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_book_response
|
142
|
+
@carrier.stubs(:perform).returns([@response_book_success])
|
143
|
+
response = @carrier.find_rates(@saopaulo, @patosdeminas, [@book])
|
144
|
+
|
145
|
+
assert_equal 1, response.rates.size
|
146
|
+
assert_equal [10520], response.rates.map(&:price)
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_poster_response
|
150
|
+
@carrier.stubs(:perform).returns([@response_poster_success])
|
151
|
+
response = @carrier.find_rates(@saopaulo, @patosdeminas, [@poster])
|
152
|
+
|
153
|
+
assert_equal 2, response.rates.size
|
154
|
+
assert_equal [1000, 2000], response.rates.map(&:price)
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_two_books_response
|
158
|
+
@carrier.stubs(:perform).returns([@response_book_success, @response_book_success])
|
159
|
+
response = @carrier.find_rates(@saopaulo, @patosdeminas, [@book, @book])
|
160
|
+
|
161
|
+
assert_equal 1, response.rates.size
|
162
|
+
assert_equal [21040], response.rates.map(&:price)
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_two_posters_response
|
166
|
+
@carrier.stubs(:perform).returns([@response_poster_success, @response_poster_success])
|
167
|
+
response = @carrier.find_rates(@saopaulo, @patosdeminas, [@poster, @poster])
|
168
|
+
|
169
|
+
assert_equal 2, response.rates.size
|
170
|
+
assert_equal [2000, 4000], response.rates.map(&:price)
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_response_parsing
|
174
|
+
@carrier.stubs(:perform).returns([@response_clothes, @response_shoes])
|
175
|
+
response = @carrier.find_rates(@saopaulo, @patosdeminas, [@book, @book])
|
176
|
+
service_codes = [41106, 41300, 40215, 81019]
|
177
|
+
service_names = [
|
178
|
+
'PAC sem contrato',
|
179
|
+
'PAC para grandes formatos',
|
180
|
+
'SEDEX 10, sem contrato',
|
181
|
+
'e-SEDEX, com contrato'
|
182
|
+
]
|
183
|
+
|
184
|
+
assert_equal service_codes, response.rates.map(&:service_code)
|
185
|
+
assert_equal service_names, response.rates.map(&:service_name)
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_response_params_options
|
189
|
+
@carrier.stubs(:perform).returns([@response_book_success])
|
190
|
+
response = @carrier.find_rates(@saopaulo, @patosdeminas, [@book])
|
191
|
+
|
192
|
+
assert_equal [Nokogiri::XML::Document], response.params['responses'].map(&:class)
|
193
|
+
assert_equal [Nokogiri::XML(@response_book_success).to_xml], response.params['responses'].map(&:to_xml)
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_book_invalid_response
|
197
|
+
error = assert_raises(ActiveShipping::ResponseError) do
|
198
|
+
@carrier.stubs(:perform).returns([@response_book_invalid])
|
199
|
+
@carrier.find_rates(@saopaulo, @patosdeminas, [@book])
|
200
|
+
end
|
201
|
+
|
202
|
+
assert_equal "CEP de origem invalido", error.message
|
203
|
+
assert_equal error.response.raw_responses, [@response_book_invalid]
|
204
|
+
assert_equal Hash.new, error.response.params
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_valid_book_and_invalid_book_response
|
208
|
+
error = assert_raises(ActiveShipping::ResponseError) do
|
209
|
+
@carrier.stubs(:perform).returns([@response_book_success, @response_book_invalid])
|
210
|
+
@carrier.find_rates(@saopaulo, @patosdeminas, [@book, @book])
|
211
|
+
end
|
212
|
+
|
213
|
+
assert_equal "CEP de origem invalido", error.message
|
214
|
+
assert_equal error.response.raw_responses, [@response_book_success, @response_book_invalid]
|
215
|
+
assert_equal Hash.new, error.response.params
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_show_available_services
|
219
|
+
services = Correios.available_services
|
220
|
+
|
221
|
+
assert_kind_of Hash, services
|
222
|
+
assert_equal 19, services.size
|
223
|
+
assert_equal 'PAC sem contrato', services[41106]
|
224
|
+
assert_equal 'PAC com contrato', services[41068]
|
225
|
+
assert_equal 'PAC para grandes formatos', services[41300]
|
226
|
+
assert_equal 'SEDEX sem contrato', services[40010]
|
227
|
+
assert_equal 'SEDEX a Cobrar, sem contrato', services[40045]
|
228
|
+
assert_equal 'SEDEX a Cobrar, com contrato', services[40126]
|
229
|
+
assert_equal 'SEDEX 10, sem contrato', services[40215]
|
230
|
+
assert_equal 'SEDEX Hoje, sem contrato', services[40290]
|
231
|
+
assert_equal 'SEDEX com contrato', services[40096]
|
232
|
+
assert_equal 'SEDEX com contrato', services[40436]
|
233
|
+
assert_equal 'SEDEX com contrato', services[40444]
|
234
|
+
assert_equal 'SEDEX com contrato', services[40568]
|
235
|
+
assert_equal 'SEDEX com contrato', services[40606]
|
236
|
+
assert_equal 'e-SEDEX, com contrato', services[81019]
|
237
|
+
assert_equal 'e-SEDEX Prioritário, com contrato', services[81027]
|
238
|
+
assert_equal 'e-SEDEX Express, com contrato', services[81035]
|
239
|
+
assert_equal '(Grupo 1) e-SEDEX, com contrato', services[81868]
|
240
|
+
assert_equal '(Grupo 2) e-SEDEX, com contrato', services[81833]
|
241
|
+
assert_equal '(Grupo 3) e-SEDEX, com contrato', services[81850]
|
242
|
+
end
|
243
|
+
|
244
|
+
end
|
@@ -4,8 +4,7 @@ class FedExTest < Minitest::Test
|
|
4
4
|
include ActiveShipping::Test::Fixtures
|
5
5
|
|
6
6
|
def setup
|
7
|
-
@carrier
|
8
|
-
@tracking_response = xml_fixture('fedex/tracking_response')
|
7
|
+
@carrier = FedEx.new(:key => '1111', :password => '2222', :account => '3333', :login => '4444')
|
9
8
|
end
|
10
9
|
|
11
10
|
def test_initialize_options_requirements
|
@@ -73,150 +72,11 @@ class FedExTest < Minitest::Test
|
|
73
72
|
@carrier.find_rates location_fixtures[:ottawa], destination, package_fixtures[:book], :test => true
|
74
73
|
end
|
75
74
|
|
76
|
-
def test_find_tracking_info_should_return_a_tracking_response
|
77
|
-
@carrier.expects(:commit).returns(@tracking_response)
|
78
|
-
assert_instance_of ActiveShipping::TrackingResponse, @carrier.find_tracking_info('077973360403984', :test => true)
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_find_tracking_info_should_mark_shipment_as_delivered
|
82
|
-
@carrier.expects(:commit).returns(@tracking_response)
|
83
|
-
assert_equal true, @carrier.find_tracking_info('077973360403984').delivered?
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_find_tracking_info_should_return_correct_carrier
|
87
|
-
@carrier.expects(:commit).returns(@tracking_response)
|
88
|
-
assert_equal :fedex, @carrier.find_tracking_info('077973360403984').carrier
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_find_tracking_info_should_return_correct_carrier_name
|
92
|
-
@carrier.expects(:commit).returns(@tracking_response)
|
93
|
-
assert_equal 'FedEx', @carrier.find_tracking_info('077973360403984').carrier_name
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_find_tracking_info_should_return_correct_status
|
97
|
-
@carrier.expects(:commit).returns(@tracking_response)
|
98
|
-
assert_equal :delivered, @carrier.find_tracking_info('077973360403984').status
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_find_tracking_info_should_return_correct_status_code
|
102
|
-
@carrier.expects(:commit).returns(@tracking_response)
|
103
|
-
assert_equal 'dl', @carrier.find_tracking_info('077973360403984').status_code.downcase
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_find_tracking_info_should_return_correct_status_description
|
107
|
-
@carrier.expects(:commit).returns(@tracking_response)
|
108
|
-
assert_equal 'delivered', @carrier.find_tracking_info('1Z5FX0076803466397').status_description.downcase
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_find_tracking_info_should_return_delivery_signature
|
112
|
-
@carrier.expects(:commit).returns(@tracking_response)
|
113
|
-
assert_equal 'KKING', @carrier.find_tracking_info('077973360403984').delivery_signature
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_find_tracking_info_should_return_destination_address
|
117
|
-
@carrier.expects(:commit).returns(@tracking_response)
|
118
|
-
result = @carrier.find_tracking_info('077973360403984')
|
119
|
-
assert_equal 'sacramento', result.destination.city.downcase
|
120
|
-
assert_equal 'CA', result.destination.state
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_find_tracking_info_should_gracefully_handle_missing_destination_information
|
124
|
-
@carrier.expects(:commit).returns(xml_fixture('fedex/tracking_response_no_destination'))
|
125
|
-
result = @carrier.find_tracking_info('077973360403984')
|
126
|
-
assert_equal 'unknown', result.destination.city.downcase
|
127
|
-
assert_equal 'unknown', result.destination.state
|
128
|
-
assert_equal 'ZZ', result.destination.country.code(:alpha2).to_s
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_find_tracking_info_should_gracefully_handle_empty_destination_information
|
132
|
-
@carrier.expects(:commit).returns(xml_fixture('fedex/tracking_response_empty_destination'))
|
133
|
-
result = @carrier.find_tracking_info('077973360403984')
|
134
|
-
assert_equal 'unknown', result.destination.city.downcase
|
135
|
-
assert_equal 'unknown', result.destination.state
|
136
|
-
assert_equal 'ZZ', result.destination.country.code(:alpha2).to_s
|
137
|
-
end
|
138
|
-
|
139
|
-
def test_find_tracking_info_should_return_correct_shipper_address
|
140
|
-
@carrier.expects(:commit).returns(xml_fixture('fedex/tracking_response_with_shipper_address'))
|
141
|
-
response = @carrier.find_tracking_info('927489999894450502838')
|
142
|
-
assert_equal 'wallingford', response.shipper_address.city.downcase
|
143
|
-
assert_equal 'CT', response.shipper_address.state
|
144
|
-
end
|
145
|
-
|
146
|
-
def test_find_tracking_info_should_gracefully_handle_missing_shipper_address
|
147
|
-
@carrier.expects(:commit).returns(@tracking_response)
|
148
|
-
response = @carrier.find_tracking_info('077973360403984')
|
149
|
-
assert_equal nil, response.shipper_address
|
150
|
-
end
|
151
|
-
|
152
|
-
def test_find_tracking_info_should_return_correct_ship_time
|
153
|
-
@carrier.expects(:commit).returns(@tracking_response)
|
154
|
-
response = @carrier.find_tracking_info('927489999894450502838')
|
155
|
-
assert_equal Time.parse("2008-12-03T00:00:00").utc, response.ship_time
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_find_tracking_info_should_gracefully_handle_missing_ship_time
|
159
|
-
@carrier.expects(:commit).returns(xml_fixture('fedex/tracking_response_no_ship_time'))
|
160
|
-
response = @carrier.find_tracking_info('927489999894450502838')
|
161
|
-
assert_equal nil, response.ship_time
|
162
|
-
end
|
163
|
-
|
164
|
-
def test_find_tracking_info_should_return_correct_actual_delivery_date
|
165
|
-
@carrier.expects(:commit).returns(@tracking_response)
|
166
|
-
response = @carrier.find_tracking_info('077973360403984')
|
167
|
-
assert_equal Time.parse('2008-12-08T07:43:37-08:00').utc, response.actual_delivery_date
|
168
|
-
end
|
169
|
-
|
170
|
-
def test_find_tracking_info_should_gracefully_handle_missing_actual_delivery_date
|
171
|
-
# This particular fixture doesn't contain an actual delivery date
|
172
|
-
# (in addition to having a shipper address)
|
173
|
-
@carrier.expects(:commit).returns(xml_fixture('fedex/tracking_response_with_shipper_address'))
|
174
|
-
response = @carrier.find_tracking_info('9274899998944505028386')
|
175
|
-
assert_equal nil, response.actual_delivery_date
|
176
|
-
end
|
177
|
-
|
178
|
-
def test_find_tracking_info_should_return_correct_scheduled_delivery_date
|
179
|
-
@carrier.expects(:commit).returns(xml_fixture('fedex/tracking_response_with_estimated_delivery_date'))
|
180
|
-
response = @carrier.find_tracking_info('1234567890111')
|
181
|
-
assert_equal Time.parse('2013-10-15T00:00:00').utc, response.scheduled_delivery_date
|
182
|
-
end
|
183
|
-
|
184
|
-
def test_find_tracking_info_should_gracefully_handle_missing_scheduled_delivery_date
|
185
|
-
@carrier.expects(:commit).returns(@tracking_response)
|
186
|
-
response = @carrier.find_tracking_info('077973360403984')
|
187
|
-
assert_equal nil, response.scheduled_delivery_date
|
188
|
-
end
|
189
|
-
|
190
|
-
def test_find_tracking_info_should_return_origin_address
|
191
|
-
@carrier.expects(:commit).returns(@tracking_response)
|
192
|
-
result = @carrier.find_tracking_info('077973360403984')
|
193
|
-
assert_equal 'nashville', result.origin.city.downcase
|
194
|
-
assert_equal 'TN', result.origin.state
|
195
|
-
end
|
196
|
-
|
197
|
-
def test_find_tracking_info_should_parse_response_into_correct_number_of_shipment_events
|
198
|
-
@carrier.expects(:commit).returns(@tracking_response)
|
199
|
-
response = @carrier.find_tracking_info('077973360403984', :test => true)
|
200
|
-
assert_equal 6, response.shipment_events.size
|
201
|
-
end
|
202
|
-
|
203
|
-
def test_find_tracking_info_should_return_shipment_events_in_ascending_chronological_order
|
204
|
-
@carrier.expects(:commit).returns(@tracking_response)
|
205
|
-
response = @carrier.find_tracking_info('077973360403984', :test => true)
|
206
|
-
assert_equal response.shipment_events.map(&:time).sort, response.shipment_events.map(&:time)
|
207
|
-
end
|
208
|
-
|
209
|
-
def test_find_tracking_info_should_not_include_events_without_an_address
|
210
|
-
@carrier.expects(:commit).returns(@tracking_response)
|
211
|
-
response = @carrier.find_tracking_info('077973360403984', :test => true)
|
212
|
-
assert_nil response.shipment_events.find { |event| event.name == 'Shipment information sent to FedEx' }
|
213
|
-
end
|
214
|
-
|
215
75
|
def test_building_request_with_address_type_commercial_should_not_include_residential
|
216
76
|
mock_response = xml_fixture('fedex/ottawa_to_beverly_hills_rate_response')
|
217
77
|
expected_request = xml_fixture('fedex/ottawa_to_beverly_hills_commercial_rate_request')
|
218
|
-
Time.any_instance.expects(:to_xml_value).returns("2009-07-20T12:01:55-04:00")
|
219
78
|
|
79
|
+
@carrier.expects(:ship_timestamp).returns(Time.parse("2009-07-20T12:01:55-04:00").in_time_zone('US/Eastern'))
|
220
80
|
@carrier.expects(:commit).with { |request, test_mode| Hash.from_xml(request) == Hash.from_xml(expected_request) && test_mode }.returns(mock_response)
|
221
81
|
destination = ActiveShipping::Location.from(location_fixtures[:beverly_hills].to_hash, :address_type => :commercial)
|
222
82
|
@carrier.find_rates( location_fixtures[:ottawa],
|
@@ -227,8 +87,8 @@ class FedExTest < Minitest::Test
|
|
227
87
|
def test_building_freight_request_and_parsing_response
|
228
88
|
expected_request = xml_fixture('fedex/freight_rate_request')
|
229
89
|
mock_response = xml_fixture('fedex/freight_rate_response')
|
230
|
-
Time.any_instance.expects(:to_xml_value).returns("2013-11-01T14:04:01-07:00")
|
231
90
|
|
91
|
+
@carrier.expects(:ship_timestamp).returns(Time.parse("2013-11-01T14:04:01-07:00").in_time_zone('US/Pacific'))
|
232
92
|
@carrier.expects(:commit).with { |request, test_mode| Hash.from_xml(request) == Hash.from_xml(expected_request) && test_mode }.returns(mock_response)
|
233
93
|
|
234
94
|
# shipping and billing addresses below are provided by fedex test credentials
|
@@ -288,8 +148,7 @@ class FedExTest < Minitest::Test
|
|
288
148
|
def test_building_request_and_parsing_response
|
289
149
|
expected_request = xml_fixture('fedex/ottawa_to_beverly_hills_rate_request')
|
290
150
|
mock_response = xml_fixture('fedex/ottawa_to_beverly_hills_rate_response')
|
291
|
-
|
292
|
-
|
151
|
+
@carrier.expects(:ship_timestamp).returns(Time.parse("2009-07-20T12:01:55-04:00").in_time_zone('US/Eastern'))
|
293
152
|
@carrier.expects(:commit).with { |request, test_mode| Hash.from_xml(request) == Hash.from_xml(expected_request) && test_mode }.returns(mock_response)
|
294
153
|
response = @carrier.find_rates( location_fixtures[:ottawa],
|
295
154
|
location_fixtures[:beverly_hills],
|
@@ -322,15 +181,15 @@ class FedExTest < Minitest::Test
|
|
322
181
|
def test_parsing_response_with_no_rate_reply
|
323
182
|
expected_request = xml_fixture('fedex/ottawa_to_beverly_hills_rate_request')
|
324
183
|
mock_response = xml_fixture('fedex/unknown_fedex_document_reply')
|
325
|
-
Time.any_instance.expects(:to_xml_value).returns("2009-07-20T12:01:55-04:00")
|
326
184
|
|
185
|
+
@carrier.expects(:ship_timestamp).returns(Time.parse("2009-07-20T12:01:55-04:00").in_time_zone('US/Eastern'))
|
327
186
|
@carrier.expects(:commit).with { |request, test_mode| Hash.from_xml(request) == Hash.from_xml(expected_request) && test_mode }.returns(mock_response)
|
328
|
-
exception = assert_raises
|
187
|
+
exception = assert_raises(ActiveShipping::ResponseContentError) do
|
329
188
|
@carrier.find_rates( location_fixtures[:ottawa],
|
330
189
|
location_fixtures[:beverly_hills],
|
331
190
|
package_fixtures.values_at(:book, :wii), :test => true)
|
332
191
|
end
|
333
|
-
message = "Invalid document \n\n
|
192
|
+
message = "Invalid document \n\n#{mock_response}"
|
334
193
|
assert_equal message, exception.message
|
335
194
|
end
|
336
195
|
|
@@ -391,18 +250,164 @@ class FedExTest < Minitest::Test
|
|
391
250
|
end
|
392
251
|
end
|
393
252
|
|
394
|
-
def
|
253
|
+
def test_parsing_response_without_notifications
|
395
254
|
mock_response = xml_fixture('fedex/reply_without_notifications')
|
396
255
|
|
397
256
|
@carrier.expects(:commit).returns(mock_response)
|
398
257
|
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
258
|
+
response = @carrier.find_rates(
|
259
|
+
location_fixtures[:ottawa],
|
260
|
+
location_fixtures[:beverly_hills],
|
261
|
+
package_fixtures.values_at(:book, :wii),
|
262
|
+
:test => true
|
263
|
+
)
|
264
|
+
|
265
|
+
assert response.success?
|
266
|
+
end
|
267
|
+
|
268
|
+
### find_tracking_info
|
269
|
+
|
270
|
+
def test_tracking_info_for_delivered_with_signature
|
271
|
+
mock_response = xml_fixture('fedex/tracking_response_delivered_with_signature')
|
272
|
+
@carrier.expects(:commit).returns(mock_response)
|
273
|
+
|
274
|
+
response = @carrier.find_tracking_info('449044304137821')
|
275
|
+
assert_equal '449044304137821', response.tracking_number
|
276
|
+
assert_equal 'AVILLALON', response.delivery_signature
|
277
|
+
assert response.delivered?
|
278
|
+
refute response.exception?
|
279
|
+
|
280
|
+
assert_equal Date.parse('2013-12-30'), response.ship_time
|
281
|
+
assert_equal nil, response.scheduled_delivery_date
|
282
|
+
assert_equal Time.parse('2014-01-02T18:23:29Z'), response.actual_delivery_date
|
283
|
+
|
284
|
+
origin_address = ActiveShipping::Location.new(
|
285
|
+
city: 'JEFFERSONVILLE',
|
286
|
+
country: 'US',
|
287
|
+
state: 'IN'
|
288
|
+
)
|
289
|
+
assert_equal origin_address.to_hash, response.origin.to_hash
|
290
|
+
|
291
|
+
destination_address = ActiveShipping::Location.new(
|
292
|
+
city: 'Miami',
|
293
|
+
country: 'US',
|
294
|
+
state: 'FL'
|
295
|
+
)
|
296
|
+
assert_equal destination_address.to_hash, response.destination.to_hash
|
297
|
+
|
298
|
+
assert_equal 11, response.shipment_events.length
|
299
|
+
assert_equal 'Delivered', response.latest_event.name
|
300
|
+
end
|
301
|
+
|
302
|
+
def test_tracking_info_for_delivered_at_door
|
303
|
+
mock_response = xml_fixture('fedex/tracking_response_delivered_at_door')
|
304
|
+
@carrier.expects(:commit).returns(mock_response)
|
305
|
+
|
306
|
+
response = @carrier.find_tracking_info('403934084723025')
|
307
|
+
assert_equal '403934084723025', response.tracking_number
|
308
|
+
assert response.delivered?
|
309
|
+
refute response.exception?
|
310
|
+
assert_equal 10, response.shipment_events.length
|
311
|
+
assert_equal 'Delivered', response.latest_event.name
|
312
|
+
assert_equal nil, response.delivery_signature
|
313
|
+
end
|
314
|
+
|
315
|
+
def test_tracking_info_for_in_transit
|
316
|
+
mock_response = xml_fixture('fedex/tracking_response_in_transit')
|
317
|
+
@carrier.expects(:commit).returns(mock_response)
|
318
|
+
|
319
|
+
response = @carrier.find_tracking_info('123456789012')
|
320
|
+
refute response.delivered?
|
321
|
+
refute response.exception?
|
322
|
+
|
323
|
+
assert_equal '123456789012', response.tracking_number
|
324
|
+
assert_equal :fedex, response.carrier
|
325
|
+
assert_equal 'FedEx', response.carrier_name
|
326
|
+
assert_equal :in_transit, response.status
|
327
|
+
assert_equal 'IT', response.status_code
|
328
|
+
assert_equal "Package available for clearance", response.status_description
|
329
|
+
assert_equal nil, response.delivery_signature
|
330
|
+
|
331
|
+
assert_equal Time.parse('2014-11-17T22:39:00+11:00'), response.ship_time
|
332
|
+
assert_equal nil, response.scheduled_delivery_date
|
333
|
+
assert_equal nil, response.actual_delivery_date
|
334
|
+
|
335
|
+
assert_equal nil, response.origin
|
336
|
+
|
337
|
+
destination_address = ActiveShipping::Location.new(
|
338
|
+
city: 'GRAFTON',
|
339
|
+
country: 'AU',
|
340
|
+
state: 'ON'
|
341
|
+
)
|
342
|
+
assert_equal destination_address.to_hash, response.destination.to_hash
|
343
|
+
|
344
|
+
assert_equal 1, response.shipment_events.length
|
345
|
+
assert_equal 'In transit', response.latest_event.name
|
346
|
+
end
|
347
|
+
|
348
|
+
def test_tracking_info_for_shipment_exception
|
349
|
+
mock_response = xml_fixture('fedex/tracking_response_shipment_exception')
|
350
|
+
@carrier.expects(:commit).returns(mock_response)
|
351
|
+
|
352
|
+
response = @carrier.find_tracking_info('957794015041323')
|
353
|
+
assert_equal '957794015041323', response.tracking_number
|
354
|
+
refute response.delivered?
|
355
|
+
assert response.exception?
|
356
|
+
assert_equal :exception, response.status
|
357
|
+
assert_equal "Unable to deliver", response.status_description
|
358
|
+
|
359
|
+
assert_equal Date.parse('2014-01-27'), response.ship_time
|
360
|
+
assert_equal nil, response.scheduled_delivery_date
|
361
|
+
assert_equal nil, response.actual_delivery_date
|
362
|
+
|
363
|
+
origin_address = ActiveShipping::Location.new(
|
364
|
+
city: 'AUSTIN',
|
365
|
+
country: 'US',
|
366
|
+
state: 'TX'
|
367
|
+
)
|
368
|
+
assert_equal origin_address.to_hash, response.origin.to_hash
|
369
|
+
|
370
|
+
destination_address = ActiveShipping::Location.new(
|
371
|
+
city: 'GOOSE CREEK',
|
372
|
+
country: 'US',
|
373
|
+
state: 'SC'
|
374
|
+
)
|
375
|
+
assert_equal destination_address.to_hash, response.destination.to_hash
|
376
|
+
|
377
|
+
assert_equal 8, response.shipment_events.length
|
378
|
+
assert_equal "Shipment exception", response.latest_event.name
|
379
|
+
end
|
380
|
+
|
381
|
+
def test_tracking_info_without_status
|
382
|
+
mock_response = xml_fixture('fedex/tracking_response_multiple_results')
|
383
|
+
@carrier.expects(:commit).returns(mock_response)
|
384
|
+
|
385
|
+
error = assert_raises(ActiveShipping::Error) do
|
386
|
+
@carrier.find_tracking_info('123456789012')
|
387
|
+
end
|
388
|
+
|
389
|
+
msg = 'Multiple matches were found. Specify a unqiue identifier: 2456987000~123456789012~FX, 2456979001~123456789012~FX, 2456979000~123456789012~FX'
|
390
|
+
assert_equal msg, error.message
|
391
|
+
end
|
392
|
+
|
393
|
+
def test_tracking_info_with_unknown_tracking_number
|
394
|
+
mock_response = xml_fixture('fedex/tracking_response_not_found')
|
395
|
+
@carrier.expects(:commit).returns(mock_response)
|
396
|
+
|
397
|
+
error = assert_raises(ActiveShipping::ShipmentNotFound) do
|
398
|
+
@carrier.find_tracking_info('123456789013')
|
399
|
+
end
|
400
|
+
|
401
|
+
msg = 'This tracking number cannot be found. Please check the number or contact the sender.'
|
402
|
+
assert_equal msg, error.message
|
403
|
+
end
|
404
|
+
|
405
|
+
def test_tracking_info_with_bad_tracking_number
|
406
|
+
mock_response = xml_fixture('fedex/tracking_response_bad_tracking_number')
|
407
|
+
@carrier.expects(:commit).returns(mock_response)
|
408
|
+
|
409
|
+
assert_raises(ActiveShipping::ResponseError) do
|
410
|
+
@carrier.find_tracking_info('abc')
|
406
411
|
end
|
407
412
|
end
|
408
413
|
end
|