active_fulfillment 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_fulfillment.rb +4 -18
- data/lib/active_fulfillment/fulfillment/services/amazon_mws.rb +438 -0
- data/lib/active_fulfillment/fulfillment/services/shipwire.rb +39 -34
- data/lib/active_fulfillment/fulfillment/services/webgistix.rb +5 -1
- data/lib/active_fulfillment/fulfillment/version.rb +6 -0
- data/test/fixtures/xml/amazon_mws/fulfillment_get_fulfillment_order.xml +114 -0
- data/test/fixtures/xml/amazon_mws/fulfillment_get_fulfillment_order_2.xml +90 -0
- data/test/fixtures/xml/amazon_mws/fulfillment_get_fullfillment_order_with_multiple_tracking_numbers.xml +121 -0
- data/test/fixtures/xml/amazon_mws/fulfillment_list_all_fulfillment_orders.xml +70 -0
- data/test/fixtures/xml/amazon_mws/inventory_list_inventory_item_supply.xml +32 -0
- data/test/fixtures/xml/amazon_mws/inventory_list_inventory_supply.xml +75 -0
- data/test/fixtures/xml/amazon_mws/inventory_list_inventory_supply_by_next_token.xml +38 -0
- data/test/fixtures/xml/amazon_mws/tracking_response_error.xml +9 -0
- data/test/fixtures/xml/amazon_mws/tracking_response_not_found.xml +9 -0
- data/test/fixtures/xml/shipwire/fulfillment_failure_response.xml +7 -0
- data/test/fixtures/xml/shipwire/invalid_login_response.xml +7 -0
- data/test/fixtures/xml/shipwire/inventory_get_response.xml +44 -0
- data/test/fixtures/xml/shipwire/successful_empty_tracking_response.xml +8 -0
- data/test/fixtures/xml/shipwire/successful_live_tracking_response.xml +53 -0
- data/test/fixtures/xml/shipwire/successful_tracking_response.xml +16 -0
- data/test/fixtures/xml/shipwire/successful_tracking_response_with_tracking_urls.xml +31 -0
- data/test/fixtures/xml/webgistix/multiple_tracking_response.xml +21 -0
- data/test/remote/amazon_mws_test.rb +114 -0
- data/test/unit/services/amazon_mws_test.rb +357 -0
- data/test/unit/services/shipwire_test.rb +20 -95
- data/test/unit/services/webgistix_test.rb +12 -1
- metadata +57 -11
- data/Rakefile +0 -36
- data/VERSION +0 -1
- data/active_fulfillment.gemspec +0 -70
- data/init.rb +0 -1
@@ -0,0 +1,357 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class AmazonMarketplaceWebServiceTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@service = AmazonMarketplaceWebService.new(
|
6
|
+
:login => 'l',
|
7
|
+
:password => 'p'
|
8
|
+
)
|
9
|
+
|
10
|
+
@options = {
|
11
|
+
:shipping_method => 'Standard',
|
12
|
+
:order_date => Time.now.utc.yesterday,
|
13
|
+
:comment => "Delayed due to tornados"
|
14
|
+
}
|
15
|
+
|
16
|
+
@address = {
|
17
|
+
:name => 'Johnny Chase',
|
18
|
+
:address1 => '100 Information Super Highway',
|
19
|
+
:address2 => 'Suite 66',
|
20
|
+
:city => 'Beverly Hills',
|
21
|
+
:state => 'CA',
|
22
|
+
:country => 'US',
|
23
|
+
:zip => '90210',
|
24
|
+
:phone => "(555)555-5555"
|
25
|
+
}
|
26
|
+
|
27
|
+
@line_items = [
|
28
|
+
{ :sku => 'SETTLERS1',
|
29
|
+
:quantity => 1,
|
30
|
+
:comment => 'Awesome'
|
31
|
+
}
|
32
|
+
]
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_get_default_fulfillment_gateway
|
36
|
+
assert_equal AmazonMarketplaceWebService::ENDPOINTS[:us], @service.endpoint
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_create_service_with_different_fulfillment_gateway
|
40
|
+
service = AmazonMarketplaceWebService.new(:login => 'l', :password => 'p', :endpoint => :jp)
|
41
|
+
assert_equal AmazonMarketplaceWebService::ENDPOINTS[:jp], service.endpoint
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_build_basic_api_query
|
45
|
+
options = {
|
46
|
+
"Action" => "SubmitFeed",
|
47
|
+
"FeedType" => "_POST_INVENTORY_AVAILABILITY_DATA_",
|
48
|
+
"Merchant" => "SuperMerchant123"
|
49
|
+
}
|
50
|
+
expected_keys = ["AWSAccessKeyId", "Action", "FeedType", "Merchant", "SignatureMethod", "SignatureVersion", "Timestamp", "Version"]
|
51
|
+
opts = @service.build_basic_api_query(options)
|
52
|
+
assert_equal expected_keys.sort, opts.keys.map(&:to_s).sort
|
53
|
+
assert_equal "l", opts["AWSAccessKeyId"]
|
54
|
+
assert_equal AmazonMarketplaceWebService::SIGNATURE_VERSION, opts["SignatureVersion"]
|
55
|
+
assert_equal "Hmac#{AmazonMarketplaceWebService::SIGNATURE_METHOD}", opts["SignatureMethod"]
|
56
|
+
assert_equal AmazonMarketplaceWebService::VERSION, opts["Version"]
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_build_inventory_list_request
|
60
|
+
skus = ["CITADELS", "INNOVATION", "JAIPUR"]
|
61
|
+
request_params = @service.build_inventory_list_request(:skus => skus)
|
62
|
+
keys = request_params.keys
|
63
|
+
|
64
|
+
assert keys.include?("SellerSkus.member.1")
|
65
|
+
assert keys.include?("SellerSkus.member.2")
|
66
|
+
assert keys.include?("SellerSkus.member.3")
|
67
|
+
assert_equal 'CITADELS', request_params['SellerSkus.member.1']
|
68
|
+
assert_equal 'INNOVATION', request_params['SellerSkus.member.2']
|
69
|
+
assert_equal 'JAIPUR', request_params["SellerSkus.member.3"]
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_create_signature
|
73
|
+
service = AmazonMarketplaceWebService.new(:login => "0PExampleR2", :password => "sekrets")
|
74
|
+
expected_signature = "39XxH6iKLysjjDmWZSkyr2z8iSxfECHBYE1Pd0Qqpwo%3D"
|
75
|
+
options = {
|
76
|
+
"AWSAccessKeyId" => "0PExampleR2",
|
77
|
+
"Action" => "SubmitFeed",
|
78
|
+
"FeedType" => "_POST_INVENTORY_AVAILABILITY_DATA_",
|
79
|
+
"Marketplace" => "ATExampleER",
|
80
|
+
"Merchant" => "A1ExampleE6",
|
81
|
+
"SignatureMethod" => "HmacSHA256",
|
82
|
+
"SignatureVersion" => "2",
|
83
|
+
"Timestamp" => "2009-08-20T01:10:27.607Z",
|
84
|
+
"Version" => "2009-01-01"
|
85
|
+
}
|
86
|
+
|
87
|
+
uri = URI.parse("https://#{AmazonMarketplaceWebService::ENDPOINTS[:us]}")
|
88
|
+
|
89
|
+
assert_equal expected_signature, service.sign(:POST, uri, options)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_verify_amazon_response
|
93
|
+
service = AmazonMarketplaceWebService.new(:login => "AKIAFJPPO5KLY6G4XO7Q", :password => "aaa")
|
94
|
+
string_signed_by_amazon = "POST\nhttps://www.vendor.com/mwsApp1\n/orders/listRecentOrders.jsp?sessionId=123"
|
95
|
+
string_signed_by_amazon += "\nAWSAccessKeyId=AKIAFJPPO5KLY6G4XO7Q&Marketplace=ATVPDKIKX0DER&Merchant=A047950713KM6AGKQCBRD&SignatureMethod=HmacSHA256&SignatureVersion=2"
|
96
|
+
assert service.amazon_request?(string_signed_by_amazon, "b0hxWov1RfBOqNk77UDfNRRZmf3tkdM7vuNa%2FolfnWg%3D")
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_build_address
|
100
|
+
expected_items = {
|
101
|
+
"DestinationAddress.Name" => @address[:name],
|
102
|
+
"DestinationAddress.Line1" => @address[:address1],
|
103
|
+
"DestinationAddress.Line2" => @address[:address2],
|
104
|
+
"DestinationAddress.City" => @address[:city],
|
105
|
+
"DestinationAddress.StateOrProvinceCode" => @address[:state],
|
106
|
+
"DestinationAddress.CountryCode" => @address[:country],
|
107
|
+
"DestinationAddress.PostalCode" => @address[:zip],
|
108
|
+
"DestinationAddress.PhoneNumber" => @address[:phone]
|
109
|
+
}
|
110
|
+
assert_equal expected_items, @service.build_address(@address)
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_build_address_with_missing_fields
|
114
|
+
expected_items = {
|
115
|
+
"DestinationAddress.Name" => @address[:name],
|
116
|
+
"DestinationAddress.Line1" => @address[:address1],
|
117
|
+
"DestinationAddress.City" => @address[:city],
|
118
|
+
"DestinationAddress.StateOrProvinceCode" => @address[:state],
|
119
|
+
"DestinationAddress.CountryCode" => @address[:country],
|
120
|
+
"DestinationAddress.PostalCode" => @address[:zip],
|
121
|
+
"DestinationAddress.PhoneNumber" => @address[:phone]
|
122
|
+
}
|
123
|
+
@address[:address2] = ""
|
124
|
+
|
125
|
+
assert_equal expected_items, @service.build_address(@address)
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_integrated_registration_url_creation
|
129
|
+
service = AmazonMarketplaceWebService.new(:login => "AKIAFJPPO5KLY6G4XO7Q", :password => "aaa", :app_id => "1014f5ad-c359-4e86-8e50-bb8f8e431a9")
|
130
|
+
options = {
|
131
|
+
"returnPathAndParameters" => "/orders/listRecentOrders.jsp?sessionId=123"
|
132
|
+
}
|
133
|
+
expected_registration_url = "#{AmazonMarketplaceWebService::REGISTRATION_URI.to_s}?AWSAccessKeyId=AKIAFJPPO5KLY6G4XO7Q&SignatureMethod=HmacSHA256&SignatureVersion=2&id=1014f5ad-c359-4e86-8e50-bb8f8e431a9&returnPathAndParameters=%2Forders%2FlistRecentOrders.jsp%3FsessionId%3D123&Signature=zpZyHd8rMf5gg5rpO5ri5RGUi0kks03ZkhAtPm4npVk%3D"
|
134
|
+
assert_equal expected_registration_url, service.registration_url(options)
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_build_items
|
138
|
+
expected_items = {
|
139
|
+
"Items.member.1.DisplayableComment" => "Awesome",
|
140
|
+
"Items.member.1.Quantity" => 1,
|
141
|
+
"Items.member.1.SellerFulfillmentOrderItemId" => "SETTLERS1",
|
142
|
+
"Items.member.1.SellerSKU" => "SETTLERS1"
|
143
|
+
}
|
144
|
+
|
145
|
+
actual_items = @service.build_items(@line_items)
|
146
|
+
|
147
|
+
assert_equal expected_items, @service.build_items(@line_items)
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_successful_fulfillment
|
151
|
+
@service.expects(:ssl_post).returns(successful_fulfillment_response)
|
152
|
+
response = @service.fulfill('12345678', @address, @line_items, @options)
|
153
|
+
assert response.success?
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_invalid_arguments
|
157
|
+
http_response = build_mock_response(invalid_params_response, "", 500)
|
158
|
+
@service.expects(:ssl_post).raises(ActiveMerchant::ResponseError.new(http_response))
|
159
|
+
response = @service.fulfill('12345678', @address, @line_items, @options)
|
160
|
+
assert !response.success?
|
161
|
+
assert_equal "MalformedInput: timestamp must follow ISO8601", response.params['response_comment']
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_missing_order_date
|
165
|
+
@options.delete(:order_date)
|
166
|
+
assert_raise(ArgumentError) { @service.fulfill('12345678', @address, @line_items, @options) }
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_missing_shipping_method
|
170
|
+
@options.delete(:shipping_method)
|
171
|
+
assert_raise(ArgumentError) { @service.fulfill('12345678', @address, @line_items, @options) }
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_get_service_status
|
175
|
+
@service.expects(:ssl_post).returns(successful_status_response)
|
176
|
+
|
177
|
+
response = @service.status
|
178
|
+
assert response.success?
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_get_inventory
|
182
|
+
@service.expects(:ssl_post).returns(xml_fixture('amazon_mws/inventory_list_inventory_supply'))
|
183
|
+
|
184
|
+
response = @service.fetch_stock_levels
|
185
|
+
assert response.success?
|
186
|
+
assert_equal 202, response.stock_levels['GN-00-01A']
|
187
|
+
assert_equal 199, response.stock_levels['GN-00-02A']
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_get_inventory_multipage
|
191
|
+
@service.expects(:ssl_post).with() { |uri, query, headers|
|
192
|
+
query.include?('ListInventorySupply') && !query.include?('ListInventorySupplyByNextToken')
|
193
|
+
}.returns(xml_fixture('amazon_mws/inventory_list_inventory_supply_by_next_token'))
|
194
|
+
|
195
|
+
@service.expects(:ssl_post).with() { |uri, query, headers|
|
196
|
+
query.include?('ListInventorySupplyByNextToken') && query.include?('NextToken')
|
197
|
+
}.returns(xml_fixture('amazon_mws/inventory_list_inventory_supply'))
|
198
|
+
|
199
|
+
response = @service.fetch_stock_levels
|
200
|
+
assert response.success?
|
201
|
+
|
202
|
+
assert_equal 202, response.stock_levels['GN-00-01A']
|
203
|
+
assert_equal 199, response.stock_levels['GN-00-02A']
|
204
|
+
assert_equal 0, response.stock_levels['GN-01-01A']
|
205
|
+
assert_equal 5259, response.stock_levels['GN-01-02A']
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_get_next_page_builds_query_with_proper_params
|
209
|
+
@service.expects(:build_basic_api_query).with(:NextToken => "abracadabra", :Action => 'ListInventorySupplyByNextToken')
|
210
|
+
@service.send(:build_next_inventory_list_request, "abracadabra")
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_fetch_tracking_numbers
|
214
|
+
@service.expects(:ssl_post).twice.
|
215
|
+
returns(xml_fixture('amazon_mws/fulfillment_get_fulfillment_order')).
|
216
|
+
returns(xml_fixture('amazon_mws/fulfillment_get_fulfillment_order_2'))
|
217
|
+
|
218
|
+
response = @service.fetch_tracking_numbers(['extern_id_1154539615776', 'extern_id_1154539615777'])
|
219
|
+
assert response.success?
|
220
|
+
assert_equal %w{93ZZ00}, response.tracking_numbers['extern_id_1154539615776']
|
221
|
+
assert_nil response.tracking_numbers['extern_id_1154539615777']
|
222
|
+
end
|
223
|
+
|
224
|
+
|
225
|
+
def test_fetch_multiple_tracking_numbers
|
226
|
+
@service.expects(:ssl_post).returns(xml_fixture('amazon_mws/fulfillment_get_fullfillment_order_with_multiple_tracking_numbers'))
|
227
|
+
|
228
|
+
response = @service.fetch_tracking_numbers(['extern_id_1154539615776'])
|
229
|
+
assert response.success?
|
230
|
+
assert_equal %w{93YY00 93ZZ00}, response.tracking_numbers['extern_id_1154539615776']
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_that_generated_requests_do_not_double_escape_spaces
|
234
|
+
fulfillment_request = @service.send(:build_fulfillment_request, "12345", @address, @line_items, @options)
|
235
|
+
result = @service.build_full_query(:post, URI.parse("http://example.com/someservice/2011"), fulfillment_request)
|
236
|
+
|
237
|
+
assert !result.include?('%2520')
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_fetch_tracking_numbers_ignores_not_found
|
241
|
+
response = mock('response')
|
242
|
+
response.stubs(:code).returns(500)
|
243
|
+
response.stubs(:message).returns("Internal Server Error")
|
244
|
+
response.stubs(:body).returns(xml_fixture('amazon_mws/tracking_response_not_found'))
|
245
|
+
|
246
|
+
@service.expects(:ssl_post).times(3).
|
247
|
+
returns(xml_fixture('amazon_mws/fulfillment_get_fulfillment_order')).
|
248
|
+
raises(ActiveMerchant::ResponseError.new(response)).
|
249
|
+
returns(xml_fixture('amazon_mws/fulfillment_get_fulfillment_order_2'))
|
250
|
+
|
251
|
+
response = @service.fetch_tracking_numbers(['extern_id_1154539615776', 'dafdfafsdafdafasdfa', 'extern_id_1154539615777'])
|
252
|
+
assert response.success?
|
253
|
+
assert_equal %w{93ZZ00}, response.tracking_numbers['extern_id_1154539615776']
|
254
|
+
end
|
255
|
+
|
256
|
+
def test_fetch_tracking_numbers_aborts_on_error
|
257
|
+
response = mock('response')
|
258
|
+
response.stubs(:code).returns(500)
|
259
|
+
response.stubs(:message).returns("Internal Server Error")
|
260
|
+
response.stubs(:body).returns(xml_fixture('amazon_mws/tracking_response_error'))
|
261
|
+
|
262
|
+
@service.expects(:ssl_post).twice.
|
263
|
+
returns(xml_fixture('amazon_mws/fulfillment_get_fulfillment_order')).
|
264
|
+
raises(ActiveMerchant::ResponseError.new(response))
|
265
|
+
|
266
|
+
response = @service.fetch_tracking_numbers(['extern_id_1154539615776', 'ERROR', 'extern_id_1154539615777'])
|
267
|
+
assert !response.success?
|
268
|
+
assert_equal 'Something has gone terribly wrong!', response.faultstring
|
269
|
+
end
|
270
|
+
|
271
|
+
def test_404_error
|
272
|
+
http_response = build_mock_response(response_from_404, "Not Found", "404")
|
273
|
+
@service.expects(:ssl_post).raises(ActiveMerchant::ResponseError.new(http_response))
|
274
|
+
|
275
|
+
response = @service.fulfill('987654321', @address, @line_items, @options)
|
276
|
+
assert !response.success?
|
277
|
+
|
278
|
+
assert_equal "404: Not Found", response.response_comment
|
279
|
+
assert_equal "404", response.http_code
|
280
|
+
assert_equal "Not Found", response.http_message
|
281
|
+
assert_equal response_from_404, response.http_body
|
282
|
+
end
|
283
|
+
|
284
|
+
def test_building_address_skips_nil_values
|
285
|
+
@address[:address2] = nil
|
286
|
+
assert_nothing_raised do
|
287
|
+
@service.send(:build_address, @address)
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
def test_building_a_full_query_does_not_cause_query_to_fail
|
292
|
+
@address[:company] = "Powerthirst Inc."
|
293
|
+
|
294
|
+
constructed_address = @service.send(:build_address, @address)
|
295
|
+
assert !constructed_address[nil]
|
296
|
+
end
|
297
|
+
|
298
|
+
private
|
299
|
+
def build_mock_response(response, message, code = "200")
|
300
|
+
http_response = mock(:code => code, :message => message)
|
301
|
+
http_response.stubs(:body).returns(response)
|
302
|
+
http_response
|
303
|
+
end
|
304
|
+
|
305
|
+
def successful_fulfillment_response
|
306
|
+
<<-XML
|
307
|
+
<?xml version="1.0"?>
|
308
|
+
<CreateFulfillmentOrderResponse
|
309
|
+
xmlns="http://mws.amazonaws.com/FulfillmentOutboundShipment/2010-10-01/">
|
310
|
+
<ResponseMetadata>
|
311
|
+
<RequestId>d95be26c-16cf-4bbc-ab58-dce89fd4ac53</RequestId>
|
312
|
+
</ResponseMetadata>
|
313
|
+
</CreateFulfillmentOrderResponse>
|
314
|
+
XML
|
315
|
+
end
|
316
|
+
|
317
|
+
def successful_status_response
|
318
|
+
<<-XML
|
319
|
+
<?xml version="1.0"?>
|
320
|
+
<GetServiceStatusResponse
|
321
|
+
xmlns="http://mws.amazonaws.com/FulfillmentOutboundShipment/2010-10-01/">
|
322
|
+
<GetServiceStatusResult>
|
323
|
+
<Status>GREEN_I</Status>
|
324
|
+
<Timestamp>2010-11-01T21:38:09.676Z</Timestamp>
|
325
|
+
<MessageId>173964729I</MessageId>
|
326
|
+
<Messages>
|
327
|
+
<Message>
|
328
|
+
<Locale>en_US</Locale>
|
329
|
+
<Text>We are experiencing high latency in UK because of heavy
|
330
|
+
traffic.</Text>
|
331
|
+
</Message>
|
332
|
+
</Messages>
|
333
|
+
</GetServiceStatusResult>
|
334
|
+
<ResponseMetadata>
|
335
|
+
<RequestId>d80c6c7b-f7c7-4fa7-bdd7-854711cb3bcc</RequestId>
|
336
|
+
</ResponseMetadata>
|
337
|
+
</GetServiceStatusResponse>
|
338
|
+
XML
|
339
|
+
end
|
340
|
+
|
341
|
+
def response_from_404
|
342
|
+
'<html><head><title>Apache Tomcat</title></head><body>That was not found</body></html>'
|
343
|
+
end
|
344
|
+
|
345
|
+
def invalid_params_response
|
346
|
+
<<-XML
|
347
|
+
<ErrorResponse xmlns="http://mws.amazonaws.com/FulfillmentInventory/2010-10-01/">
|
348
|
+
<Error>
|
349
|
+
<Type>Sender</Type>
|
350
|
+
<Code>MalformedInput</Code>
|
351
|
+
<Message>timestamp must follow ISO8601</Message>
|
352
|
+
</Error>
|
353
|
+
<RequestId>e71f72f5-3df6-4306-bb67-9f55bd9d9665</RequestId>
|
354
|
+
</ErrorResponse>
|
355
|
+
XML
|
356
|
+
end
|
357
|
+
end
|
@@ -98,6 +98,7 @@ class ShipwireTest < Test::Unit::TestCase
|
|
98
98
|
end
|
99
99
|
|
100
100
|
def test_no_tracking_numbers_available
|
101
|
+
successful_empty_tracking_response = xml_fixture('shipwire/successful_empty_tracking_response')
|
101
102
|
@shipwire.expects(:ssl_post).returns(successful_empty_tracking_response)
|
102
103
|
response = @shipwire.fetch_tracking_numbers(['1234'])
|
103
104
|
assert response.success?
|
@@ -108,6 +109,7 @@ class ShipwireTest < Test::Unit::TestCase
|
|
108
109
|
expected = { "2986" => ["1ZW682E90326614239"],
|
109
110
|
"2987" => ["1ZW682E90326795080"] }
|
110
111
|
|
112
|
+
successful_tracking_response = xml_fixture('shipwire/successful_tracking_response')
|
111
113
|
@shipwire.expects(:ssl_post).returns(successful_tracking_response)
|
112
114
|
response = @shipwire.fetch_tracking_numbers(["2986", "2987"])
|
113
115
|
assert response.success?
|
@@ -119,6 +121,7 @@ class ShipwireTest < Test::Unit::TestCase
|
|
119
121
|
end
|
120
122
|
|
121
123
|
def test_successful_tracking_with_live_data
|
124
|
+
successful_live_tracking_response = xml_fixture('shipwire/successful_live_tracking_response')
|
122
125
|
@shipwire.expects(:ssl_post).returns(successful_live_tracking_response)
|
123
126
|
response = @shipwire.fetch_tracking_numbers([
|
124
127
|
'21', '22', '23', '24', '25',
|
@@ -133,12 +136,28 @@ class ShipwireTest < Test::Unit::TestCase
|
|
133
136
|
assert_equal 13, response.tracking_numbers.size
|
134
137
|
end
|
135
138
|
|
139
|
+
def test_successful_tracking_with_urls
|
140
|
+
successful_tracking_response_with_urls = xml_fixture('shipwire/successful_tracking_response_with_tracking_urls')
|
141
|
+
@shipwire.expects(:ssl_post).returns(successful_tracking_response_with_urls)
|
142
|
+
response = @shipwire.fetch_tracking_numbers(["40289"])
|
143
|
+
assert response.success?
|
144
|
+
assert_equal "1", response.params["total_orders"]
|
145
|
+
assert_equal "Test", response.params["status"]
|
146
|
+
assert_equal "1", response.params["total_shipped_orders"]
|
147
|
+
|
148
|
+
assert_equal ["9400110200793596422990"], response.tracking_numbers["40298"]
|
149
|
+
assert_equal "USPS", response.tracking_company["40298"]
|
150
|
+
assert_equal ["http://trkcnfrm1.smi.usps.com/PTSInternetWeb/InterLabelInquiry.do?origTrackNum=9400110200793596422990"], response.tracking_urls["40298"]
|
151
|
+
end
|
152
|
+
|
136
153
|
def test_valid_credentials
|
137
|
-
|
154
|
+
successful_empty_tracing_response = xml_fixture('shipwire/successful_empty_tracking_response')
|
155
|
+
@shipwire.expects(:ssl_post).returns(successful_empty_tracing_response)
|
138
156
|
assert @shipwire.valid_credentials?
|
139
157
|
end
|
140
158
|
|
141
159
|
def test_invalid_credentials
|
160
|
+
invalid_login_response = xml_fixture('shipwire/invalid_login_response')
|
142
161
|
@shipwire.expects(:ssl_post).returns(invalid_login_response)
|
143
162
|
assert !@shipwire.valid_credentials?
|
144
163
|
end
|
@@ -175,98 +194,4 @@ class ShipwireTest < Test::Unit::TestCase
|
|
175
194
|
assert !@shipwire.valid_credentials?
|
176
195
|
end
|
177
196
|
|
178
|
-
private
|
179
|
-
def successful_empty_tracking_response
|
180
|
-
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n<TrackingUpdateResponse><Status>Test</Status><TotalOrders></TotalOrders><TotalShippedOrders></TotalShippedOrders><TotalProducts></TotalProducts><Bookmark></Bookmark></TrackingUpdateResponse>"
|
181
|
-
end
|
182
|
-
|
183
|
-
def successful_tracking_response
|
184
|
-
<<-XML
|
185
|
-
<?xml version="1.0"?>
|
186
|
-
<TrackingUpdateResponse>
|
187
|
-
<Status>Test</Status>
|
188
|
-
<Order id="2986" shipped="YES" shipper="UPS GD" handling="1.00" shipping="13.66" total="14.66">
|
189
|
-
<TrackingNumber>1ZW682E90326614239</TrackingNumber>
|
190
|
-
</Order>
|
191
|
-
<Order id="2987" shipped="YES" shipper="UPS GD" handling="1.50" shipping="9.37" total="10.87">
|
192
|
-
<TrackingNumber>1ZW682E90326795080</TrackingNumber>
|
193
|
-
</Order>
|
194
|
-
<Order id="2988" shipped="NO" shipper="UPS GD" handling="" shipping="" total="">
|
195
|
-
<TrackingNumber></TrackingNumber>
|
196
|
-
</Order>
|
197
|
-
<TotalOrders>3</TotalOrders>
|
198
|
-
<TotalShippedOrders>2</TotalShippedOrders>
|
199
|
-
<Bookmark>2006-04-28 20:35:45</Bookmark>
|
200
|
-
</TrackingUpdateResponse>
|
201
|
-
XML
|
202
|
-
end
|
203
|
-
|
204
|
-
def successful_live_tracking_response
|
205
|
-
<<-XML
|
206
|
-
<?xml version="1.0" encoding="ISO-8859-1"?>
|
207
|
-
<TrackingUpdateResponse>
|
208
|
-
<Status>0</Status>
|
209
|
-
<Order id="21" shipped="YES" shipper="5" handling="0.00" shipping="6.58" total="6.58">
|
210
|
-
<TrackingNumber>1Z6296VW0398500001</TrackingNumber>
|
211
|
-
</Order>
|
212
|
-
<Order id="22" shipped="YES" shipper="5" handling="0.00" shipping="8.13" total="8.13">
|
213
|
-
<TrackingNumber>1Z6296VW0390790002</TrackingNumber>
|
214
|
-
</Order>
|
215
|
-
<Order id="23" shipped="YES" shipper="5" handling="0.00" shipping="7.63" total="7.63">
|
216
|
-
<TrackingNumber>1Z6296VW0396490003</TrackingNumber>
|
217
|
-
</Order>
|
218
|
-
<Order id="24" shipped="YES" shipper="5" handling="0.00" shipping="8.97" total="8.97">
|
219
|
-
<TrackingNumber>1Z6296VW0390200004</TrackingNumber>
|
220
|
-
</Order>
|
221
|
-
<Order id="25" shipped="YES" shipper="5" handling="0.00" shipping="8.42" total="8.42">
|
222
|
-
<TrackingNumber>1Z6296VW0393240005</TrackingNumber>
|
223
|
-
</Order>
|
224
|
-
<Order id="26" shipped="YES" shipper="5" handling="0.00" shipping="8.42" total="8.42">
|
225
|
-
<TrackingNumber>1Z6296VW0396400006</TrackingNumber>
|
226
|
-
</Order>
|
227
|
-
<Order id="2581" shipped="YES" shipper="5" handling="0.00" shipping="8.21" total="8.21">
|
228
|
-
<TrackingNumber>1Z6296VW0391160007</TrackingNumber>
|
229
|
-
</Order>
|
230
|
-
<Order id="2576" shipped="YES" shipper="43" handling="0.00" shipping="18.60" total="18.60">
|
231
|
-
<TrackingNumber>CJ3026000018US</TrackingNumber>
|
232
|
-
</Order>
|
233
|
-
<Order id="2593" shipped="YES" shipper="5" handling="0.00" shipping="7.63" total="7.63">
|
234
|
-
<TrackingNumber>1Z6296VW0398660008</TrackingNumber>
|
235
|
-
</Order>
|
236
|
-
<Order id="2598" shipped="YES" shipper="5" handling="0.00" shipping="9.84" total="9.84">
|
237
|
-
<TrackingNumber>1Z6296VW0391610009</TrackingNumber>
|
238
|
-
</Order>
|
239
|
-
<Order id="2610" shipped="YES" shipper="5" handling="0.00" shipping="7.63" total="7.63">
|
240
|
-
<TrackingNumber>1Z6296VW0395650010</TrackingNumber>
|
241
|
-
</Order>
|
242
|
-
<Order id="2611" shipped="YES" shipper="5" handling="0.00" shipping="7.13" total="7.13">
|
243
|
-
<TrackingNumber>1Z6296VW0397050011</TrackingNumber>
|
244
|
-
</Order>
|
245
|
-
<Order id="2613" shipped="YES" shipper="5" handling="0.00" shipping="8.97" total="8.97">
|
246
|
-
<TrackingNumber>1Z6296VW0398970012</TrackingNumber>
|
247
|
-
</Order>
|
248
|
-
<Order id="2616" shipped="NO" shipper="5" handling="0.00" shipping="9.84" total="9.84">
|
249
|
-
<TrackingNumber></TrackingNumber>
|
250
|
-
</Order>
|
251
|
-
<Order id="2631" shipped="NO" shipper="" handling="" shipping="" total="">
|
252
|
-
<TrackingNumber></TrackingNumber>
|
253
|
-
</Order>
|
254
|
-
<TotalOrders>15</TotalOrders>
|
255
|
-
<TotalShippedOrders>13</TotalShippedOrders>
|
256
|
-
<TotalProducts/>
|
257
|
-
<Bookmark/>
|
258
|
-
</TrackingUpdateResponse>
|
259
|
-
|
260
|
-
XML
|
261
|
-
end
|
262
|
-
|
263
|
-
def invalid_login_response
|
264
|
-
<<-XML
|
265
|
-
<?xml version="1.0" encoding="ISO-8859-1"?>
|
266
|
-
<TrackingUpdateResponse><Status>Error</Status><ErrorMessage>
|
267
|
-
Error with Valid Username/EmailAddress and Password Required.
|
268
|
-
There is an error in XML document.
|
269
|
-
</ErrorMessage></TrackingUpdateResponse>
|
270
|
-
XML
|
271
|
-
end
|
272
197
|
end
|