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.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.yardopts +0 -1
  5. data/CHANGELOG.md +17 -0
  6. data/CONTRIBUTING.md +2 -2
  7. data/Gemfile.activesupport32 +1 -0
  8. data/README.md +1 -1
  9. data/Rakefile +1 -1
  10. data/active_shipping.gemspec +2 -2
  11. data/lib/active_shipping.rb +2 -3
  12. data/lib/active_shipping/carriers.rb +1 -0
  13. data/lib/active_shipping/carriers/canada_post_pws.rb +281 -266
  14. data/lib/active_shipping/carriers/correios.rb +285 -0
  15. data/lib/active_shipping/carriers/fedex.rb +205 -199
  16. data/lib/active_shipping/carriers/stamps.rb +218 -219
  17. data/lib/active_shipping/carriers/ups.rb +287 -48
  18. data/lib/active_shipping/carriers/usps.rb +3 -3
  19. data/lib/active_shipping/delivery_date_estimate.rb +21 -0
  20. data/lib/active_shipping/delivery_date_estimates_response.rb +11 -0
  21. data/lib/active_shipping/errors.rb +20 -1
  22. data/lib/active_shipping/location.rb +0 -5
  23. data/lib/active_shipping/response.rb +0 -15
  24. data/lib/active_shipping/version.rb +1 -1
  25. data/test/credentials.yml +11 -3
  26. data/test/fixtures/xml/correios/book_response.xml +13 -0
  27. data/test/fixtures/xml/correios/book_response_invalid.xml +13 -0
  28. data/test/fixtures/xml/correios/clothes_response.xml +43 -0
  29. data/test/fixtures/xml/correios/poster_response.xml +23 -0
  30. data/test/fixtures/xml/correios/shoes_response.xml +43 -0
  31. data/test/fixtures/xml/fedex/tracking_request.xml +13 -11
  32. data/test/fixtures/xml/fedex/tracking_response_bad_tracking_number.xml +20 -0
  33. data/test/fixtures/xml/fedex/tracking_response_delivered_at_door.xml +254 -0
  34. data/test/fixtures/xml/fedex/tracking_response_delivered_at_facility.xml +403 -0
  35. data/test/fixtures/xml/fedex/tracking_response_delivered_with_signature.xml +269 -0
  36. data/test/fixtures/xml/fedex/tracking_response_in_transit.xml +127 -0
  37. data/test/fixtures/xml/fedex/tracking_response_multiple_results.xml +100 -0
  38. data/test/fixtures/xml/fedex/tracking_response_not_found.xml +52 -0
  39. data/test/fixtures/xml/fedex/tracking_response_shipment_exception.xml +209 -0
  40. data/test/fixtures/xml/ups/delivery_dates_response.xml +140 -0
  41. data/test/fixtures/xml/ups/package_exceeds_maximum_length.xml +12 -0
  42. data/test/fixtures/xml/ups/rate_single_service.xml +54 -0
  43. data/test/fixtures/xml/ups/rescheduled_shipment.xml +204 -0
  44. data/test/fixtures/xml/ups/test_real_home_as_residential_destination_response.xml +290 -1
  45. data/test/fixtures/xml/usps/delivered_extended_tracking_response.xml +11 -0
  46. data/test/remote/canada_post_pws_platform_test.rb +35 -22
  47. data/test/remote/canada_post_pws_test.rb +32 -40
  48. data/test/remote/correios_test.rb +83 -0
  49. data/test/remote/fedex_test.rb +95 -13
  50. data/test/remote/stamps_test.rb +1 -0
  51. data/test/remote/ups_test.rb +77 -40
  52. data/test/remote/usps_test.rb +13 -1
  53. data/test/test_helper.rb +12 -2
  54. data/test/unit/carriers/canada_post_pws_rating_test.rb +66 -59
  55. data/test/unit/carriers/canada_post_pws_shipping_test.rb +34 -23
  56. data/test/unit/carriers/correios_test.rb +244 -0
  57. data/test/unit/carriers/fedex_test.rb +161 -156
  58. data/test/unit/carriers/ups_test.rb +193 -1
  59. data/test/unit/carriers/usps_test.rb +14 -0
  60. data/test/unit/location_test.rb +0 -10
  61. metadata +63 -46
  62. metadata.gz.sig +0 -0
  63. data/lib/vendor/test_helper.rb +0 -6
  64. data/lib/vendor/xml_node/README +0 -36
  65. data/lib/vendor/xml_node/Rakefile +0 -21
  66. data/lib/vendor/xml_node/benchmark/bench_generation.rb +0 -30
  67. data/lib/vendor/xml_node/init.rb +0 -1
  68. data/lib/vendor/xml_node/lib/xml_node.rb +0 -221
  69. data/lib/vendor/xml_node/test/test_generating.rb +0 -89
  70. data/lib/vendor/xml_node/test/test_parsing.rb +0 -40
  71. data/test/fixtures/xml/fedex/tracking_response.xml +0 -151
  72. data/test/fixtures/xml/fedex/tracking_response_empty_destination.xml +0 -76
  73. data/test/fixtures/xml/fedex/tracking_response_no_destination.xml +0 -139
  74. data/test/fixtures/xml/fedex/tracking_response_no_ship_time.xml +0 -150
  75. data/test/fixtures/xml/fedex/tracking_response_with_estimated_delivery_date.xml +0 -95
  76. data/test/fixtures/xml/fedex/tracking_response_with_shipper_address.xml +0 -71
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0"?>
2
+ <TrackResponse>
3
+ <TrackInfo ID="9361289949034102283511">
4
+ <TrackSummary>Your item was delivered to the front desk or reception area at 2:16 pm on October 12, 2013 in BROOKLYN, NY 11201.</TrackSummary>
5
+ <TrackDetail>Out for Delivery, October 12, 2013, 10:16 am, BROOKLYN, NY 11201</TrackDetail>
6
+ <TrackDetail>Sorting Complete, October 12, 2013, 10:06 am, BROOKLYN, NY 11201</TrackDetail>
7
+ <TrackDetail>Arrival at Post Office, October 12, 2013, 6:32 am, BROOKLYN, NY 11201</TrackDetail>
8
+ <TrackDetail>Acceptance, October 12, 2013, 6:26 am, BROOKLYN, NY 11201</TrackDetail>
9
+ <TrackDetail>Electronic Shipping Info Received, October 12, 2013</TrackDetail>
10
+ </TrackInfo>
11
+ </TrackResponse>
@@ -8,7 +8,7 @@ class RemoteCanadaPostPWSPlatformTest < Minitest::Test
8
8
  include ActiveShipping::Test::Fixtures
9
9
 
10
10
  def setup
11
- @login = credentials(:canada_post_pws)
11
+ @login = credentials(:canada_post_pws_platform).merge(endpoint: "https://ct.soa-gw.canadapost.ca/")
12
12
 
13
13
  # 100 grams, 93 cm long, 10 cm diameter, cylinders have different volume calculations
14
14
  # @pkg1 = Package.new(1000, [93,10], :value => 10.00)
@@ -92,31 +92,24 @@ class RemoteCanadaPostPWSPlatformTest < Minitest::Test
92
92
  @cp = CanadaPostPWS.new(@login)
93
93
  @cp.logger = Logger.new(StringIO.new)
94
94
 
95
- @customer_number = @login[:customer_number]
96
- @customer_api_key = @login[:customer_api_key]
97
- @customer_secret = @login[:customer_secret]
98
95
  rescue NoCredentialsFound => e
99
96
  skip(e.message)
100
97
  end
101
98
 
102
99
  def build_options
103
- {
104
- :customer_number => @customer_number,
105
- :customer_api_key => @customer_api_key,
106
- :customer_secret => @customer_secret
107
- }
100
+ { :customer_number => @login[:customer_number] }
108
101
  end
109
102
 
110
103
  def test_rates
111
- rates = @cp.find_rates(@home_params, @dom_params, [@pkg1], build_options)
112
- assert_equal RateResponse, rates.class
113
- assert_equal RateEstimate, rates.rates.first.class
104
+ rate_response = @cp.find_rates(@home_params, @dom_params, [@pkg1], build_options)
105
+ assert_kind_of ActiveShipping::RateResponse, rate_response
106
+ assert_kind_of ActiveShipping::RateEstimate, rate_response.rates.first
114
107
  end
115
108
 
116
109
  def test_rates_with_insurance_changes_price
117
110
  rates = @cp.find_rates(@home_params, @dom_params, [@pkg1], build_options)
118
111
  insured_rates = @cp.find_rates(@home_params, @dom_params, [@pkg1], build_options.merge(@shipping_opts1))
119
- assert_not_equal rates.rates.first.price, insured_rates.rates.first.price
112
+ refute_equal rates.rates.first.price, insured_rates.rates.first.price
120
113
  end
121
114
 
122
115
  def test_rates_with_invalid_customer_raises_exception
@@ -139,7 +132,7 @@ class RemoteCanadaPostPWSPlatformTest < Minitest::Test
139
132
  assert_equal 'Xpresspost', response.service_name
140
133
  assert response.expected_date.is_a?(Date)
141
134
  assert response.customer_number
142
- assert_equal 10, response.shipment_events.count
135
+ assert_equal 13, response.shipment_events.count
143
136
  end
144
137
 
145
138
  def test_tracking_invalid_pin_raises_exception
@@ -147,7 +140,7 @@ class RemoteCanadaPostPWSPlatformTest < Minitest::Test
147
140
  exception = assert_raises(ResponseError) do
148
141
  @cp.find_tracking_info(pin, build_options)
149
142
  end
150
- assert_equal "No Pin History", exception.message
143
+ assert_equal "No Tracking", exception.message
151
144
  end
152
145
 
153
146
  def test_create_shipment_with_invalid_customer_raises_exception
@@ -164,11 +157,14 @@ class RemoteCanadaPostPWSPlatformTest < Minitest::Test
164
157
  end
165
158
 
166
159
  def test_merchant_details_empty_details
167
- response = @cp.register_merchant
168
- exception = assert_raises(ResponseError) do
169
- response = @cp.retrieve_merchant_details(:token_id => response.token_id)
170
- end
171
- assert_equal "No Merchant Info", exception.message
160
+ register_response = @cp.register_merchant
161
+ details_response = @cp.retrieve_merchant_details(:token_id => register_response.token_id)
162
+ assert_kind_of ActiveShipping::CPPWSMerchantDetailsResponse, details_response
163
+
164
+ assert_equal '0000000000', details_response.customer_number
165
+ assert_equal '1234567890', details_response.contract_number
166
+ assert_equal '0000000000000000', details_response.username
167
+ assert_equal '1a2b3c4d5e6f7a8b9c0d12', details_response.password
172
168
  end
173
169
 
174
170
  def test_find_services_no_country
@@ -192,7 +188,7 @@ class RemoteCanadaPostPWSPlatformTest < Minitest::Test
192
188
  assert response = @cp.find_service_options("INT.XP", nil, build_options)
193
189
  assert_equal "INT.XP", response[:service_code]
194
190
  assert_equal "Xpresspost International", response[:service_name]
195
- assert_equal 4, response[:options].size
191
+ assert_equal 5, response[:options].size
196
192
  assert_equal "COV", response[:options][0][:code]
197
193
  assert_equal false, response[:options][0][:required]
198
194
  assert_equal true, response[:options][0][:qualifier_required]
@@ -211,7 +207,7 @@ class RemoteCanadaPostPWSPlatformTest < Minitest::Test
211
207
  assert response = @cp.find_service_options("INT.XP", "JP", build_options)
212
208
  assert_equal "INT.XP", response[:service_code]
213
209
  assert_equal "Xpresspost International", response[:service_name]
214
- assert_equal 3, response[:options].size
210
+ assert_equal 4, response[:options].size
215
211
  assert_equal "COV", response[:options][0][:code]
216
212
  assert_equal false, response[:options][0][:required]
217
213
  assert_equal true, response[:options][0][:qualifier_required]
@@ -245,4 +241,21 @@ class RemoteCanadaPostPWSPlatformTest < Minitest::Test
245
241
  assert_equal "LAD", response[:code]
246
242
  assert_equal "Laisser à la porte (pas d'avis)", response[:name]
247
243
  end
244
+
245
+ def test_register_merchant
246
+ response = @cp.register_merchant
247
+ assert response.is_a?(CPPWSRegisterResponse)
248
+ assert_equal "1111111111111111111111", response.token_id
249
+ end
250
+
251
+ def test_merchant_details
252
+ token_id = "1111111111111111111111"
253
+ response = @cp.retrieve_merchant_details(:token_id => token_id)
254
+ assert response.is_a?(CPPWSMerchantDetailsResponse)
255
+ assert_equal "0000000000", response.customer_number
256
+ assert_equal "1234567890", response.contract_number
257
+ assert_equal "0000000000000000", response.username
258
+ assert_equal "1a2b3c4d5e6f7a8b9c0d12", response.password
259
+ assert_equal true, response.has_default_credit_card
260
+ end
248
261
  end
@@ -7,15 +7,14 @@ class RemoteCanadaPostPWSTest < Minitest::Test
7
7
 
8
8
  def setup
9
9
  @login = credentials(:canada_post_pws)
10
+ refute @login.key?(:platform_id), "The 'canada_post_pws' credentials should NOT include a platform ID"
10
11
 
11
- # 100 grams, 93 cm long, 10 cm diameter, cylinders have different volume calculations
12
- # @pkg1 = Package.new(1000, [93,10], :value => 10.00)
13
- @pkg1 = Package.new(1000, nil, :value => 10.00)
12
+ # 1000 grams, 93 cm long, 10 cm diameter, cylinders have different volume calculations
13
+ @pkg1 = Package.new(1000, [93, 10, 10], :value => 10.00)
14
14
 
15
15
  @line_item1 = line_item_fixture
16
16
 
17
- @shipping_opts1 = {:dc => true, :cod => true, :cod_amount => 500.00, :cov => true, :cov_amount => 100.00,
18
- :so => true, :pa18 => true}
17
+ @shipping_opts1 = { :dc => true, :cov => true, :cov_amount => 100.00, :aban => true }
19
18
 
20
19
  @home_params = {
21
20
  :name => "John Smith",
@@ -81,7 +80,7 @@ class RemoteCanadaPostPWSTest < Minitest::Test
81
80
 
82
81
  @DEFAULT_RESPONSE = {
83
82
  :shipping_id => "406951321983787352",
84
- :tracking_number => "11111118901234",
83
+ :tracking_number => "123456789012",
85
84
  :label_url => "https://ct.soa-gw.canadapost.ca/ers/artifact/#{@login[:api_key]}/20238/0"
86
85
  }
87
86
  rescue NoCredentialsFound => e
@@ -90,9 +89,9 @@ class RemoteCanadaPostPWSTest < Minitest::Test
90
89
 
91
90
  def test_rates
92
91
  opts = {:customer_number => @customer_number}
93
- rates = @cp.find_rates(@home_params, @dom_params, [@pkg1], opts)
94
- assert_equal RateResponse, rates.class
95
- assert_equal RateEstimate, rates.rates.first.class
92
+ rate_response = @cp.find_rates(@home_params, @dom_params, [@pkg1], opts)
93
+ assert_kind_of ActiveShipping::RateResponse, rate_response
94
+ assert_kind_of ActiveShipping::RateEstimate, rate_response.rates.first
96
95
  end
97
96
 
98
97
  def test_rates_with_invalid_customer_raises_exception
@@ -108,7 +107,7 @@ class RemoteCanadaPostPWSTest < Minitest::Test
108
107
  assert_equal 'Xpresspost', response.service_name
109
108
  assert response.expected_date.is_a?(Date)
110
109
  assert response.customer_number
111
- assert_equal 10, response.shipment_events.count
110
+ assert_equal 13, response.shipment_events.count
112
111
  end
113
112
 
114
113
  def test_tracking_when_no_tracking_info_raises_exception
@@ -124,26 +123,36 @@ class RemoteCanadaPostPWSTest < Minitest::Test
124
123
  def test_create_shipment
125
124
  opts = {:customer_number => @customer_number, :service => "DOM.XP"}
126
125
  response = @cp.create_shipment(@home_params, @dom_params, @pkg1, @line_item1, opts)
127
- assert response.is_a?(CPPWSShippingResponse)
128
- assert_equal @DEFAULT_RESPONSE[:shipping_id], response.shipping_id
129
- assert_equal @DEFAULT_RESPONSE[:tracking_number], response.tracking_number
130
- assert_equal @DEFAULT_RESPONSE[:label_url], response.label_url
126
+ assert_kind_of CPPWSShippingResponse, response
127
+ assert_match /\A\d{17}\z/, response.shipping_id
128
+ assert_equal "123456789012", response.tracking_number
129
+ assert_match "https://ct.soa-gw.canadapost.ca/ers/artifact/", response.label_url
130
+ assert_match @login[:api_key], response.label_url
131
131
  end
132
132
 
133
133
  def test_create_shipment_with_options
134
- opts = {:customer_number => @customer_number, :service => "USA.EP"}
135
- opts.merge! @shipping_opts1
134
+ opts = {:customer_number => @customer_number, :service => "USA.EP"}.merge(@shipping_opts1)
136
135
  response = @cp.create_shipment(@home_params, @dest_params, @pkg1, @line_item1, opts)
137
- assert response.is_a?(CPPWSShippingResponse)
138
- assert_equal @DEFAULT_RESPONSE[:shipping_id], response.shipping_id
139
- assert_equal @DEFAULT_RESPONSE[:tracking_number], response.tracking_number
140
- assert_equal @DEFAULT_RESPONSE[:label_url], response.label_url
136
+
137
+ assert_kind_of CPPWSShippingResponse, response
138
+ assert_match /\A\d{17}\z/, response.shipping_id
139
+ assert_equal "123456789012", response.tracking_number
140
+ assert_match "https://ct.soa-gw.canadapost.ca/ers/artifact/", response.label_url
141
+ assert_match @login[:api_key], response.label_url
141
142
  end
142
143
 
143
144
  def test_retrieve_shipping_label
144
- shipping_response = CPPWSShippingResponse.new(true, '', {}, @DEFAULT_RESPONSE)
145
- response = @cp.retrieve_shipping_label(shipping_response)
146
- assert_not_nil response
145
+ opts = {:customer_number => @customer_number, :service => "DOM.XP"}
146
+ shipping_response = @cp.create_shipment(@home_params, @dom_params, @pkg1, @line_item1, opts)
147
+
148
+ # Looks like it takes Canada Post some time to actually generate the PDF.
149
+ response = nil
150
+ 10.times do
151
+ response = @cp.retrieve_shipping_label(shipping_response)
152
+ break unless response == ""
153
+ sleep(0.5)
154
+ end
155
+
147
156
  assert_equal "%PDF", response[0...4]
148
157
  end
149
158
 
@@ -153,21 +162,4 @@ class RemoteCanadaPostPWSTest < Minitest::Test
153
162
  @cp.create_shipment(@home_params, @dom_params, @pkg1, @line_item1, opts)
154
163
  end
155
164
  end
156
-
157
- def test_register_merchant
158
- response = @cp.register_merchant
159
- assert response.is_a?(CPPWSRegisterResponse)
160
- assert_equal "1111111111111111111111", response.token_id
161
- end
162
-
163
- def test_merchant_details
164
- token_id = "1111111111111111111111"
165
- response = @cp.retrieve_merchant_details(:token_id => token_id)
166
- assert response.is_a?(CPPWSMerchantDetailsResponse)
167
- assert_equal "0000000000", response.customer_number
168
- assert_equal "1234567890", response.contract_number
169
- assert_equal "0000000000000000", response.username
170
- assert_equal "1a2b3c4d5e6f7a8b9c0d12", response.password
171
- assert_equal true, response.has_default_credit_card
172
- end
173
165
  end
@@ -0,0 +1,83 @@
1
+ require 'test_helper'
2
+
3
+ class RemoteCorreiosTest < Minitest::Test
4
+
5
+ def setup
6
+ @carrier = Correios.new
7
+
8
+ @saopaulo = Location.new(:zip => "01415000")
9
+ @riodejaneiro = Location.new(:zip => "22210030")
10
+ @invalid_city = Location.new(:zip => "invalid")
11
+
12
+ @book = Package.new(250, [14, 19, 2])
13
+ @invalid_book = Package.new(9999999999999, [14, 19, 2])
14
+ @poster = Package.new(100, [93, 15], :cylinder => true)
15
+ end
16
+
17
+ def test_book_request
18
+ response = @carrier.find_rates(@saopaulo, @riodejaneiro, [@book])
19
+
20
+ assert response.is_a?(RateResponse)
21
+ assert response.rates.first.is_a?(RateEstimate)
22
+ assert response.success?
23
+ assert_equal 1, response.params["responses"].size
24
+ assert_equal 2, response.rates.size
25
+ assert_equal 1, response.raw_responses.size
26
+ end
27
+
28
+ def test_poster_and_book_request
29
+ response = @carrier.find_rates(@saopaulo, @riodejaneiro, [@book, @poster])
30
+
31
+ assert response.is_a?(RateResponse)
32
+ assert response.rates.first.is_a?(RateEstimate)
33
+ assert response.success?
34
+ assert_equal 2, response.params["responses"].size
35
+ assert_equal 2, response.rates.size
36
+ assert_equal 2, response.raw_responses.size
37
+ end
38
+
39
+ def test_book_request_with_specific_services
40
+ response = @carrier.find_rates(@saopaulo, @riodejaneiro, [@book], :services => [41106, 40010, 40215])
41
+
42
+ assert response.is_a?(RateResponse)
43
+ assert response.rates.first.is_a?(RateEstimate)
44
+ assert response.success?
45
+ assert_equal 1, response.params["responses"].size
46
+ assert_equal 3, response.rates.size
47
+ assert_equal 1, response.raw_responses.size
48
+ end
49
+
50
+ def test_response_prices
51
+ response = @carrier.find_rates(@saopaulo, @riodejaneiro, [@book, @poster])
52
+ response_book= @carrier.find_rates(@saopaulo, @riodejaneiro, [@book])
53
+ response_poster = @carrier.find_rates(@saopaulo, @riodejaneiro, [@poster])
54
+
55
+ book_price = response_book.rates.sum(&:price)
56
+ poster_price = response_poster.rates.sum(&:price)
57
+ total_price = response.rates.sum(&:price)
58
+
59
+ assert total_price == book_price + poster_price
60
+ end
61
+
62
+ def test_invalid_zip
63
+ error = assert_raises(ActiveShipping::ResponseError) do
64
+ @carrier.find_rates(@saopaulo, @invalid_city, [@book])
65
+ end
66
+
67
+ assert_kind_of RateResponse, error.response
68
+ refute error.message.empty?
69
+ assert error.response.raw_responses.any?
70
+ assert_equal Hash.new, error.response.params
71
+ end
72
+
73
+ def test_valid_book_and_invalid_book
74
+ error = assert_raises(ActiveShipping::ResponseError) do
75
+ @carrier.find_rates(@saopaulo, @riodejaneiro, [@book, @invalid_book])
76
+ end
77
+
78
+ assert_kind_of RateResponse, error.response
79
+ refute error.message.empty?
80
+ assert error.response.raw_responses.any?
81
+ assert_equal Hash.new, error.response.params
82
+ end
83
+ end
@@ -10,10 +10,18 @@ class RemoteFedExTest < Minitest::Test
10
10
  skip(e.message)
11
11
  end
12
12
 
13
+ ### valid_credentials?
14
+
13
15
  def test_valid_credentials
14
- assert @carrier.valid_credentials?
16
+ valid_carrier = FedEx.new(credentials(:fedex))
17
+ assert valid_carrier.valid_credentials?
18
+
19
+ invalid_carrier = FedEx.new(credentials(:fedex).merge(password: 'invalid'))
20
+ refute invalid_carrier.valid_credentials?
15
21
  end
16
22
 
23
+ ### find_rates
24
+
17
25
  def test_us_to_canada
18
26
  response = @carrier.find_rates(
19
27
  location_fixtures[:beverly_hills],
@@ -190,17 +198,6 @@ class RemoteFedExTest < Minitest::Test
190
198
  end
191
199
  end
192
200
 
193
- def test_tracking
194
- p response = @carrier.find_tracking_info('123456789012', :test => true)
195
- assert response
196
- end
197
-
198
- def test_tracking_with_bad_number
199
- assert_raises(ResponseError) do
200
- @carrier.find_tracking_info('12345')
201
- end
202
- end
203
-
204
201
  def test_different_rates_for_commercial
205
202
  residential_response = @carrier.find_rates(
206
203
  location_fixtures[:beverly_hills],
@@ -213,6 +210,91 @@ class RemoteFedExTest < Minitest::Test
213
210
  package_fixtures.values_at(:chocolate_stuff)
214
211
  )
215
212
 
216
- assert_not_equal residential_response.rates.map(&:price), commercial_response.rates.map(&:price)
213
+ refute_equal residential_response.rates.map(&:price), commercial_response.rates.map(&:price)
214
+ end
215
+
216
+ ### find_tracking_info
217
+
218
+ def test_find_tracking_info_for_delivered_shipment
219
+ # unfortunately, we have to use Fedex unique identifiers, because the test tracking numbers are overloaded.
220
+ response = @carrier.find_tracking_info('123456789012', unique_identifier: '2456987000~123456789012~FX')
221
+ assert response.success?
222
+ assert response.delivered?
223
+ assert_equal '123456789012', response.tracking_number
224
+ assert_equal :delivered, response.status
225
+ assert_equal 'DL', response.status_code
226
+ assert_equal "Delivered", response.status_description
227
+
228
+ assert_equal Time.parse('2014-11-14T03:49:00Z'), response.ship_time
229
+ assert_equal nil, response.scheduled_delivery_date
230
+ assert_equal Time.parse('2014-12-05T00:28:00Z'), response.actual_delivery_date
231
+
232
+ assert_equal nil, response.origin
233
+
234
+ destination_address = ActiveShipping::Location.new(
235
+ city: 'COLLIERVILLE',
236
+ country: 'US',
237
+ state: 'TN'
238
+ )
239
+ assert_equal destination_address.to_hash, response.destination.to_hash
240
+ assert_equal 1, response.shipment_events.length
241
+ end
242
+
243
+ def test_find_tracking_info_for_in_transit_shipment_1
244
+ # unfortunately, we have to use Fedex unique identifiers, because the test tracking numbers are overloaded.
245
+ response = @carrier.find_tracking_info('123456789012', unique_identifier: '2456979001~123456789012~FX')
246
+ assert response.success?
247
+ refute response.delivered?
248
+ assert_equal '123456789012', response.tracking_number
249
+ assert_equal :in_transit, response.status
250
+ assert_equal 'IT', response.status_code
251
+ assert_equal "Package available for clearance", response.status_description
252
+ assert_equal 1, response.shipment_events.length
253
+ assert_nil response.actual_delivery_date
254
+ assert_equal nil, response.scheduled_delivery_date
255
+ end
256
+
257
+ def test_find_tracking_info_for_in_transit_shipment_2
258
+ # unfortunately, we have to use Fedex unique identifiers, because the test tracking numbers are overloaded.
259
+ response = @carrier.find_tracking_info('123456789012', unique_identifier: '2456979000~123456789012~FX')
260
+ assert response.success?
261
+ refute response.delivered?
262
+ assert_equal '123456789012', response.tracking_number
263
+ assert_equal :in_transit, response.status
264
+ assert_equal 'IT', response.status_code
265
+ assert_equal "In transit", response.status_description
266
+
267
+ assert_equal Time.parse('2014-11-25T20:04:00Z'), response.ship_time
268
+ assert_equal nil, response.scheduled_delivery_date
269
+ assert_equal nil, response.actual_delivery_date
270
+
271
+ assert_equal nil, response.origin
272
+
273
+ destination_address = ActiveShipping::Location.new(
274
+ city: 'TONNESSEE',
275
+ country: 'US',
276
+ state: 'TN'
277
+ )
278
+ assert_equal destination_address.to_hash, response.destination.to_hash
279
+ assert_equal 9, response.shipment_events.length
280
+ end
281
+
282
+ def test_find_tracking_info_with_multiple_matches
283
+ exception = assert_raises(ActiveShipping::Error) do
284
+ response = @carrier.find_tracking_info('123456789012')
285
+ end
286
+ assert_match 'Multiple matches were found.', exception.message
287
+ end
288
+
289
+ def test_find_tracking_info_not_found
290
+ assert_raises(ActiveShipping::ShipmentNotFound) do
291
+ @carrier.find_tracking_info('123456789013')
292
+ end
293
+ end
294
+
295
+ def test_find_tracking_info_with_invalid_tracking_number
296
+ assert_raises(ActiveShipping::ResponseError) do
297
+ @carrier.find_tracking_info('abc')
298
+ end
217
299
  end
218
300
  end