vend 0.0.8 → 0.0.9
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +57 -0
- data/README.rdoc +1 -1
- data/Rakefile +1 -1
- data/example.rb +3 -3
- data/lib/vend.rb +2 -1
- data/lib/vend/base.rb +12 -12
- data/lib/vend/base_factory.rb +2 -6
- data/lib/vend/client.rb +5 -5
- data/lib/vend/http_client.rb +30 -31
- data/lib/vend/null_logger.rb +9 -5
- data/lib/vend/oauth2/auth_code.rb +7 -10
- data/lib/vend/oauth2/client.rb +1 -5
- data/lib/vend/pagination_info.rb +2 -1
- data/lib/vend/resource/customer.rb +1 -3
- data/lib/vend/resource/outlet.rb +0 -2
- data/lib/vend/resource/payment_type.rb +0 -2
- data/lib/vend/resource/product.rb +0 -2
- data/lib/vend/resource/register.rb +0 -2
- data/lib/vend/resource/register_sale.rb +2 -5
- data/lib/vend/resource/register_sale_product.rb +1 -1
- data/lib/vend/resource/supplier.rb +23 -0
- data/lib/vend/resource/tax.rb +0 -2
- data/lib/vend/resource/user.rb +0 -2
- data/lib/vend/resource_collection.rb +11 -15
- data/lib/vend/scope.rb +1 -2
- data/lib/vend/version.rb +1 -1
- data/spec/integration/customer_spec.rb +12 -9
- data/spec/integration/outlet_spec.rb +2 -3
- data/spec/integration/payment_types_spec.rb +1 -2
- data/spec/integration/product_spec.rb +26 -29
- data/spec/integration/register_sale_spec.rb +9 -10
- data/spec/integration/register_spec.rb +1 -2
- data/spec/integration/supplier_spec.rb +14 -0
- data/spec/integration/tax_spec.rb +1 -2
- data/spec/integration/user_spec.rb +1 -2
- data/spec/mock_responses/suppliers.json +36 -0
- data/spec/spec_helper.rb +1 -2
- data/spec/support/matchers/have_attributes.rb +3 -3
- data/spec/support/shared_examples/integration.rb +7 -9
- data/spec/support/shared_examples/logger.rb +21 -10
- data/spec/vend/base_factory_spec.rb +11 -12
- data/spec/vend/base_spec.rb +22 -23
- data/spec/vend/client_spec.rb +40 -39
- data/spec/vend/http_client_spec.rb +70 -62
- data/spec/vend/null_logger_spec.rb +1 -1
- data/spec/vend/oauth2/auth_code_spec.rb +18 -17
- data/spec/vend/oauth2/client_spec.rb +21 -21
- data/spec/vend/pagination_info_spec.rb +40 -17
- data/spec/vend/resource/register_sale_product_spec.rb +8 -6
- data/spec/vend/resource/register_sale_spec.rb +7 -8
- data/spec/vend/resource_collection_spec.rb +108 -95
- data/spec/vend/scope_spec.rb +20 -12
- data/vend.gemspec +5 -6
- metadata +10 -20
@@ -1,29 +1,38 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Vend::HttpClient do
|
4
|
-
|
5
4
|
let(:base_url) { "https://foo/bar/" }
|
6
5
|
let(:username) { "username" }
|
7
6
|
let(:password) { "password" }
|
8
|
-
let(:options)
|
9
|
-
{:
|
10
|
-
|
7
|
+
let(:options) do
|
8
|
+
{base_url: base_url, username: username, password: password}
|
9
|
+
end
|
11
10
|
|
12
|
-
subject
|
11
|
+
subject do
|
13
12
|
described_class.new(options)
|
14
|
-
|
13
|
+
end
|
14
|
+
|
15
|
+
it_behaves_like "it has a logger"
|
15
16
|
|
16
|
-
|
17
|
+
specify :base_url do
|
18
|
+
expect(subject.base_url).to eq base_url
|
19
|
+
end
|
20
|
+
|
21
|
+
specify :username do
|
22
|
+
expect(subject.username).to eq username
|
23
|
+
end
|
17
24
|
|
18
|
-
|
19
|
-
|
20
|
-
|
25
|
+
specify :password do
|
26
|
+
expect(subject.password).to eq password
|
27
|
+
end
|
21
28
|
|
22
29
|
describe "#verify_ssl?" do
|
23
|
-
|
30
|
+
specify :verify_ssl do
|
31
|
+
expect(subject.verify_ssl).to be_truthy
|
32
|
+
end
|
24
33
|
|
25
34
|
context "when overridden in the options" do
|
26
|
-
subject { described_class.new(options.merge(:
|
35
|
+
subject { described_class.new(options.merge(verify_ssl: false)) }
|
27
36
|
end
|
28
37
|
end
|
29
38
|
|
@@ -34,115 +43,114 @@ describe Vend::HttpClient do
|
|
34
43
|
let(:port) { 42 }
|
35
44
|
|
36
45
|
before do
|
37
|
-
subject.stub(:
|
38
|
-
http.
|
39
|
-
http.
|
40
|
-
http.
|
46
|
+
subject.stub(verify_mode: verify_mode)
|
47
|
+
expect(http).to receive(:use_ssl=).with(true)
|
48
|
+
expect(http).to receive(:verify_mode=).with(verify_mode)
|
49
|
+
expect(http).to receive(:read_timeout=).with(240)
|
41
50
|
Net::HTTP.stub(:new).with(host, port) { http }
|
42
51
|
end
|
43
52
|
|
44
53
|
it "returns the http_connection" do
|
45
|
-
subject.get_http_connection(host, port).
|
54
|
+
expect(subject.get_http_connection(host, port)).to eq http
|
46
55
|
end
|
47
56
|
end
|
48
57
|
|
49
58
|
describe "#verify_mode" do
|
50
|
-
|
51
59
|
context "when verify_ssl? is true" do
|
52
60
|
before do
|
53
|
-
subject.stub(
|
61
|
+
subject.stub(verify_ssl?: true)
|
62
|
+
end
|
63
|
+
specify :verify_mode do
|
64
|
+
expect(subject.verify_mode).to eq OpenSSL::SSL::VERIFY_PEER
|
54
65
|
end
|
55
|
-
its(:verify_mode) { should == OpenSSL::SSL::VERIFY_PEER }
|
56
66
|
end
|
57
67
|
|
58
68
|
context "when verify_ssl? is false" do
|
59
69
|
before do
|
60
|
-
subject.stub(
|
70
|
+
subject.stub(verify_ssl?: false)
|
71
|
+
end
|
72
|
+
specify :verify_mode do
|
73
|
+
expect(subject.verify_mode).to eq OpenSSL::SSL::VERIFY_NONE
|
61
74
|
end
|
62
|
-
its(:verify_mode) { should == OpenSSL::SSL::VERIFY_NONE }
|
63
75
|
end
|
64
|
-
|
65
76
|
end
|
66
77
|
|
67
78
|
describe "#request" do
|
68
|
-
|
69
79
|
context "when using invalid credentials" do
|
70
|
-
|
71
80
|
let(:username) { "invalid" }
|
72
81
|
|
73
82
|
it "raises an error" do
|
74
|
-
stub_request(:get, "https://invalid:password@foo/bar/products")
|
75
|
-
to_return(:
|
83
|
+
stub_request(:get, "https://invalid:password@foo/bar/products")
|
84
|
+
.to_return(status: 401)
|
76
85
|
|
77
|
-
expect
|
86
|
+
expect do
|
78
87
|
subject.request('products')
|
79
|
-
|
88
|
+
end.to raise_error(Vend::Unauthorized)
|
80
89
|
end
|
81
|
-
|
82
90
|
end
|
83
91
|
|
84
92
|
it "throws an error when an invalid request is made" do
|
85
|
-
stub_request(:get, "https://username:password@foo/bar/invalid")
|
86
|
-
to_return(:
|
93
|
+
stub_request(:get, "https://username:password@foo/bar/invalid")
|
94
|
+
.to_return(status: 404, body: '{"foo":"bar"}', headers: {})
|
87
95
|
|
88
|
-
expect
|
96
|
+
expect do
|
89
97
|
subject.request('invalid')
|
90
|
-
|
98
|
+
end.to raise_error(Vend::HTTPError)
|
91
99
|
end
|
92
100
|
|
93
101
|
it "returns parsed JSON" do
|
94
|
-
stub_request(:get, "https://username:password@foo/bar/bun")
|
95
|
-
to_return(:
|
96
|
-
subject.request("bun").
|
102
|
+
stub_request(:get, "https://username:password@foo/bar/bun")
|
103
|
+
.to_return(status: 200, body: '{"foo":"bar"}', headers: {})
|
104
|
+
expect(subject.request("bun")).to eq({"foo" => "bar"})
|
97
105
|
end
|
98
106
|
|
99
107
|
it "returns nil if the response was empty" do
|
100
|
-
stub_request(:get, "https://username:password@foo/bar/bun")
|
101
|
-
to_return(:
|
102
|
-
subject.request("bun").
|
108
|
+
stub_request(:get, "https://username:password@foo/bar/bun")
|
109
|
+
.to_return(status: 200, body: '', headers: {})
|
110
|
+
expect(subject.request("bun")).to be_nil
|
103
111
|
end
|
104
112
|
it "allows us to specify HTTP method" do
|
105
|
-
stub_request(:post, "https://username:password@foo/bar/foo")
|
106
|
-
to_return(:
|
113
|
+
stub_request(:post, "https://username:password@foo/bar/foo")
|
114
|
+
.to_return(status: 200, body: '{"foo":"bar"}', headers: {})
|
107
115
|
|
108
|
-
response = subject.request('foo', :
|
109
|
-
response.
|
116
|
+
response = subject.request('foo', method: :post)
|
117
|
+
expect(response).to eq({"foo" => "bar"})
|
110
118
|
end
|
111
119
|
|
112
120
|
it "allows us to set a request body" do
|
113
|
-
stub_request(:post, "https://username:password@foo/bar/foo")
|
114
|
-
with(:
|
115
|
-
to_return(:
|
121
|
+
stub_request(:post, "https://username:password@foo/bar/foo")
|
122
|
+
.with(body: "{\"post\":\"data\"}")
|
123
|
+
.to_return(status: 200, body: '{"foo":"bar"}', headers: {})
|
116
124
|
|
117
|
-
response = subject.request('foo', :
|
118
|
-
response.
|
125
|
+
response = subject.request('foo', method: :post, body: '{"post":"data"}')
|
126
|
+
expect(response).to eq({"foo" => "bar"})
|
119
127
|
end
|
120
128
|
|
121
129
|
it "allows us to specify url parameters" do
|
122
|
-
stub_request(:get, "https://username:password@foo/bar/foo?foo=bar&baz=baloo&flum%5B0%5D=blob&flum%5B1%5D=splat")
|
123
|
-
to_return(:
|
130
|
+
stub_request(:get, "https://username:password@foo/bar/foo?foo=bar&baz=baloo&flum%5B0%5D=blob&flum%5B1%5D=splat")
|
131
|
+
.to_return(status: 200, body: '{"foo":"bar"}', headers: {})
|
124
132
|
|
125
|
-
response = subject.request('foo', :
|
126
|
-
response.
|
133
|
+
response = subject.request('foo', url_params: {foo: "bar", baz: "baloo", flum: ["blob", "splat"]})
|
134
|
+
expect(response).to eq({"foo" => "bar"})
|
127
135
|
end
|
128
136
|
|
129
137
|
it "follows redirects" do
|
130
|
-
stub_request(:get, "https://username:password@foo/bar/foo")
|
131
|
-
to_return(:
|
138
|
+
stub_request(:get, "https://username:password@foo/bar/foo")
|
139
|
+
.to_return(status: 302, body: '{"bar":"baz"}', headers: {"Location" => "http://username:password@foo/bar/floo"})
|
132
140
|
|
133
|
-
stub_request(:get, "http://username:password@foo/bar/floo")
|
134
|
-
to_return(:
|
141
|
+
stub_request(:get, "http://username:password@foo/bar/floo")
|
142
|
+
.to_return(status: 200, body: '{"foo":"bar"}', headers: {})
|
135
143
|
|
136
144
|
response = subject.request('foo')
|
137
|
-
response.
|
145
|
+
expect(response).to eq({"foo" => "bar"})
|
138
146
|
end
|
139
147
|
|
140
148
|
it "raises an exception when the redirection limit is exceeded" do
|
141
|
-
stub_request(:get, "https://username:password@foo/bar/foo")
|
142
|
-
to_return(:
|
143
|
-
expect
|
149
|
+
stub_request(:get, "https://username:password@foo/bar/foo")
|
150
|
+
.to_return(status: 302, body: '{"bar":"baz"}', headers: {"Location" => "https://username:password@foo/bar/foo"})
|
151
|
+
expect do
|
144
152
|
subject.request('foo')
|
145
|
-
|
153
|
+
end.to raise_exception(Vend::RedirectionLimitExceeded)
|
146
154
|
end
|
147
155
|
end
|
148
156
|
end
|
@@ -1,13 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Vend::Oauth2::AuthCode do
|
4
|
-
|
5
4
|
subject { described_class.new('store', 'client_id', 'secret', 'redirect_uri') }
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
describe "#initialize" do
|
7
|
+
it "sets up the attr_readers" do
|
8
|
+
expect(subject.store).to eq 'store'
|
9
|
+
expect(subject.client_id).to eq 'client_id'
|
10
|
+
expect(subject.secret).to eq 'secret'
|
11
|
+
expect(subject.redirect_uri).to eq 'redirect_uri'
|
12
|
+
end
|
13
|
+
end
|
11
14
|
|
12
15
|
it "creates an instance of Client" do
|
13
16
|
expect(subject).to be_a Vend::Oauth2::AuthCode
|
@@ -19,21 +22,20 @@ describe Vend::Oauth2::AuthCode do
|
|
19
22
|
end
|
20
23
|
end
|
21
24
|
|
22
|
-
|
23
25
|
describe "#token_from_code" do
|
24
|
-
let(:store) {"store"}
|
26
|
+
let(:store) { "store" }
|
25
27
|
let(:token_type) { "Bearer" }
|
26
|
-
let(:access_token) { "Uy4eObSRn1RwzQbAitDMEkY6thdHsDJjwdGehpgr"}
|
27
|
-
let(:refresh_token) {"nbCoejmJp1XZgs7as6FeQQ5QZLlUfefzaBjrxvtV"}
|
28
|
+
let(:access_token) { "Uy4eObSRn1RwzQbAitDMEkY6thdHsDJjwdGehpgr" }
|
29
|
+
let(:refresh_token) { "nbCoejmJp1XZgs7as6FeQQ5QZLlUfefzaBjrxvtV" }
|
28
30
|
|
29
31
|
before do
|
30
|
-
stub_request(:post, "https://store.vendhq.com/api/1.0/token")
|
31
|
-
to_return(:
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
stub_request(:post, "https://store.vendhq.com/api/1.0/token")
|
33
|
+
.to_return(status: 200, body: {token_type: token_type,
|
34
|
+
expires: 2435942384,
|
35
|
+
domain_prefix: store,
|
36
|
+
access_token: access_token,
|
37
|
+
refresh_token: refresh_token,
|
38
|
+
expires_at: 2435942383}.to_json, headers: { 'Content-Type' => 'application/json' })
|
37
39
|
end
|
38
40
|
|
39
41
|
it "return access token" do
|
@@ -43,5 +45,4 @@ describe Vend::Oauth2::AuthCode do
|
|
43
45
|
expect(token.refresh_token).to eq(refresh_token)
|
44
46
|
end
|
45
47
|
end
|
46
|
-
|
47
48
|
end
|
@@ -1,13 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Vend::Oauth2::Client do
|
4
|
-
|
5
4
|
subject { described_class.new('store', 'auth_token') }
|
6
5
|
|
7
|
-
|
6
|
+
it_behaves_like "it has a logger"
|
8
7
|
|
9
|
-
|
10
|
-
|
8
|
+
describe "#initialize" do
|
9
|
+
it "sets up the attr_readers" do
|
10
|
+
expect(subject.store).to eq('store')
|
11
|
+
expect(subject.auth_token).to eq('auth_token')
|
12
|
+
end
|
13
|
+
end
|
11
14
|
|
12
15
|
it "creates an instance of Client" do
|
13
16
|
expect(subject).to be_a Vend::Oauth2::Client
|
@@ -15,33 +18,30 @@ describe Vend::Oauth2::Client do
|
|
15
18
|
|
16
19
|
describe "resource factories" do
|
17
20
|
it "gets all products" do
|
18
|
-
Vend::Resource::Product.
|
19
|
-
subject.Product.all.
|
21
|
+
expect(Vend::Resource::Product).to receive(:all).and_return([])
|
22
|
+
expect(subject.Product.all).to eq []
|
20
23
|
end
|
21
24
|
end
|
22
25
|
|
23
26
|
describe "#http_client_options" do
|
24
|
-
|
25
|
-
let(:options) { {:foo => 'bar'} }
|
27
|
+
let(:options) { {foo: 'bar'} }
|
26
28
|
let(:base_url) { "http://foo/" }
|
27
29
|
let(:auth_token) { "auth_token" }
|
28
30
|
|
29
31
|
before do
|
30
32
|
subject.stub(
|
31
|
-
|
32
|
-
|
33
|
-
|
33
|
+
options: options,
|
34
|
+
base_url: base_url,
|
35
|
+
auth_token: auth_token
|
34
36
|
)
|
35
37
|
end
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
}
|
43
|
-
|
39
|
+
specify :http_client_options do
|
40
|
+
expect(subject.http_client_options).to eq({
|
41
|
+
foo: 'bar',
|
42
|
+
base_url: base_url,
|
43
|
+
auth_token: auth_token
|
44
|
+
})
|
45
|
+
end
|
44
46
|
end
|
45
|
-
|
46
|
-
|
47
|
-
end
|
47
|
+
end
|
@@ -1,48 +1,71 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Vend::PaginationInfo do
|
4
|
-
|
5
4
|
subject { described_class.new(response) }
|
6
5
|
|
7
6
|
let(:response) { double("response") }
|
8
7
|
|
9
|
-
|
8
|
+
specify :response do
|
9
|
+
expect(subject.response).to eq response
|
10
|
+
end
|
10
11
|
|
11
12
|
context "when response has pagination info" do
|
12
|
-
let(:response)
|
13
|
+
let(:response) do
|
13
14
|
{
|
14
15
|
"pagination" => {
|
15
16
|
"results" => 7461,
|
16
17
|
"page" => 41,
|
17
18
|
"page_size" => 100,
|
18
|
-
"pages" => 75
|
19
|
+
"pages" => 75
|
19
20
|
}
|
20
21
|
}
|
21
|
-
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
specify :pages do
|
25
|
+
expect(subject.pages).to eq 75
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
+
specify :page do
|
29
|
+
expect(subject.page).to eq 41
|
30
|
+
end
|
31
|
+
|
32
|
+
specify :paged do
|
33
|
+
expect(subject).to be_paged
|
34
|
+
end
|
28
35
|
|
29
|
-
|
36
|
+
describe "#last_page?" do
|
37
|
+
specify :is_not_last_page do
|
38
|
+
expect(subject).to_not be_last_page
|
39
|
+
end
|
30
40
|
|
31
41
|
context "when page is equal to pages" do
|
32
42
|
before do
|
33
|
-
subject.stub(:
|
43
|
+
subject.stub(page: 42, pages: 42)
|
34
44
|
end
|
35
|
-
it { should be_last_page }
|
36
|
-
end
|
37
45
|
|
46
|
+
specify :is_last_page do
|
47
|
+
expect(subject).to be_last_page
|
48
|
+
end
|
49
|
+
end
|
38
50
|
end
|
39
51
|
end
|
40
52
|
|
41
53
|
context "when response does not have pagination info" do
|
42
54
|
let(:response) { Hash.new }
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
55
|
+
specify :pages do
|
56
|
+
expect(subject.pages).to eq 1
|
57
|
+
end
|
58
|
+
|
59
|
+
specify :page do
|
60
|
+
expect(subject.page).to eq 1
|
61
|
+
end
|
62
|
+
|
63
|
+
specify :is_last_page do
|
64
|
+
expect(subject).to be_last_page
|
65
|
+
end
|
66
|
+
|
67
|
+
specify :is_paged do
|
68
|
+
expect(subject).to_not be_paged
|
69
|
+
end
|
47
70
|
end
|
48
71
|
end
|
@@ -5,23 +5,25 @@ describe Vend::Resource::RegisterSaleProduct do
|
|
5
5
|
|
6
6
|
subject { described_class.new(attrs) }
|
7
7
|
|
8
|
-
|
8
|
+
specify :attrs do
|
9
|
+
expect(subject.attrs).to eq attrs
|
10
|
+
end
|
9
11
|
|
10
12
|
describe "provides an attr reader for the attributes in attrs" do
|
11
13
|
let(:attr1) { double("attr1") }
|
12
14
|
|
13
|
-
let(:attrs)
|
14
|
-
{
|
15
|
+
let(:attrs) do
|
16
|
+
{
|
15
17
|
"attr1" => attr1
|
16
18
|
}
|
17
|
-
|
19
|
+
end
|
18
20
|
|
19
21
|
it "responds to attr1" do
|
20
|
-
subject.send(:attr1).
|
22
|
+
expect(subject.send(:attr1)).to eq attr1
|
21
23
|
end
|
22
24
|
|
23
25
|
it "does not respond to attr2" do
|
24
|
-
|
26
|
+
expect { subject.send(:attr2) }.to raise_error NoMethodError
|
25
27
|
end
|
26
28
|
end
|
27
29
|
end
|