bigcommerce-oauth-api 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+ require 'bigcommerce-oauth-api/client'
3
+ require 'bigcommerce-oauth-api/error'
4
+
5
+ module BigcommerceOAuthAPI
6
+ describe BigcommerceOAuthAPI::Client do
7
+ before do
8
+ @client = BigcommerceOAuthAPI::Client.new(:store_hash => 'TEST_STORE',
9
+ :client_id => 'SECRET_ID',
10
+ :access_token => 'SECRET_TOKEN')
11
+ end
12
+
13
+ describe 'when using with_api_methods' do
14
+ context 'and one of those actions would overwrite a defined method' do
15
+ it 'raises MethodAlreadyDefinedError' do
16
+ # The required client attempts to overwrite the 'post' method which is used to make HTTP POST requests
17
+ expect {
18
+ require 'support/method_already_defined_client'
19
+ }.to raise_error(BigcommerceOAuthAPI::MethodAlreadyDefinedError, "Method already defined: 'post'")
20
+ end
21
+ end
22
+
23
+ context 'and two api definitions would define methods with the same name' do
24
+ it 'raises MethodAlreadyDefinedError' do
25
+ # The required client has duplicate api definitions
26
+ expect {
27
+ require 'support/duplicate_api_definition_client'
28
+ }.to raise_error(BigcommerceOAuthAPI::MethodAlreadyDefinedError, "Method already defined: 'states'")
29
+ end
30
+ end
31
+ end
32
+
33
+ describe '.time' do
34
+ it 'returns the server time' do
35
+ stub_get(@client, 'time').
36
+ to_return(:headers => { :content_type => "application/#{@client.format}" })
37
+ @client.time
38
+ expect(a_get(@client, 'time').
39
+ with(:headers => {'X-Auth-Client' => 'SECRET_ID',
40
+ 'X-Auth-Token' => 'SECRET_TOKEN'})).to have_been_made
41
+ end
42
+ end
43
+
44
+ describe '.store_information' do
45
+ it 'returns the store information' do
46
+ stub_get(@client, 'store').
47
+ to_return(:headers => { :content_type => "application/#{@client.format}" })
48
+ @client.store_information
49
+ expect(a_get(@client, 'store').
50
+ with(:headers => {'X-Auth-Client' => 'SECRET_ID',
51
+ 'X-Auth-Token' => 'SECRET_TOKEN'})).to have_been_made
52
+ end
53
+ end
54
+
55
+ describe '.product_googleproductsearch' do
56
+ it 'returns the google product search mappings for a product' do
57
+ product_id = 10
58
+ stub_get(@client, "products/#{product_id}/googleproductsearch").
59
+ to_return(:headers => { :content_type => "application/#{@client.format}" })
60
+ @client.product_googleproductsearch(product_id)
61
+ expect(a_get(@client, "products/#{product_id}/googleproductsearch").
62
+ with(:headers => {'X-Auth-Client' => 'SECRET_ID',
63
+ 'X-Auth-Token' => 'SECRET_TOKEN'})).to have_been_made
64
+ end
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+ require 'bigcommerce-oauth-api/configuration'
3
+
4
+ module BigcommerceOAuthAPI
5
+ describe BigcommerceOAuthAPI::Configuration do
6
+ after do
7
+ BigcommerceOAuthAPI.reset
8
+ end
9
+
10
+ describe '.configure' do
11
+ BigcommerceOAuthAPI::Configuration::VALID_OPTIONS_KEYS.each do |key|
12
+ it "should set the #{key}" do
13
+ BigcommerceOAuthAPI.configure do |config|
14
+ config.send("#{key}=", key)
15
+ expect(BigcommerceOAuthAPI.send(key)).to eql(key)
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ BigcommerceOAuthAPI::Configuration::VALID_OPTIONS_KEYS.each do |key|
22
+ describe ".#{key}" do
23
+ it 'should reutrn the default value' do
24
+ expect(BigcommerceOAuthAPI.send(key)).to eql(BigcommerceOAuthAPI::Configuration.const_get("DEFAULT_#{key.upcase}"))
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,23 @@
1
+ require 'bigcommerce-oauth-api/request'
2
+ require 'bigcommerce-oauth-api/client'
3
+
4
+ describe BigcommerceOAuthAPI::Request do
5
+ describe '#get' do
6
+ context 'given a path and set of options' do
7
+ it 'should perform HTTP GET with OAuth headers' do
8
+ client = BigcommerceOAuthAPI::Client.new(
9
+ :store_hash => 'TEST_STORE',
10
+ :client_id => 'SECRET_ID',
11
+ :access_token => 'SECRET_TOKEN')
12
+ path = '/awesome/1/path/1'
13
+ url = client.send(:connection).build_url(path).to_s
14
+ stub_request(:get, url).to_return(:status => 200, :body => '', :headers => {})
15
+
16
+ client.get(path, {})
17
+ expect(a_request(:get, url).
18
+ with(:headers => {'X-Auth-Client' => 'SECRET_ID',
19
+ 'X-Auth-Token' => 'SECRET_TOKEN'})).to have_been_made
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+ require 'bigcommerce-oauth-api/resource'
3
+
4
+ module BigcommerceOAuthAPI
5
+ describe BigcommerceOAuthAPI::Resource do
6
+ context 'when initialized with a hash' do
7
+ let(:instance) do
8
+ described_class.new({ a: 'foo', b: 'bar', c: { foo: 'bar'} })
9
+ end
10
+
11
+ it 'responds to the methods corresponding to the hash keys' do
12
+ expect(instance.respond_to?(:a)).to eql(true)
13
+ expect(instance.respond_to?(:b)).to eql(true)
14
+ expect(instance.respond_to?(:c)).to eql(true)
15
+ end
16
+
17
+ it 'returns the correct values when accessing through methods' do
18
+ expect(instance.a).to eql('foo')
19
+ expect(instance.b).to eql('bar')
20
+ expect(instance.c).to be_a Resource
21
+ expect(instance.c['foo']).to eql('bar')
22
+ expect(instance.c[:foo]).to eql('bar')
23
+ expect(instance.c.foo).to eql('bar')
24
+ end
25
+ end
26
+
27
+ context 'when initialized with a deeply nested hash' do
28
+ let(:instance) do
29
+ described_class.new({a: { b: { c: { d: 'e' } } } })
30
+ end
31
+
32
+ it 'responds to both methods and keys on all level' do
33
+ expect(instance.respond_to?(:a)).to eql(true)
34
+ expect(instance.a.respond_to?(:b)).to eql(true)
35
+ expect(instance.a.b.respond_to?(:c)).to eql(true)
36
+ expect(instance.a.b.c.respond_to?(:d)).to eql(true)
37
+ expect(instance[:a][:b][:c][:d]).to eql('e')
38
+ expect(instance['a']['b']['c']['d']).to eql('e')
39
+ expect(instance.a.b.c.d).to eql('e')
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+ require 'bigcommerce-oauth-api'
3
+
4
+ describe Faraday::Response do
5
+ before do
6
+ @client = BigcommerceOAuthAPI::Client.new(:store_hash => 'TEST_STORE',
7
+ :client_id => 'SECRET_ID',
8
+ :access_token => 'SECRET_TOKEN')
9
+ end
10
+
11
+ {
12
+ 400 => BigcommerceOAuthAPI::BadRequest,
13
+ 404 => BigcommerceOAuthAPI::NotFound,
14
+ 429 => BigcommerceOAuthAPI::TooManyRequests,
15
+ 500 => BigcommerceOAuthAPI::InternalServerError,
16
+ 502 => BigcommerceOAuthAPI::BadGateway
17
+ }.each do |status, exception|
18
+ context "when HTTP status is #{status}" do
19
+ before do
20
+ stub_get(@client, 'products/1337').to_return(:body => '', :status => status)
21
+ end
22
+
23
+ it "should raise #{exception.name} error" do
24
+ expect{ @client.product(1337) }.to raise_error(exception)
25
+ end
26
+ end
27
+ end
28
+
29
+ context 'when the api limit is hit' do
30
+ it 'raises a TooManyRequests error' do
31
+ stub_get(@client, 'products').
32
+ to_return(:body => '', :status => 429, :headers => { 'X-Retry-After' => 15 })
33
+ expect{ @client.products }.to raise_error(BigcommerceOAuthAPI::TooManyRequests, '15')
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,56 @@
1
+ require 'simplecov'
2
+ require 'simplecov-rcov'
3
+ require 'codeclimate-test-reporter'
4
+
5
+ SimpleCov.start do
6
+ formatter SimpleCov::Formatter::MultiFormatter[
7
+ SimpleCov::Formatter::HTMLFormatter,
8
+ SimpleCov::Formatter::RcovFormatter,
9
+ CodeClimate::TestReporter::Formatter
10
+ ]
11
+ add_group('BigcommerceOAuthAPI', 'lib/bigcommerce-oauth-api')
12
+ add_group('Faraday', 'lib/faraday')
13
+ add_group('Specs', 'spec')
14
+ end
15
+
16
+ require 'bigcommerce-oauth-api'
17
+
18
+ require 'rspec'
19
+ require 'webmock/rspec'
20
+ RSpec.configure do |config|
21
+ config.include WebMock::API
22
+ end
23
+
24
+ WebMock.disable_net_connect!(:allow => 'codeclimate.com')
25
+
26
+ def stub_get(client, path)
27
+ stub_request(:get, "#{client.endpoint}/#{client.store_hash}/v2/#{path}")
28
+ end
29
+
30
+ def stub_post(client, path)
31
+ stub_request(:post, "#{client.endpoint}/#{client.store_hash}/v2/#{path}")
32
+ end
33
+
34
+ def stub_put(client, path)
35
+ stub_request(:put, "#{client.endpoint}/#{client.store_hash}/v2/#{path}")
36
+ end
37
+
38
+ def stub_delete(client, path)
39
+ stub_request(:delete, "#{client.endpoint}/#{client.store_hash}/v2/#{path}")
40
+ end
41
+
42
+ def a_get(client, path)
43
+ a_request(:get, "#{client.endpoint}/#{client.store_hash}/v2/#{path}")
44
+ end
45
+
46
+ def a_post(client, path)
47
+ a_request(:post, "#{client.endpoint}/#{client.store_hash}/v2/#{path}")
48
+ end
49
+
50
+ def a_put(client, path)
51
+ a_request(:put, "#{client.endpoint}/#{client.store_hash}/v2/#{path}")
52
+ end
53
+
54
+ def a_delete(client, path)
55
+ a_request(:delete, "#{client.endpoint}/#{client.store_hash}/v2/#{path}")
56
+ end
@@ -0,0 +1,7 @@
1
+ require 'bigcommerce-oauth-api'
2
+ require 'bigcommerce-oauth-api/api'
3
+
4
+ class DuplicateApiDefinitionClient < BigcommerceOAuthAPI::API
5
+ with_api_methods :state => { api_module: :state, scope: :self, methods: [:all, :select]},
6
+ :geography_state => { api_module: :state, scope: :self, methods: [:all, :select]}
7
+ end
@@ -0,0 +1,6 @@
1
+ require 'bigcommerce-oauth-api'
2
+ require 'bigcommerce-oauth-api/api'
3
+
4
+ class MethodAlreadyDefinedClient < BigcommerceOAuthAPI::API
5
+ with_api_methods :post => { api_module: :post, scope: :self, methods: [:select]}
6
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bigcommerce-oauth-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Orthmann
@@ -133,7 +133,35 @@ email: christian.orthmann@gmail.com
133
133
  executables: []
134
134
  extensions: []
135
135
  extra_rdoc_files: []
136
- files: []
136
+ files:
137
+ - ".rspec"
138
+ - CHANGELOG.md
139
+ - Gemfile
140
+ - README.md
141
+ - Rakefile
142
+ - bigcommerce-oauth-api.gemspec
143
+ - lib/bigcommerce-oauth-api.rb
144
+ - lib/bigcommerce-oauth-api/api.rb
145
+ - lib/bigcommerce-oauth-api/base.rb
146
+ - lib/bigcommerce-oauth-api/client.rb
147
+ - lib/bigcommerce-oauth-api/configuration.rb
148
+ - lib/bigcommerce-oauth-api/connection.rb
149
+ - lib/bigcommerce-oauth-api/error.rb
150
+ - lib/bigcommerce-oauth-api/request.rb
151
+ - lib/bigcommerce-oauth-api/resource.rb
152
+ - lib/bigcommerce-oauth-api/version.rb
153
+ - lib/faraday/raise_http_exception.rb
154
+ - spec/bigcommerce_oauth_api/api_spec.rb
155
+ - spec/bigcommerce_oauth_api/client/client_module_spec.rb
156
+ - spec/bigcommerce_oauth_api/client/client_nested_module_spec.rb
157
+ - spec/bigcommerce_oauth_api/client_spec.rb
158
+ - spec/bigcommerce_oauth_api/configuration_spec.rb
159
+ - spec/bigcommerce_oauth_api/request_spec.rb
160
+ - spec/bigcommerce_oauth_api/resource_spec.rb
161
+ - spec/faraday/response_spec.rb
162
+ - spec/spec_helper.rb
163
+ - spec/support/duplicate_api_definition_client.rb
164
+ - spec/support/method_already_defined_client.rb
137
165
  homepage: http://rubygems.org/gems/bigcommerce-oauth-api
138
166
  licenses:
139
167
  - MIT