active_fulfillment 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: edee633e1484a24673765631ab0a8a85cb114f4d
4
- data.tar.gz: 1b3c6f2099542ca7f988a0a7ac9ee9f3309cc809
3
+ metadata.gz: c0398fdadc0a5d2c85eda230851fe5727c07b63e
4
+ data.tar.gz: c3084c84d669ea956856716bc0f32388d27039d7
5
5
  SHA512:
6
- metadata.gz: 21c48116701f5281c5a4deacc5a445126e12b6e407551fc097709d579231a31d74944e88eb404b476bc2667d073686717dbce7c79388608600f73445b10a2538
7
- data.tar.gz: 90872e2cce274d7bc42593f93da678bf8a234fed5c4b12d3bf4e83d8ae665ab046cf22c7ded2e26fb8f1425aa0a108d256c61ca7060f3434268e1c713bc81b31
6
+ metadata.gz: 86f6821811d3c3b32b83bb29ec9b1e49f2a45ede0d2296f72940a732dec6f773aa3835b2e691421aef1f44b0654fdff32be8feb5da4afbe6e49202453d005435
7
+ data.tar.gz: f35bcd2587f11e1ebc2e0e5189cfe9dbb373ed26db88b6773de13a906d3b2cf7c9d9b2911ae94fbabb18a8e2dc77b3dff5dd264c280a67a8211ff7904ba6e606
@@ -168,7 +168,7 @@ module ActiveFulfillment
168
168
  query = build_full_query(verb, uri, params)
169
169
  headers = build_headers(query)
170
170
  log_query = query.dup
171
- [@options[:login], @options[:app_id], @mws_auth_token].each { |key| log_query.gsub!(/#{key}/, '[filtered]') if key.present? }
171
+ [@options[:login], @options[:app_id], @mws_auth_token].each { |key| log_query.gsub!(key.to_s, '[filtered]') if key.present? }
172
172
 
173
173
  logger.info "[#{self.class}][#{action}] query=#{log_query}"
174
174
  data = ssl_post(uri.to_s, query, headers)
@@ -171,7 +171,11 @@ module ActiveFulfillment
171
171
  end
172
172
 
173
173
  def commit(action, request)
174
+ log_query = request.dup
175
+ [@options[:password], affiliate_id].each { |key| log_query.gsub!(key.to_s, '[filtered]') if key.present? }
176
+ logger.info "[#{self.class}][#{SERVICE_URLS[action]}][#{POST_VARS[action]}] query=#{log_query}"
174
177
  data = ssl_post(SERVICE_URLS[action], "#{POST_VARS[action]}=#{CGI.escape(request)}")
178
+ logger.info "[#{self.class}][result] #{data}"
175
179
 
176
180
  response = parse_response(action, data)
177
181
  Response.new(response[:success], response[:message], response, :test => test?)
@@ -220,8 +224,8 @@ module ActiveFulfillment
220
224
  response = { stock_levels: {} }
221
225
  Parsing.with_xml_document(xml, response) do |document|
222
226
  status = document.at_xpath('//Status'.freeze).child.content
223
- total_products = document.at_xpath('//TotalProducts'.freeze).child.content
224
227
  success = test? ? status == 'Test'.freeze : status == '0'.freeze
228
+ total_products = success ? document.at_xpath('//TotalProducts'.freeze).child.content : 0
225
229
  message = success ? 'Successfully received the stock levels'.freeze : document.at_xpath('//ErrorMessage'.freeze).child.content
226
230
 
227
231
  {
@@ -51,7 +51,7 @@ module ActiveFulfillment
51
51
  end
52
52
 
53
53
  def fetch_tracking_data(order_numbers, options = {})
54
- options.merge!({:order_ids => order_numbers, :order_names => order_numbers})
54
+ options.merge!({:order_names => order_numbers})
55
55
  response = send_app_request('fetch_tracking_numbers'.freeze, options.delete(:headers), options)
56
56
  if response
57
57
  tracking_numbers = parse_response(response, 'TrackingNumbers'.freeze, 'Order'.freeze, 'ID'.freeze, 'Tracking'.freeze) { |o| o }
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module ActiveFulfillment
3
- VERSION = "3.0.1"
3
+ VERSION = "3.0.2"
4
4
  end
data/test/test_helper.rb CHANGED
@@ -5,7 +5,6 @@ require 'active_fulfillment'
5
5
  require 'minitest/autorun'
6
6
  require 'mocha/setup'
7
7
  require 'timecop'
8
- require 'rexml/document'
9
8
 
10
9
  require 'logger'
11
10
  ActiveFulfillment::Service.logger = Logger.new(nil)
@@ -3,12 +3,14 @@ require 'test_helper'
3
3
  class ShipwireTest < Minitest::Test
4
4
  include ActiveFulfillment::Test::Fixtures
5
5
 
6
+ PASSWORD = 'test_password'
7
+
6
8
  def setup
7
9
  ActiveFulfillment::Base.mode = :test
8
10
 
9
11
  @shipwire = ActiveFulfillment::ShipwireService.new(
10
12
  :login => 'cody@example.com',
11
- :password => 'test'
13
+ :password => PASSWORD
12
14
  )
13
15
 
14
16
  @options = {
@@ -32,7 +34,7 @@ class ShipwireTest < Minitest::Test
32
34
 
33
35
  def test_missing_login
34
36
  assert_raises(ArgumentError) do
35
- ActiveFulfillment::ShipwireService.new(:password => 'test')
37
+ ActiveFulfillment::ShipwireService.new(:password => PASSWORD)
36
38
  end
37
39
  end
38
40
 
@@ -44,20 +46,20 @@ class ShipwireTest < Minitest::Test
44
46
 
45
47
  def test_missing_credentials
46
48
  assert_raises(ArgumentError) do
47
- ActiveFulfillment::ShipwireService.new(:password => 'test')
49
+ ActiveFulfillment::ShipwireService.new(:password => PASSWORD)
48
50
  end
49
51
  end
50
52
 
51
53
  def test_credentials_present
52
54
  assert ActiveFulfillment::ShipwireService.new(
53
55
  :login => 'cody',
54
- :password => 'test'
56
+ :password => PASSWORD
55
57
  )
56
58
  end
57
59
 
58
60
  def test_country_format
59
- xml = REXML::Document.new(@shipwire.send(:build_fulfillment_request, '123456', @address, @line_items, @options))
60
- country_node = REXML::XPath.first(xml, "//Country")
61
+ xml = Nokogiri::XML(@shipwire.send(:build_fulfillment_request, '123456', @address, @line_items, @options))
62
+ country_node = xml.at_xpath(xml, "//Country")
61
63
  assert_equal 'US', country_node.text
62
64
  end
63
65
 
@@ -71,6 +73,36 @@ class ShipwireTest < Minitest::Test
71
73
  assert_equal 677, response.stock_levels['KingMonkey']
72
74
  end
73
75
 
76
+ def test_stock_levels_parses_invalid_credentials
77
+ @shipwire.expects(:ssl_post).returns(xml_fixture('shipwire/invalid_login_inventory_update_response'))
78
+
79
+ response = @shipwire.fetch_stock_levels
80
+ refute response.success?
81
+ assert_equal 'Error with Valid Username/EmailAddress and Password Required. There is an error in XML document.', response.message
82
+ end
83
+
84
+ def test_stock_levels_logs_request_and_response
85
+ @shipwire.class.logger.expects(:info).with do |message|
86
+ assert_match /InventoryUpdate/, message unless message.include?('InventoryUpdateResponse')
87
+ refute message.include?(PASSWORD)
88
+ true
89
+ end.twice
90
+
91
+ @shipwire.expects(:ssl_post).returns(xml_fixture('shipwire/inventory_get_response'))
92
+ response = @shipwire.fetch_stock_levels
93
+ end
94
+
95
+ def test_logging_with_specific_passwords
96
+ @shipwire = ActiveFulfillment::ShipwireService.new(login: 'cody@example.com', password: 345)
97
+ @shipwire.class.logger.expects(:info).with do |message|
98
+ refute message.include?('345')
99
+ true
100
+ end.twice
101
+
102
+ @shipwire.stubs(:ssl_post).returns(xml_fixture('shipwire/inventory_get_response'))
103
+ response = @shipwire.fetch_stock_levels
104
+ end
105
+
74
106
  def test_stock_levels_include_pending_when_set
75
107
  @shipwire = ActiveFulfillment::ShipwireService.new(
76
108
  :login => 'cody@example.com',
@@ -93,8 +125,8 @@ class ShipwireTest < Minitest::Test
93
125
  :password => 'test',
94
126
  :include_empty_stock => true
95
127
  )
96
- xml = REXML::Document.new(@shipwire.send(:build_inventory_request, {}))
97
- assert REXML::XPath.first(xml, '//IncludeEmpty')
128
+ xml = Nokogiri::XML(@shipwire.send(:build_inventory_request, {}))
129
+ assert xml.at_xpath(xml, '//IncludeEmpty')
98
130
  end
99
131
 
100
132
  def test_no_tracking_numbers_available
@@ -164,29 +196,30 @@ class ShipwireTest < Minitest::Test
164
196
 
165
197
  def test_affiliate_id
166
198
  ActiveFulfillment::ShipwireService.affiliate_id = 'affiliate_id'
167
-
168
- xml = REXML::Document.new(@shipwire.send(:build_fulfillment_request, '123456', @address, @line_items, @options))
169
- affiliate_id = REXML::XPath.first(xml, "//AffiliateId")
199
+ xml = Nokogiri::XML(@shipwire.send(:build_fulfillment_request, '123456', @address, @line_items, @options))
200
+ affiliate_id = xml.at_xpath(xml, "//AffiliateId")
170
201
  assert_equal 'affiliate_id', affiliate_id.text
171
202
  end
172
203
 
173
204
  def test_company_name_in_request
174
- xml = REXML::Document.new(@shipwire.send(:build_fulfillment_request, '123456', @address, @line_items, @options))
175
- company_node = REXML::XPath.first(xml, "//Company")
205
+ xml = Nokogiri::XML(@shipwire.send(:build_fulfillment_request, '123456', @address, @line_items, @options))
206
+ company_node = xml.at_xpath(xml, "//Company")
176
207
  assert_equal 'MyCorp', company_node.text
177
208
  end
178
209
 
179
210
  def test_order_excludes_note_by_default
180
- xml = REXML::Document.new(@shipwire.send(:build_fulfillment_request, '123456', @address, @line_items, @options))
181
- note_node = REXML::XPath.first(xml, "//Note").cdatas.first
182
- assert_nil note_node
211
+ xml = Nokogiri::XML(@shipwire.send(:build_fulfillment_request, '123456', @address, @line_items, @options))
212
+ note_node = xml.at_xpath(xml, "//Note")
213
+ assert_equal 0, note_node.children.select { |child| child.cdata? }.size
214
+ assert_equal false, note_node.cdata?
183
215
  end
184
216
 
185
217
  def test_order_includes_note_when_present
186
218
  @options[:note] = "A test note"
187
- xml = REXML::Document.new(@shipwire.send(:build_fulfillment_request, '123456', @address, @line_items, @options))
188
- note_node = REXML::XPath.first(xml, "//Note").cdatas.first
189
- assert_equal "A test note", note_node.to_s
219
+ xml = Nokogiri::XML(@shipwire.send(:build_fulfillment_request, '123456', @address, @line_items, @options))
220
+ note_node = xml.at_xpath(xml, "//Note")
221
+ assert_equal "A test note", note_node.text.strip
222
+ assert_equal note_node.children.select { |child| child.cdata? }.size, 1
190
223
  end
191
224
 
192
225
  def test_error_response_cdata_parsing
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_fulfillment
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Fauser
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-01-07 00:00:00.000000000 Z
12
+ date: 2016-07-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -18,6 +18,9 @@ dependencies:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: 3.2.9
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: 5.1.0
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -25,6 +28,9 @@ dependencies:
25
28
  - - ">="
26
29
  - !ruby/object:Gem::Version
27
30
  version: 3.2.9
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: 5.1.0
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: builder
30
36
  requirement: !ruby/object:Gem::Requirement
@@ -154,7 +160,8 @@ files:
154
160
  - test/unit/services/shopify_api_test.rb
155
161
  - test/unit/services/webgistix_test.rb
156
162
  homepage: http://github.com/shopify/active_fulfillment
157
- licenses: []
163
+ licenses:
164
+ - MIT
158
165
  metadata: {}
159
166
  post_install_message:
160
167
  rdoc_options: []