vacuum 1.5.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,9 @@ require 'minitest/autorun'
2
2
  require 'vcr'
3
3
  require_relative '../lib/vacuum'
4
4
 
5
+ ENV['AWS_ACCESS_KEY_ID'] ||= 'key'
6
+ ENV['AWS_SECRET_ACCESS_KEY'] ||= 'secret'
7
+
5
8
  VCR.configure do |c|
6
9
  c.hook_into :excon
7
10
  c.cassette_library_dir = 'test/cassettes'
@@ -24,14 +27,13 @@ class TestIntegration < Minitest::Test
24
27
  VCR.eject_cassette
25
28
  end
26
29
 
27
- # rubocop:disable AbcSize
28
30
  def test_encoding_issues
29
31
  params = { 'SearchIndex' => 'All', 'Keywords' => 'google' }
30
32
  titles = %w[BR CA CN DE ES FR GB IN IT JP US MX].flat_map do |locale|
31
33
  req = Vacuum.new(locale)
32
34
  req.associate_tag = 'foo'
33
35
  res = req.item_search(query: params)
34
- items = res.to_h['ItemSearchResponse']['Items']['Item']
36
+ items = res.dig('ItemSearchResponse', 'Items', 'Item')
35
37
  items.map { |item| item['ItemAttributes']['Title'] }
36
38
  end
37
39
  encodings = titles.map { |t| t.encoding.name }.uniq
@@ -40,4 +42,12 @@ class TestIntegration < Minitest::Test
40
42
  # whether the string has non-ASCII characters. MRI will only return latter.
41
43
  assert(encodings.any? { |encoding| encoding == 'UTF-8' })
42
44
  end
45
+
46
+ def test_unauthorized_errors
47
+ req = Vacuum.new
48
+ req.associate_tag = 'foo'
49
+ params = { 'SearchIndex' => 'All', 'Keywords' => 'amazon' }
50
+ res = req.item_search(query: params)
51
+ assert_equal 'InvalidClientTokenId', res.dig('ItemSearchErrorResponse', 'Error', 'Code')
52
+ end
43
53
  end
data/test/test_vacuum.rb CHANGED
@@ -80,4 +80,16 @@ class TestVacuum < Minitest::Test
80
80
  res.parser = parser
81
81
  assert_kind_of Hash, res.to_h
82
82
  end
83
+
84
+ def test_digs
85
+ Excon.stub({}, body: '<foo><bar>baz</bar></foo>')
86
+ res = @req.item_lookup(query: {}, mock: true)
87
+ assert_equal 'baz', res.dig('foo', 'bar')
88
+ end
89
+
90
+ def test_handles_unauthorized_errors
91
+ Excon.stub({}, status: 403, body: '<foo/>')
92
+ res = @req.item_lookup(query: {}, mock: true)
93
+ assert_equal 403, res.status
94
+ end
83
95
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vacuum
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hakan Ensari
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-27 00:00:00.000000000 Z
11
+ date: 2017-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dig_rb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: jeff
15
29
  requirement: !ruby/object:Gem::Requirement