vacuum 3.4.1 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/helper.rb DELETED
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Keep SimpleCov at top.
4
- require 'simplecov'
5
-
6
- SimpleCov.start do
7
- add_filter '/test/'
8
- end
9
-
10
- require 'minitest/autorun'
@@ -1,105 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'integration_helper'
4
-
5
- module Vacuum
6
- class TestRequests < IntegrationTest
7
- def test_get_browse_nodes
8
- requests.each do |request|
9
- response = request.get_browse_nodes(browse_node_ids: ['3045'])
10
- assert_equal 200, response.status
11
- end
12
- end
13
-
14
- def test_get_items
15
- requests.each do |request|
16
- response = request.get_items(item_ids: ['B07212L4G2'])
17
- assert_equal 200, response.status
18
- end
19
- end
20
-
21
- RESOURCE_ALL = %w[BrowseNodeInfo.BrowseNodes
22
- BrowseNodeInfo.BrowseNodes.Ancestor
23
- BrowseNodeInfo.BrowseNodes.SalesRank
24
- BrowseNodeInfo.WebsiteSalesRank
25
- Images.Primary.Small
26
- Images.Primary.Medium
27
- Images.Primary.Large
28
- Images.Variants.Small
29
- Images.Variants.Medium
30
- Images.Variants.Large
31
- ItemInfo.ByLineInfo
32
- ItemInfo.Classifications
33
- ItemInfo.ContentInfo
34
- ItemInfo.ContentRating
35
- ItemInfo.ExternalIds
36
- ItemInfo.Features
37
- ItemInfo.ManufactureInfo
38
- ItemInfo.ProductInfo
39
- ItemInfo.TechnicalInfo
40
- ItemInfo.Title
41
- ItemInfo.TradeInInfo
42
- Offers.Listings.Availability.MaxOrderQuantity
43
- Offers.Listings.Availability.Message
44
- Offers.Listings.Availability.MinOrderQuantity
45
- Offers.Listings.Availability.Type
46
- Offers.Listings.Condition
47
- Offers.Listings.Condition.SubCondition
48
- Offers.Listings.DeliveryInfo.IsAmazonFulfilled
49
- Offers.Listings.DeliveryInfo.IsFreeShippingEligible
50
- Offers.Listings.DeliveryInfo.IsPrimeEligible
51
- Offers.Listings.IsBuyBoxWinner
52
- Offers.Listings.LoyaltyPoints.Points
53
- Offers.Listings.MerchantInfo
54
- Offers.Listings.Price
55
- Offers.Listings.ProgramEligibility.IsPrimeExclusive
56
- Offers.Listings.ProgramEligibility.IsPrimePantry
57
- Offers.Listings.Promotions
58
- Offers.Listings.SavingBasis
59
- Offers.Summaries.HighestPrice
60
- Offers.Summaries.LowestPrice
61
- Offers.Summaries.OfferCount
62
- ParentASIN].freeze
63
-
64
- def test_get_items_with_all_resources
65
- requests.each do |request|
66
- response = request.get_items(item_ids: 'B07212L4G2',
67
- resources: RESOURCE_ALL)
68
- assert_equal 200, response.status
69
- item = response.dig('ItemsResult', 'Items').first
70
- assert item.key?('BrowseNodeInfo')
71
- end
72
- end
73
-
74
- def test_get_variations
75
- requests.each do |request|
76
- response = request.get_variations(asin: 'B07212L4G2')
77
- assert_equal 200, response.status
78
- end
79
- end
80
-
81
- def test_search_items
82
- requests.each do |request|
83
- response = request.search_items(keywords: 'Harry Potter')
84
- assert_equal 200, response.status
85
- end
86
- end
87
-
88
- def test_persistent
89
- request = requests.sample
90
- refute request.client.persistent?
91
- request.persistent
92
- assert request.client.persistent?
93
- end
94
-
95
- def test_logging
96
- require 'logger'
97
- logdev = StringIO.new
98
- logger = Logger.new(logdev)
99
- request = requests.sample
100
- request.use(logging: { logger: logger })
101
- request.search_items(keywords: 'Harry Potter')
102
- refute_empty logdev.string
103
- end
104
- end
105
- end
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'helper'
4
- require 'vcr'
5
-
6
- require 'locales'
7
- require 'vacuum'
8
- require 'vacuum/matcher'
9
-
10
- VCR.configure do |c|
11
- c.hook_into :webmock
12
- c.cassette_library_dir = 'test/cassettes'
13
- c.default_cassette_options = {
14
- match_requests_on: [Vacuum::Matcher],
15
- record: ENV['RECORD'] ? :new_episodes : :none
16
- }
17
- c.before_record do |interaction|
18
- interaction.ignore! if interaction.response.status.code != 200
19
- end
20
-
21
- Locales.each do |record|
22
- record.each do |key, val|
23
- next if key == :marketplace
24
-
25
- c.filter_sensitive_data(key.upcase) { val }
26
- end
27
- end
28
- end
29
-
30
- module Vacuum
31
- class IntegrationTest < Minitest::Test
32
- def setup
33
- if ENV['LIVE']
34
- VCR.turn_off!
35
- WebMock.allow_net_connect!
36
- else
37
- VCR.insert_cassette('vacuum')
38
- end
39
- end
40
-
41
- def teardown
42
- VCR.eject_cassette if VCR.turned_on?
43
- end
44
-
45
- private
46
-
47
- def requests
48
- Locales.map { |credentials| Vacuum.new(**credentials) }.shuffle
49
- end
50
- end
51
- end
data/test/locales.rb DELETED
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'forwardable'
4
- require 'yaml'
5
-
6
- module Locales
7
- class << self
8
- extend Forwardable
9
- include Enumerable
10
-
11
- attr_reader :all
12
-
13
- def_delegators :all, :each
14
- end
15
-
16
- %w[locales.yml locales.yml.example].each do |filename|
17
- path = File.expand_path(filename, __dir__)
18
- if File.exist?(path)
19
- @all = YAML.load_file(path)
20
- break
21
- end
22
- end
23
- end
@@ -1,28 +0,0 @@
1
- - :marketplace: CA
2
- :access_key: access_key
3
- :secret_key: secret_key
4
- :partner_tag: partner_tag
5
- - :marketplace: ES
6
- :access_key: access_key
7
- :secret_key: secret_key
8
- :partner_tag: partner_tag
9
- - :marketplace: DE
10
- :access_key: access_key
11
- :secret_key: secret_key
12
- :partner_tag: partner_tag
13
- - :marketplace: FR
14
- :access_key: access_key
15
- :secret_key: secret_key
16
- :partner_tag: partner_tag
17
- - :marketplace: IT
18
- :access_key: access_key
19
- :secret_key: secret_key
20
- :partner_tag: partner_tag
21
- - :marketplace: GB
22
- :access_key: access_key
23
- :secret_key: secret_key
24
- :partner_tag: partner_tag
25
- - :marketplace: US
26
- :access_key: access_key
27
- :secret_key: secret_key
28
- :partner_tag: partner_tag
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'helper'
4
- require 'vacuum/locale'
5
-
6
- module Vacuum
7
- class TestLocale < Minitest::Test
8
- def test_host
9
- locale = Locale.new(:us, **credentials)
10
- assert locale.host
11
- end
12
-
13
- def test_region
14
- locale = Locale.new(:us, **credentials)
15
- assert locale.region
16
- end
17
-
18
- def test_partner_type_default
19
- locale = Locale.new(:us, **credentials)
20
- assert locale.partner_type
21
- end
22
-
23
- def test_upcased_marketplace
24
- Locale.new('US', **credentials) # does not raise
25
- end
26
-
27
- def test_uk
28
- Locale.new(:uk, **credentials) # does not raise
29
- end
30
-
31
- def test_not_found
32
- assert_raises Locale::NotFound do
33
- Locale.new(:foo, **credentials)
34
- end
35
- end
36
-
37
- private
38
-
39
- def credentials
40
- { access_key: '123', secret_key: '123', partner_tag: 'xyz-20' }
41
- end
42
- end
43
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'helper'
4
- require 'vacuum/locale'
5
- require 'vacuum/operation'
6
-
7
- module Vacuum
8
- class TestOperation < Minitest::Test
9
- def setup
10
- @operation = Operation.new('Action', params: { foo: 1 }, locale: locale)
11
- end
12
-
13
- def test_body
14
- assert @operation.body
15
- end
16
-
17
- def test_url
18
- assert @operation.url
19
- end
20
-
21
- def test_headers
22
- assert @operation.headers
23
- end
24
-
25
- private
26
-
27
- def locale
28
- Locale.new(:us, access_key: '123', secret_key: '123', partner_tag: 'xyz')
29
- end
30
- end
31
- end
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'helper'
4
- require 'vacuum/request'
5
-
6
- module Vacuum
7
- class TestRequest < Minitest::Test
8
- def test_search_keywords
9
- err = assert_raises(ArgumentError) do
10
- api.search_items(keywords: ['Harry Potter'])
11
- end
12
-
13
- assert_equal ':keyword argument expects a String', err.message
14
- end
15
-
16
- def test_search_resources
17
- err = assert_raises(ArgumentError) do
18
- api.search_items(
19
- keywords: 'Harry Potter',
20
- resources: %w[Images.Primary.Large ItemInfo.ExternalIds Offer.Listings.Price]
21
- )
22
- end
23
-
24
- assert_equal 'There is not such resource: Offer.Listings.Price', err.message
25
- end
26
-
27
- def test_get_items_wrong_resource
28
- err = assert_raises(ArgumentError) do
29
- api.get_items(
30
- item_ids: :B07212L4G2,
31
- resources: %w[BrowseNodeInfo.BrowseNode.SalesRank]
32
- )
33
- end
34
-
35
- assert_equal 'There is not such resource: BrowseNodeInfo.BrowseNode.SalesRank', err.message
36
- end
37
-
38
- def test_get_variations_wrong_resource
39
- err = assert_raises(ArgumentError) do
40
- api.get_variations(asin: 'B07212L4G2', resources: %w[BrowseNodeInfo.BrowseNode.SalesRank])
41
- end
42
-
43
- assert_equal 'There is not such resource: BrowseNodeInfo.BrowseNode.SalesRank', err.message
44
- end
45
-
46
- def test_resource_not_array
47
- err = assert_raises(ArgumentError) do
48
- api.get_items(item_ids: :B07212L4G2, resources: 'foo')
49
- end
50
-
51
- assert_equal ':resources argument expects an Array', err.message
52
- end
53
-
54
- def api
55
- @api ||= Vacuum::Request.new(marketplace: 'US',
56
- access_key: 'key',
57
- secret_key: 'secret',
58
- partner_tag: 'tag')
59
- end
60
- end
61
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'helper'
4
- require 'vacuum/response'
5
-
6
- module Vacuum
7
- class TestResponse < Minitest::Test
8
- def setup
9
- mock = Minitest::Mock.new
10
- mock.expect(:body, %({"ItemsResult":{"Items":[{"ASIN":"B07212L4G2"}]}}))
11
- @response = Response.new(mock)
12
- end
13
-
14
- def test_parse
15
- assert @response.parse
16
- end
17
-
18
- def test_cast_to_hash
19
- assert_kind_of Hash, @response.to_h
20
- end
21
-
22
- def test_dig
23
- assert @response.dig('ItemsResult', 'Items')
24
- end
25
- end
26
- end