active_fulfillment 2.0.2 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -0
- data/lib/active_fulfillment/fulfillment/service.rb +13 -6
- data/lib/active_fulfillment/fulfillment/services/amazon.rb +62 -51
- data/lib/active_fulfillment/fulfillment/services/amazon_mws.rb +35 -23
- data/lib/active_fulfillment/fulfillment/services/shipwire.rb +8 -6
- data/lib/active_fulfillment/fulfillment/services/webgistix.rb +76 -66
- data/lib/active_fulfillment/fulfillment/version.rb +1 -1
- data/test/remote/amazon_mws_test.rb +17 -10
- data/test/remote/amazon_test.rb +22 -15
- data/test/remote/shipwire_test.rb +36 -28
- data/test/remote/webgistix_test.rb +25 -16
- data/test/unit/services/amazon_mws_test.rb +36 -11
- data/test/unit/services/amazon_test.rb +46 -36
- data/test/unit/services/shipwire_test.rb +22 -22
- data/test/unit/services/webgistix_test.rb +45 -33
- metadata +1 -1
@@ -3,16 +3,16 @@ require 'test_helper'
|
|
3
3
|
class WebgistixTest < Test::Unit::TestCase
|
4
4
|
def setup
|
5
5
|
Base.mode = :test
|
6
|
-
|
6
|
+
|
7
7
|
@service = WebgistixService.new(
|
8
8
|
:login => 'cody@example.com',
|
9
9
|
:password => 'test'
|
10
10
|
)
|
11
|
-
|
12
|
-
@options = {
|
11
|
+
|
12
|
+
@options = {
|
13
13
|
:shipping_method => 'UPS Ground'
|
14
14
|
}
|
15
|
-
|
15
|
+
|
16
16
|
@address = { :name => 'Fred Brooks',
|
17
17
|
:address1 => '1234 Penny Lane',
|
18
18
|
:city => 'Jonsetown',
|
@@ -21,32 +21,32 @@ class WebgistixTest < Test::Unit::TestCase
|
|
21
21
|
:zip => '23456',
|
22
22
|
:email => 'buyer@jadedpallet.com'
|
23
23
|
}
|
24
|
-
|
24
|
+
|
25
25
|
@line_items = [
|
26
26
|
{ :sku => '9999',
|
27
27
|
:quantity => 25
|
28
28
|
}
|
29
29
|
]
|
30
|
-
end
|
31
|
-
|
30
|
+
end
|
31
|
+
|
32
32
|
def test_missing_login
|
33
33
|
assert_raise(ArgumentError) do
|
34
34
|
WebgistixService.new(:password => 'test')
|
35
35
|
end
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
def test_missing_password
|
39
39
|
assert_raise(ArgumentError) do
|
40
40
|
WebgistixService.new(:login => 'cody')
|
41
41
|
end
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def test_missing_credentials
|
45
45
|
assert_raise(ArgumentError) do
|
46
46
|
WebgistixService.new(:password => 'test')
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def test_credentials_present
|
51
51
|
assert_nothing_raised do
|
52
52
|
WebgistixService.new(
|
@@ -55,36 +55,36 @@ class WebgistixTest < Test::Unit::TestCase
|
|
55
55
|
)
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
def test_successful_fulfillment
|
60
60
|
@service.expects(:ssl_post).returns(successful_response)
|
61
|
-
|
61
|
+
|
62
62
|
response = @service.fulfill('123456', @address, @line_items, @options)
|
63
63
|
assert response.success?
|
64
64
|
assert response.test?
|
65
65
|
assert_equal WebgistixService::SUCCESS_MESSAGE, response.message
|
66
66
|
assert_equal '619669', response.params['order_id']
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
def test_minimal_successful_fulfillment
|
70
70
|
@service.expects(:ssl_post).returns(minimal_successful_response)
|
71
|
-
|
71
|
+
|
72
72
|
response = @service.fulfill('123456', @address, @line_items, @options)
|
73
73
|
assert response.success?
|
74
74
|
assert response.test?
|
75
75
|
assert_equal WebgistixService::SUCCESS_MESSAGE, response.message
|
76
76
|
assert_nil response.params['order_id']
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
def test_failed_fulfillment
|
80
80
|
@service.expects(:ssl_post).returns(failure_response)
|
81
|
-
|
81
|
+
|
82
82
|
response = @service.fulfill('123456', @address, @line_items, @options)
|
83
83
|
assert !response.success?
|
84
84
|
assert response.test?
|
85
85
|
assert_equal WebgistixService::FAILURE_MESSAGE, response.message
|
86
86
|
assert_nil response.params['order_id']
|
87
|
-
|
87
|
+
|
88
88
|
assert_equal 'No Address Line 1', response.params['error_0']
|
89
89
|
assert_equal 'Unknown ItemID: testitem', response.params['error_1']
|
90
90
|
assert_equal 'Unknown ItemID: WX-01-1000', response.params['error_2']
|
@@ -92,7 +92,7 @@ class WebgistixTest < Test::Unit::TestCase
|
|
92
92
|
|
93
93
|
def test_stock_levels
|
94
94
|
@service.expects(:ssl_post).returns(inventory_response)
|
95
|
-
|
95
|
+
|
96
96
|
response = @service.fetch_stock_levels
|
97
97
|
assert response.success?
|
98
98
|
assert_equal WebgistixService::SUCCESS_MESSAGE, response.message
|
@@ -102,7 +102,7 @@ class WebgistixTest < Test::Unit::TestCase
|
|
102
102
|
|
103
103
|
def test_tracking_numbers
|
104
104
|
@service.expects(:ssl_post).returns(xml_fixture('webgistix/tracking_response'))
|
105
|
-
|
105
|
+
|
106
106
|
response = @service.fetch_tracking_numbers(['AB12345', 'XY4567'])
|
107
107
|
assert response.success?
|
108
108
|
assert_equal WebgistixService::SUCCESS_MESSAGE, response.message
|
@@ -121,38 +121,50 @@ class WebgistixTest < Test::Unit::TestCase
|
|
121
121
|
assert_equal ['345678070437428', '546932544227'], response.tracking_numbers[invoice_number]
|
122
122
|
end
|
123
123
|
|
124
|
+
def test_tracking_data
|
125
|
+
@service.expects(:ssl_post).returns(xml_fixture('webgistix/tracking_response'))
|
126
|
+
|
127
|
+
response = @service.fetch_tracking_data(['AB12345', 'XY4567'])
|
128
|
+
|
129
|
+
assert response.success?
|
130
|
+
assert_equal WebgistixService::SUCCESS_MESSAGE, response.message
|
131
|
+
assert_equal ['1Z8E5A380396682872'], response.tracking_numbers['AB12345']
|
132
|
+
assert_equal ['UPS'], response.tracking_companies['AB12345']
|
133
|
+
assert_equal({}, response.tracking_urls)
|
134
|
+
end
|
135
|
+
|
124
136
|
def test_failed_login
|
125
137
|
@service.expects(:ssl_post).returns(invalid_login_response)
|
126
|
-
|
138
|
+
|
127
139
|
response = @service.fulfill('123456', @address, @line_items, @options)
|
128
140
|
assert !response.success?
|
129
141
|
assert response.test?
|
130
142
|
assert_equal 'Invalid Credentials', response.message
|
131
143
|
assert_nil response.params['order_id']
|
132
|
-
|
144
|
+
|
133
145
|
assert_equal 'Invalid Credentials', response.params['error_0']
|
134
146
|
end
|
135
|
-
|
147
|
+
|
136
148
|
def test_garbage_response
|
137
149
|
@service.expects(:ssl_post).returns(garbage_response)
|
138
|
-
|
150
|
+
|
139
151
|
response = @service.fulfill('123456', @address, @line_items, @options)
|
140
152
|
assert !response.success?
|
141
153
|
assert response.test?
|
142
154
|
assert_equal WebgistixService::FAILURE_MESSAGE, response.message
|
143
155
|
assert_nil response.params['order_id']
|
144
156
|
end
|
145
|
-
|
157
|
+
|
146
158
|
def test_valid_credentials
|
147
159
|
@service.expects(:ssl_post).returns(failure_response)
|
148
160
|
assert @service.valid_credentials?
|
149
161
|
end
|
150
|
-
|
162
|
+
|
151
163
|
def test_invalid_credentials
|
152
164
|
@service.expects(:ssl_post).returns(invalid_login_response)
|
153
165
|
assert !@service.valid_credentials?
|
154
166
|
end
|
155
|
-
|
167
|
+
|
156
168
|
def test_duplicate_response_is_treated_as_success
|
157
169
|
response = stub(:code => 200, :body => duplicate_response, :message => '')
|
158
170
|
Net::HTTP.any_instance.stubs(:post).raises(ActiveMerchant::ConnectionError).returns(response)
|
@@ -168,35 +180,35 @@ class WebgistixTest < Test::Unit::TestCase
|
|
168
180
|
def test_ensure_gateway_uses_safe_retry
|
169
181
|
assert @service.retry_safe
|
170
182
|
end
|
171
|
-
|
183
|
+
|
172
184
|
private
|
173
185
|
def minimal_successful_response
|
174
186
|
'<Completed><Success>True</Success></Completed>'
|
175
187
|
end
|
176
|
-
|
188
|
+
|
177
189
|
def successful_response
|
178
190
|
'<Completed><Success>True</Success><OrderID>619669</OrderID></Completed>'
|
179
191
|
end
|
180
|
-
|
192
|
+
|
181
193
|
def invalid_login_response
|
182
194
|
'<Errors><Error>Invalid Credentials</Error></Errors>'
|
183
195
|
end
|
184
|
-
|
196
|
+
|
185
197
|
def failure_response
|
186
198
|
'<Errors><Error>No Address Line 1</Error><Error>Unknown ItemID: testitem</Error><Error>Unknown ItemID: WX-01-1000</Error></Errors>'
|
187
199
|
end
|
188
|
-
|
200
|
+
|
189
201
|
def garbage_response
|
190
202
|
'<font face="Arial" size=2>/XML/shippingTest.asp</font><font face="Arial" size=2>, line 39</font>'
|
191
203
|
end
|
192
|
-
|
204
|
+
|
193
205
|
def inventory_response
|
194
206
|
'<InventoryXML>' +
|
195
207
|
'<Item><ItemID>GN-00-01A</ItemID><ItemQty>202</ItemQty></Item>' +
|
196
208
|
'<Item><ItemID>GN-00-02A</ItemID><ItemQty>199</ItemQty></Item>' +
|
197
209
|
'</InventoryXML>'
|
198
210
|
end
|
199
|
-
|
211
|
+
|
200
212
|
def duplicate_response
|
201
213
|
'<Completed><Success>Duplicate</Success></Completed>'
|
202
214
|
end
|