bitbuckets 0.2.0
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 +7 -0
- data/LICENSE.txt +7 -0
- data/README.md +169 -0
- data/Rakefile +1 -0
- data/lib/bitbucket_rest_api.rb +86 -0
- data/lib/bitbucket_rest_api/api.rb +104 -0
- data/lib/bitbucket_rest_api/api/actions.rb +32 -0
- data/lib/bitbucket_rest_api/api_factory.rb +29 -0
- data/lib/bitbucket_rest_api/authorization.rb +31 -0
- data/lib/bitbucket_rest_api/client.rb +53 -0
- data/lib/bitbucket_rest_api/configuration.rb +103 -0
- data/lib/bitbucket_rest_api/connection.rb +97 -0
- data/lib/bitbucket_rest_api/constants.rb +57 -0
- data/lib/bitbucket_rest_api/core_ext/array.rb +6 -0
- data/lib/bitbucket_rest_api/core_ext/hash.rb +58 -0
- data/lib/bitbucket_rest_api/deprecation.rb +36 -0
- data/lib/bitbucket_rest_api/error.rb +37 -0
- data/lib/bitbucket_rest_api/error/bad_events.rb +10 -0
- data/lib/bitbucket_rest_api/error/bad_request.rb +11 -0
- data/lib/bitbucket_rest_api/error/blank_value.rb +10 -0
- data/lib/bitbucket_rest_api/error/client_error.rb +19 -0
- data/lib/bitbucket_rest_api/error/forbidden.rb +11 -0
- data/lib/bitbucket_rest_api/error/internal_server_error.rb +11 -0
- data/lib/bitbucket_rest_api/error/invalid_options.rb +17 -0
- data/lib/bitbucket_rest_api/error/no_events.rb +10 -0
- data/lib/bitbucket_rest_api/error/not_found.rb +11 -0
- data/lib/bitbucket_rest_api/error/required_params.rb +17 -0
- data/lib/bitbucket_rest_api/error/service_error.rb +18 -0
- data/lib/bitbucket_rest_api/error/service_unavailable.rb +11 -0
- data/lib/bitbucket_rest_api/error/unauthorized.rb +11 -0
- data/lib/bitbucket_rest_api/error/unknown_value.rb +17 -0
- data/lib/bitbucket_rest_api/error/unprocessable_entity.rb +11 -0
- data/lib/bitbucket_rest_api/error/validations.rb +17 -0
- data/lib/bitbucket_rest_api/invitations.rb +14 -0
- data/lib/bitbucket_rest_api/issues.rb +229 -0
- data/lib/bitbucket_rest_api/issues/comments.rb +116 -0
- data/lib/bitbucket_rest_api/issues/components.rb +105 -0
- data/lib/bitbucket_rest_api/issues/milestones.rb +105 -0
- data/lib/bitbucket_rest_api/normalizer.rb +24 -0
- data/lib/bitbucket_rest_api/parameter_filter.rb +29 -0
- data/lib/bitbucket_rest_api/repos.rb +276 -0
- data/lib/bitbucket_rest_api/repos/changesets.rb +52 -0
- data/lib/bitbucket_rest_api/repos/commits.rb +38 -0
- data/lib/bitbucket_rest_api/repos/components.rb +35 -0
- data/lib/bitbucket_rest_api/repos/default_reviewers.rb +60 -0
- data/lib/bitbucket_rest_api/repos/download.rb +15 -0
- data/lib/bitbucket_rest_api/repos/following.rb +38 -0
- data/lib/bitbucket_rest_api/repos/forks.rb +66 -0
- data/lib/bitbucket_rest_api/repos/keys.rb +86 -0
- data/lib/bitbucket_rest_api/repos/pull_request.rb +158 -0
- data/lib/bitbucket_rest_api/repos/services.rb +101 -0
- data/lib/bitbucket_rest_api/repos/sources.rb +36 -0
- data/lib/bitbucket_rest_api/repos/webhooks.rb +99 -0
- data/lib/bitbucket_rest_api/request.rb +71 -0
- data/lib/bitbucket_rest_api/request/basic_auth.rb +30 -0
- data/lib/bitbucket_rest_api/request/jsonize.rb +39 -0
- data/lib/bitbucket_rest_api/request/oauth.rb +50 -0
- data/lib/bitbucket_rest_api/response.rb +26 -0
- data/lib/bitbucket_rest_api/response/helpers.rb +18 -0
- data/lib/bitbucket_rest_api/response/jsonize.rb +25 -0
- data/lib/bitbucket_rest_api/response/mashify.rb +23 -0
- data/lib/bitbucket_rest_api/response/raise_error.rb +28 -0
- data/lib/bitbucket_rest_api/response/xmlize.rb +25 -0
- data/lib/bitbucket_rest_api/result.rb +136 -0
- data/lib/bitbucket_rest_api/teams.rb +91 -0
- data/lib/bitbucket_rest_api/user.rb +87 -0
- data/lib/bitbucket_rest_api/users.rb +20 -0
- data/lib/bitbucket_rest_api/users/account.rb +50 -0
- data/lib/bitbucket_rest_api/utils/url.rb +61 -0
- data/lib/bitbucket_rest_api/validations.rb +23 -0
- data/lib/bitbucket_rest_api/validations/format.rb +21 -0
- data/lib/bitbucket_rest_api/validations/presence.rb +21 -0
- data/lib/bitbucket_rest_api/validations/required.rb +37 -0
- data/lib/bitbucket_rest_api/validations/token.rb +38 -0
- data/lib/bitbucket_rest_api/version.rb +10 -0
- data/lib/bitbuckets.rb +2 -0
- data/spec/bitbucket_rest_api/api/actions_spec.rb +18 -0
- data/spec/bitbucket_rest_api/api_factory_spec.rb +28 -0
- data/spec/bitbucket_rest_api/api_spec.rb +87 -0
- data/spec/bitbucket_rest_api/authorization_spec.rb +74 -0
- data/spec/bitbucket_rest_api/client_spec.rb +17 -0
- data/spec/bitbucket_rest_api/core_ext/array_spec.rb +13 -0
- data/spec/bitbucket_rest_api/core_ext/hash_spec.rb +47 -0
- data/spec/bitbucket_rest_api/deprecation_spec.rb +31 -0
- data/spec/bitbucket_rest_api/error/bad_events_spec.rb +11 -0
- data/spec/bitbucket_rest_api/error/blank_value_spec.rb +14 -0
- data/spec/bitbucket_rest_api/error/no_events_spec.rb +11 -0
- data/spec/bitbucket_rest_api/invitations_spec.rb +21 -0
- data/spec/bitbucket_rest_api/issues/comments_spec.rb +89 -0
- data/spec/bitbucket_rest_api/issues/components_spec.rb +89 -0
- data/spec/bitbucket_rest_api/issues/milestones_spec.rb +89 -0
- data/spec/bitbucket_rest_api/issues_spec.rb +91 -0
- data/spec/bitbucket_rest_api/normalizer_spec.rb +29 -0
- data/spec/bitbucket_rest_api/parameter_filter_spec.rb +42 -0
- data/spec/bitbucket_rest_api/repos/changesets_spec.rb +44 -0
- data/spec/bitbucket_rest_api/repos/commits_spec.rb +21 -0
- data/spec/bitbucket_rest_api/repos/components_spec.rb +43 -0
- data/spec/bitbucket_rest_api/repos/default_reviewers_spec.rb +65 -0
- data/spec/bitbucket_rest_api/repos/download_spec.rb +10 -0
- data/spec/bitbucket_rest_api/repos/following_spec.rb +53 -0
- data/spec/bitbucket_rest_api/repos/forks_spec.rb +46 -0
- data/spec/bitbucket_rest_api/repos/keys_spec.rb +73 -0
- data/spec/bitbucket_rest_api/repos/pull_request_spec.rb +283 -0
- data/spec/bitbucket_rest_api/repos/sources_spec.rb +78 -0
- data/spec/bitbucket_rest_api/repos/webhooks_spec.rb +245 -0
- data/spec/bitbucket_rest_api/repos_spec.rb +158 -0
- data/spec/bitbucket_rest_api/request/jsonize_spec.rb +19 -0
- data/spec/bitbucket_rest_api/request/oauth_spec.rb +26 -0
- data/spec/bitbucket_rest_api/request_spec.rb +88 -0
- data/spec/bitbucket_rest_api/response/jsonize_spec.rb +13 -0
- data/spec/bitbucket_rest_api/response/mashify_spec.rb +33 -0
- data/spec/bitbucket_rest_api/response/raise_error_spec.rb +42 -0
- data/spec/bitbucket_rest_api/teams_spec.rb +136 -0
- data/spec/bitbucket_rest_api/user_spec.rb +78 -0
- data/spec/bitbucket_rest_api/utils/url_spec.rb +34 -0
- data/spec/bitbucket_rest_api/validations/format_spec.rb +30 -0
- data/spec/bitbucket_rest_api/validations/presence_spec.rb +13 -0
- data/spec/bitbucket_rest_api/validations/required_spec.rb +44 -0
- data/spec/bitbucket_rest_api/validations/token_spec.rb +17 -0
- data/spec/bitbucket_rest_api_spec.rb +17 -0
- data/spec/spec_helper.rb +24 -0
- metadata +358 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe BitBucket::Repos do
|
|
5
|
+
let(:repo) { BitBucket::Repos.new }
|
|
6
|
+
|
|
7
|
+
# class_eval is setting global variables in api.rb, this is creating
|
|
8
|
+
# failed expectations when these variables are not reset to nil before
|
|
9
|
+
# the next test is run. Therefore we must clear them manually as
|
|
10
|
+
# for the user attribute below...
|
|
11
|
+
after do
|
|
12
|
+
repo.clear_user
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe '.create' do
|
|
16
|
+
before do
|
|
17
|
+
expect(repo).to receive(:request).with(
|
|
18
|
+
:post,
|
|
19
|
+
'/1.0/repositories/',
|
|
20
|
+
BitBucket::Repos::DEFAULT_REPO_OPTIONS.merge('owner' => 'mock_owner', 'name' => 'mock_repo'),
|
|
21
|
+
{}
|
|
22
|
+
)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'should send a POST request to create the repo' do
|
|
26
|
+
repo.create('owner' => 'mock_owner', 'name' => 'mock_repo')
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe '.delete' do
|
|
31
|
+
before do
|
|
32
|
+
expect(repo).to receive(:request).with(
|
|
33
|
+
:delete,
|
|
34
|
+
'/1.0/repositories/mock_username/mock_repo',
|
|
35
|
+
{},
|
|
36
|
+
{}
|
|
37
|
+
)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'should send a DELETE request for the given repo' do
|
|
41
|
+
repo.delete('mock_username', 'mock_repo')
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# TODO: fix case where block_given? returns true
|
|
46
|
+
describe '.branches' do
|
|
47
|
+
before do
|
|
48
|
+
expect(repo).to receive(:request).with(
|
|
49
|
+
:get,
|
|
50
|
+
'/1.0/repositories/mock_username/mock_repo/branches/',
|
|
51
|
+
{},
|
|
52
|
+
{}
|
|
53
|
+
).and_return(%w[branch1 branch2 branch3])
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
context 'without a block' do
|
|
57
|
+
it 'invokes the .request method' do
|
|
58
|
+
repo.branches('mock_username', 'mock_repo')
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
context 'with a block' do
|
|
63
|
+
it 'invokes the .request method' do
|
|
64
|
+
repo.branches('mock_username', 'mock_repo') { |branch| branch }
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
describe '.edit' do
|
|
70
|
+
before do
|
|
71
|
+
expect(repo).to receive(:request).with(
|
|
72
|
+
:put,
|
|
73
|
+
'/1.0/repositories/mock_username/mock_repo/',
|
|
74
|
+
BitBucket::Repos::DEFAULT_REPO_OPTIONS.merge('owner' => 'mock_owner'),
|
|
75
|
+
{}
|
|
76
|
+
)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it 'should send a PUT request for the given repo' do
|
|
80
|
+
repo.edit('mock_username', 'mock_repo', 'owner' => 'mock_owner')
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# TODO: make sure this gets documented in gem since it is not in official docs
|
|
85
|
+
describe '.get' do
|
|
86
|
+
before do
|
|
87
|
+
expect(repo).to receive(:request).with(
|
|
88
|
+
:get,
|
|
89
|
+
'/1.0/repositories/mock_username/mock_repo',
|
|
90
|
+
{},
|
|
91
|
+
{}
|
|
92
|
+
)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it 'should send a GET request for the given repo' do
|
|
96
|
+
repo.get('mock_username', 'mock_repo', {})
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
describe '.list' do
|
|
101
|
+
before do
|
|
102
|
+
expect(repo).to receive(:request).with(
|
|
103
|
+
:get,
|
|
104
|
+
'/2.0/repositories',
|
|
105
|
+
{ 'pagelen' => 100 },
|
|
106
|
+
{}
|
|
107
|
+
).and_return(values: %w[repo1 repo2 repo3])
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# FIXME: this method belongs in the User class!
|
|
111
|
+
context 'without a block' do
|
|
112
|
+
it 'should send a GET request for the authenticated users repos' do
|
|
113
|
+
repo.list
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
context 'with a block' do
|
|
118
|
+
it 'should send a GET request for the authenticated users repos' do
|
|
119
|
+
repo.list { |repo| repo }
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
describe '.tags' do
|
|
125
|
+
before do
|
|
126
|
+
expect(repo).to receive(:request).with(
|
|
127
|
+
:get,
|
|
128
|
+
'/1.0/repositories/mock_username/mock_repo/tags/',
|
|
129
|
+
{},
|
|
130
|
+
{}
|
|
131
|
+
).and_return(%w[tag1 tag2 tag3])
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
context 'without a block' do
|
|
135
|
+
it 'should send a GET request for the tags belonging to the given repo' do
|
|
136
|
+
repo.tags('mock_username', 'mock_repo')
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
context 'with a block' do
|
|
141
|
+
it 'should send a GET request for the tags belonging to the given repo' do
|
|
142
|
+
repo.tags('mock_username', 'mock_repo') { |tag| tag }
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
describe 'getter methods' do
|
|
148
|
+
it 'returns an object of the correct class' do
|
|
149
|
+
expect(repo.changesets).to be_a BitBucket::Repos::Changesets
|
|
150
|
+
expect(repo.keys).to be_a BitBucket::Repos::Keys
|
|
151
|
+
expect(repo.following).to be_a BitBucket::Repos::Following
|
|
152
|
+
expect(repo.commits).to be_a BitBucket::Repos::Commits
|
|
153
|
+
expect(repo.pull_request).to be_a BitBucket::Repos::PullRequest
|
|
154
|
+
expect(repo.forks).to be_a BitBucket::Repos::Forks
|
|
155
|
+
expect(repo.download).to be_a BitBucket::Repos::Download
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe BitBucket::Request::Jsonize do
|
|
5
|
+
let(:jsonize) { described_class.new(->(env) { env }) }
|
|
6
|
+
before do
|
|
7
|
+
@env = {
|
|
8
|
+
body: { key1: 'val1' },
|
|
9
|
+
request_headers: {
|
|
10
|
+
'Content-Type' => 'application/json; charset=utf-8'
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'converts the body to json' do
|
|
16
|
+
expected = { body: '{"key1":"val1"}', request_headers: { 'Content-Type' => 'application/json; charset=utf-8' } }
|
|
17
|
+
expect(jsonize.call(@env)).to eq expected
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
require 'rack/test'
|
|
4
|
+
|
|
5
|
+
describe BitBucket::Request::OAuth do
|
|
6
|
+
include Rack::Test::Methods
|
|
7
|
+
|
|
8
|
+
let(:app) { ->(env) { [200, env, 'app'] } }
|
|
9
|
+
|
|
10
|
+
let (:middleware) { BitBucket::Request::OAuth.new(app) }
|
|
11
|
+
|
|
12
|
+
let(:request) { Rack::MockRequest.new(middleware) }
|
|
13
|
+
|
|
14
|
+
it 'add url key to env hash with URI value' do
|
|
15
|
+
query_string = 'key1=val1&key2=val2'
|
|
16
|
+
code, env = middleware.call Rack::MockRequest.env_for("/?#{query_string}", method: :post)
|
|
17
|
+
expect(code).to eq 200
|
|
18
|
+
expect(env[:url].query).to eq query_string
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'creates a empty hash if query of URI is empty' do
|
|
22
|
+
code, env = middleware.call Rack::MockRequest.env_for('/', method: :get)
|
|
23
|
+
expect(code).to eq 200
|
|
24
|
+
expect(middleware.query_params(env[:url])).to eq({})
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
require 'bitbucket_rest_api/request'
|
|
4
|
+
|
|
5
|
+
describe BitBucket::Request do
|
|
6
|
+
let(:fake_api) do
|
|
7
|
+
Class.new do
|
|
8
|
+
include BitBucket::Request
|
|
9
|
+
|
|
10
|
+
def connection(*_args)
|
|
11
|
+
Faraday.new(url: 'https://api.bitbucket.org')
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def new_access_token
|
|
15
|
+
'12345'
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe 'request' do
|
|
21
|
+
it 'raises an ArgumentError if an unsupported HTTP verb is used' do
|
|
22
|
+
expect { fake_api.new.request(:i_am_a_teapot, {}, '/') }.to raise_error(ArgumentError)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
context 'with a connection' do
|
|
26
|
+
it 'supports get' do
|
|
27
|
+
stub_request(:get, 'https://api.bitbucket.org/1.0/endpoint')
|
|
28
|
+
.with(headers: {
|
|
29
|
+
'Accept' => '*/*',
|
|
30
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
|
31
|
+
'Authorization' => 'Bearer 12345',
|
|
32
|
+
'User-Agent' => "Faraday v#{Faraday::VERSION}"
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
fake_api.new.request(:get, '/1.0/endpoint', {}, {})
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'supports put' do
|
|
39
|
+
stub_request(:put, 'https://api.bitbucket.org/1.0/endpoint')
|
|
40
|
+
.with(body: '{"data":{"key":"value"}}',
|
|
41
|
+
headers: {
|
|
42
|
+
'Accept' => '*/*',
|
|
43
|
+
'Content-Type' => 'application/x-www-form-urlencoded',
|
|
44
|
+
'Authorization' => 'Bearer 12345',
|
|
45
|
+
'User-Agent' => "Faraday v#{Faraday::VERSION}"
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
fake_api.new.request(:put, '/1.0/endpoint', { 'data' => { 'key' => 'value' } }, {})
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'supports patch' do
|
|
52
|
+
stub_request(:patch, 'https://api.bitbucket.org/1.0/endpoint')
|
|
53
|
+
.with(body: '{"data":{"key":"value"}}',
|
|
54
|
+
headers: {
|
|
55
|
+
'Accept' => '*/*',
|
|
56
|
+
'Content-Type' => 'application/x-www-form-urlencoded',
|
|
57
|
+
'Authorization' => 'Bearer 12345',
|
|
58
|
+
'User-Agent' => "Faraday v#{Faraday::VERSION}"
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
fake_api.new.request(:patch, '/1.0/endpoint', { 'data' => { 'key' => 'value' } }, {})
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'supports delete' do
|
|
65
|
+
stub_request(:delete, 'https://api.bitbucket.org/1.0/endpoint')
|
|
66
|
+
.with(headers: {
|
|
67
|
+
'Accept' => '*/*',
|
|
68
|
+
'Authorization' => 'Bearer 12345',
|
|
69
|
+
'User-Agent' => "Faraday v#{Faraday::VERSION}"
|
|
70
|
+
})
|
|
71
|
+
fake_api.new.request(:delete, '/1.0/endpoint', {}, {})
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it 'supports post' do
|
|
75
|
+
stub_request(:post, 'https://api.bitbucket.org/1.0/endpoint')
|
|
76
|
+
.with(body: '{"data":{"key":"value"}}',
|
|
77
|
+
headers: {
|
|
78
|
+
'Accept' => '*/*',
|
|
79
|
+
'Content-Type' => 'application/x-www-form-urlencoded',
|
|
80
|
+
'Authorization' => 'Bearer 12345',
|
|
81
|
+
'User-Agent' => "Faraday v#{Faraday::VERSION}"
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
fake_api.new.request(:post, '/1.0/endpoint', { 'data' => { 'key' => 'value' } }, {})
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe BitBucket::Response::Jsonize do
|
|
5
|
+
let(:jsonize) { described_class.new }
|
|
6
|
+
before do
|
|
7
|
+
@body = '{"key1":"val1"}'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it 'parses the json and returns a hash' do
|
|
11
|
+
expect(jsonize.parse(@body)).to eq('key1' => 'val1')
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe BitBucket::Response::Mashify do
|
|
5
|
+
# let(:mashify) { described_class.new }
|
|
6
|
+
describe 'parse' do
|
|
7
|
+
before do
|
|
8
|
+
@mashify = BitBucket::Response::Mashify.new
|
|
9
|
+
@string = 'Fantastic week!'
|
|
10
|
+
@array = %w[Monday Tuesday]
|
|
11
|
+
@hash = { one: 'one', two: 'two', three: 'three' }
|
|
12
|
+
@array_with_hash = ['banana', 'apple', { third: 'mango' }]
|
|
13
|
+
end
|
|
14
|
+
it 'parses a hash an returns a hashie mash' do
|
|
15
|
+
hashie_mash = @mashify.parse(@hash)
|
|
16
|
+
expect(hashie_mash.one).to eq('one')
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'parses a hash that is within an array' do
|
|
20
|
+
array_hashie_mash = @mashify.parse(@array_with_hash)
|
|
21
|
+
expect(array_hashie_mash[2].third).to eq('mango')
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'returns same object if the object does not contain a hash' do
|
|
25
|
+
string = @mashify.parse(@string)
|
|
26
|
+
array = @mashify.parse(@array)
|
|
27
|
+
|
|
28
|
+
expect(string).to eq(@string)
|
|
29
|
+
expect(array.length).to eq(2)
|
|
30
|
+
expect(array[0]).to eq('Monday')
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe BitBucket::Response::RaiseError do
|
|
5
|
+
describe '.on_complete' do
|
|
6
|
+
before do
|
|
7
|
+
@raise_error = BitBucket::Response::RaiseError.new
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it 'raises a BadRequest error on 400 status code' do
|
|
11
|
+
expect { @raise_error.on_complete(status: 400) }.to raise_error BitBucket::Error::BadRequest
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'raises an Unauthorized error on 401 status code' do
|
|
15
|
+
expect { @raise_error.on_complete(status: 401) }.to raise_error BitBucket::Error::Unauthorized
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'raises a Forbidden error on 403 status code' do
|
|
19
|
+
expect { @raise_error.on_complete(status: 403) }.to raise_error BitBucket::Error::Forbidden
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'raises a NotFound error on 404 status code' do
|
|
23
|
+
expect { @raise_error.on_complete(status: 404) }.to raise_error BitBucket::Error::NotFound
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'raises an UnprocessableEntity error on 422 status code' do
|
|
27
|
+
expect { @raise_error.on_complete(status: 422) }.to raise_error BitBucket::Error::UnprocessableEntity
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'raises an InternalServerError error on 500 status code' do
|
|
31
|
+
expect { @raise_error.on_complete(status: 500) }.to raise_error BitBucket::Error::InternalServerError
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'raises a ServiceUnavailable error on 503 status code' do
|
|
35
|
+
expect { @raise_error.on_complete(status: 503) }.to raise_error BitBucket::Error::ServiceUnavailable
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'raises a ServiceError when another status code' do
|
|
39
|
+
expect { @raise_error.on_complete(status: 501) }.to raise_error BitBucket::Error::ServiceError
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe BitBucket::Teams do
|
|
5
|
+
let(:team) { described_class.new }
|
|
6
|
+
|
|
7
|
+
describe '.list' do
|
|
8
|
+
before do
|
|
9
|
+
expect(team).to receive(:request).with(
|
|
10
|
+
:get,
|
|
11
|
+
'/2.0/teams/?role=member',
|
|
12
|
+
{},
|
|
13
|
+
{}
|
|
14
|
+
).and_return('values' => %w[team1 team2 team3])
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
context 'without a block' do
|
|
18
|
+
it 'sends a GET request for the teams of which the user is a member' do
|
|
19
|
+
team.list(:member)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
context 'with a block' do
|
|
24
|
+
it 'sends a GET request for the teams of which the user is a member' do
|
|
25
|
+
team.list(:member) { |team| team }
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe '.profile' do
|
|
31
|
+
before do
|
|
32
|
+
expect(team).to receive(:request).with(
|
|
33
|
+
:get,
|
|
34
|
+
'/2.0/teams/team_name',
|
|
35
|
+
{},
|
|
36
|
+
{}
|
|
37
|
+
)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'sends a GET request for the profile for the team' do
|
|
41
|
+
team.profile('team_name')
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe '.members' do
|
|
46
|
+
before do
|
|
47
|
+
expect(team).to receive(:request).with(
|
|
48
|
+
:get,
|
|
49
|
+
'/2.0/teams/team_name/members',
|
|
50
|
+
{},
|
|
51
|
+
{}
|
|
52
|
+
).and_return('values' => %w[member1 member2 member3])
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
context 'without a block' do
|
|
56
|
+
it 'sends a GET request for the members of the team' do
|
|
57
|
+
team.members('team_name')
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
context 'with a block' do
|
|
62
|
+
it 'sends a GET request for the members of the team' do
|
|
63
|
+
team.members('team_name') { |member| member }
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
describe '.followers' do
|
|
69
|
+
before do
|
|
70
|
+
expect(team).to receive(:request).with(
|
|
71
|
+
:get,
|
|
72
|
+
'/2.0/teams/team_name/followers',
|
|
73
|
+
{},
|
|
74
|
+
{}
|
|
75
|
+
).and_return('values' => %w[follower1 follower2 follower3])
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
context 'without a block' do
|
|
79
|
+
it 'sends a GET request for the followers of the team' do
|
|
80
|
+
team.followers('team_name')
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
context 'with a block' do
|
|
85
|
+
it 'sends a GET request for the followers of the team' do
|
|
86
|
+
team.followers('team_name') { |follower| follower }
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
describe '.following' do
|
|
92
|
+
before do
|
|
93
|
+
expect(team).to receive(:request).with(
|
|
94
|
+
:get,
|
|
95
|
+
'/2.0/teams/team_name/following',
|
|
96
|
+
{},
|
|
97
|
+
{}
|
|
98
|
+
).and_return('values' => %w[following1 following2 following3])
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
context 'without a block' do
|
|
102
|
+
it 'sends a GET request for accounts the team is following' do
|
|
103
|
+
team.following('team_name')
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
context 'with a block' do
|
|
108
|
+
it 'sends a GET request for accounts the team is following' do
|
|
109
|
+
team.following('team_name') { |followee| followee }
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
describe '.repos' do
|
|
115
|
+
before do
|
|
116
|
+
expect(team).to receive(:request).with(
|
|
117
|
+
:get,
|
|
118
|
+
'/2.0/repositories/team_name',
|
|
119
|
+
{},
|
|
120
|
+
{}
|
|
121
|
+
).and_return('values' => %w[repo1 repo2 repo3])
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
context 'without a block' do
|
|
125
|
+
it 'sends a GET request for the repos for the team' do
|
|
126
|
+
team.repos('team_name')
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
context 'with a block' do
|
|
131
|
+
it 'sends a GET request for the repos for the team' do
|
|
132
|
+
team.repos('team_name') { |repo| repo }
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|