zz_bitbucket_rest_api 0.1.8

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.
Files changed (120) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +7 -0
  3. data/README.md +169 -0
  4. data/lib/bitbucket_rest_api.rb +91 -0
  5. data/lib/bitbucket_rest_api/api.rb +106 -0
  6. data/lib/bitbucket_rest_api/api/actions.rb +35 -0
  7. data/lib/bitbucket_rest_api/api_factory.rb +30 -0
  8. data/lib/bitbucket_rest_api/authorization.rb +34 -0
  9. data/lib/bitbucket_rest_api/client.rb +55 -0
  10. data/lib/bitbucket_rest_api/configuration.rb +106 -0
  11. data/lib/bitbucket_rest_api/connection.rb +98 -0
  12. data/lib/bitbucket_rest_api/constants.rb +58 -0
  13. data/lib/bitbucket_rest_api/core_ext/array.rb +7 -0
  14. data/lib/bitbucket_rest_api/core_ext/hash.rb +46 -0
  15. data/lib/bitbucket_rest_api/deprecation.rb +39 -0
  16. data/lib/bitbucket_rest_api/error.rb +38 -0
  17. data/lib/bitbucket_rest_api/error/bad_events.rb +9 -0
  18. data/lib/bitbucket_rest_api/error/bad_request.rb +12 -0
  19. data/lib/bitbucket_rest_api/error/blank_value.rb +9 -0
  20. data/lib/bitbucket_rest_api/error/client_error.rb +20 -0
  21. data/lib/bitbucket_rest_api/error/forbidden.rb +12 -0
  22. data/lib/bitbucket_rest_api/error/internal_server_error.rb +12 -0
  23. data/lib/bitbucket_rest_api/error/invalid_options.rb +18 -0
  24. data/lib/bitbucket_rest_api/error/no_events.rb +9 -0
  25. data/lib/bitbucket_rest_api/error/not_found.rb +12 -0
  26. data/lib/bitbucket_rest_api/error/required_params.rb +18 -0
  27. data/lib/bitbucket_rest_api/error/service_error.rb +19 -0
  28. data/lib/bitbucket_rest_api/error/service_unavailable.rb +12 -0
  29. data/lib/bitbucket_rest_api/error/unauthorized.rb +12 -0
  30. data/lib/bitbucket_rest_api/error/unknown_value.rb +18 -0
  31. data/lib/bitbucket_rest_api/error/unprocessable_entity.rb +12 -0
  32. data/lib/bitbucket_rest_api/error/validations.rb +18 -0
  33. data/lib/bitbucket_rest_api/invitations.rb +15 -0
  34. data/lib/bitbucket_rest_api/issues.rb +230 -0
  35. data/lib/bitbucket_rest_api/issues/comments.rb +118 -0
  36. data/lib/bitbucket_rest_api/issues/components.rb +106 -0
  37. data/lib/bitbucket_rest_api/issues/milestones.rb +107 -0
  38. data/lib/bitbucket_rest_api/normalizer.rb +27 -0
  39. data/lib/bitbucket_rest_api/parameter_filter.rb +32 -0
  40. data/lib/bitbucket_rest_api/repos.rb +272 -0
  41. data/lib/bitbucket_rest_api/repos/changesets.rb +54 -0
  42. data/lib/bitbucket_rest_api/repos/commits.rb +40 -0
  43. data/lib/bitbucket_rest_api/repos/components.rb +36 -0
  44. data/lib/bitbucket_rest_api/repos/default_reviewers.rb +59 -0
  45. data/lib/bitbucket_rest_api/repos/download.rb +21 -0
  46. data/lib/bitbucket_rest_api/repos/following.rb +39 -0
  47. data/lib/bitbucket_rest_api/repos/forks.rb +69 -0
  48. data/lib/bitbucket_rest_api/repos/keys.rb +88 -0
  49. data/lib/bitbucket_rest_api/repos/pull_request.rb +160 -0
  50. data/lib/bitbucket_rest_api/repos/services.rb +103 -0
  51. data/lib/bitbucket_rest_api/repos/sources.rb +39 -0
  52. data/lib/bitbucket_rest_api/repos/webhooks.rb +99 -0
  53. data/lib/bitbucket_rest_api/request.rb +76 -0
  54. data/lib/bitbucket_rest_api/request/basic_auth.rb +31 -0
  55. data/lib/bitbucket_rest_api/request/jsonize.rb +46 -0
  56. data/lib/bitbucket_rest_api/request/oauth.rb +53 -0
  57. data/lib/bitbucket_rest_api/response.rb +28 -0
  58. data/lib/bitbucket_rest_api/response/helpers.rb +21 -0
  59. data/lib/bitbucket_rest_api/response/jsonize.rb +30 -0
  60. data/lib/bitbucket_rest_api/response/mashify.rb +24 -0
  61. data/lib/bitbucket_rest_api/response/raise_error.rb +31 -0
  62. data/lib/bitbucket_rest_api/response/xmlize.rb +26 -0
  63. data/lib/bitbucket_rest_api/result.rb +140 -0
  64. data/lib/bitbucket_rest_api/teams.rb +88 -0
  65. data/lib/bitbucket_rest_api/user.rb +101 -0
  66. data/lib/bitbucket_rest_api/users.rb +24 -0
  67. data/lib/bitbucket_rest_api/users/account.rb +53 -0
  68. data/lib/bitbucket_rest_api/utils/url.rb +56 -0
  69. data/lib/bitbucket_rest_api/validations.rb +25 -0
  70. data/lib/bitbucket_rest_api/validations/format.rb +24 -0
  71. data/lib/bitbucket_rest_api/validations/presence.rb +25 -0
  72. data/lib/bitbucket_rest_api/validations/required.rb +44 -0
  73. data/lib/bitbucket_rest_api/validations/token.rb +43 -0
  74. data/lib/bitbucket_rest_api/version.rb +11 -0
  75. data/spec/bitbucket_rest_api/api/actions_spec.rb +17 -0
  76. data/spec/bitbucket_rest_api/api_factory_spec.rb +30 -0
  77. data/spec/bitbucket_rest_api/api_spec.rb +86 -0
  78. data/spec/bitbucket_rest_api/authorization_spec.rb +72 -0
  79. data/spec/bitbucket_rest_api/client_spec.rb +16 -0
  80. data/spec/bitbucket_rest_api/core_ext/array_spec.rb +12 -0
  81. data/spec/bitbucket_rest_api/core_ext/hash_spec.rb +49 -0
  82. data/spec/bitbucket_rest_api/deprecation_spec.rb +30 -0
  83. data/spec/bitbucket_rest_api/error/bad_events_spec.rb +10 -0
  84. data/spec/bitbucket_rest_api/error/blank_value_spec.rb +13 -0
  85. data/spec/bitbucket_rest_api/error/no_events_spec.rb +10 -0
  86. data/spec/bitbucket_rest_api/invitations_spec.rb +21 -0
  87. data/spec/bitbucket_rest_api/issues/comments_spec.rb +89 -0
  88. data/spec/bitbucket_rest_api/issues/components_spec.rb +88 -0
  89. data/spec/bitbucket_rest_api/issues/milestones_spec.rb +88 -0
  90. data/spec/bitbucket_rest_api/issues_spec.rb +90 -0
  91. data/spec/bitbucket_rest_api/normalizer_spec.rb +30 -0
  92. data/spec/bitbucket_rest_api/parameter_filter_spec.rb +41 -0
  93. data/spec/bitbucket_rest_api/repos/changesets_spec.rb +43 -0
  94. data/spec/bitbucket_rest_api/repos/commits_spec.rb +20 -0
  95. data/spec/bitbucket_rest_api/repos/components_spec.rb +42 -0
  96. data/spec/bitbucket_rest_api/repos/default_reviewers_spec.rb +64 -0
  97. data/spec/bitbucket_rest_api/repos/download_spec.rb +9 -0
  98. data/spec/bitbucket_rest_api/repos/following_spec.rb +52 -0
  99. data/spec/bitbucket_rest_api/repos/forks_spec.rb +45 -0
  100. data/spec/bitbucket_rest_api/repos/keys_spec.rb +72 -0
  101. data/spec/bitbucket_rest_api/repos/pull_request_spec.rb +288 -0
  102. data/spec/bitbucket_rest_api/repos/sources_spec.rb +77 -0
  103. data/spec/bitbucket_rest_api/repos/webhooks_spec.rb +245 -0
  104. data/spec/bitbucket_rest_api/repos_spec.rb +157 -0
  105. data/spec/bitbucket_rest_api/request/jsonize_spec.rb +18 -0
  106. data/spec/bitbucket_rest_api/request/oauth_spec.rb +27 -0
  107. data/spec/bitbucket_rest_api/request_spec.rb +81 -0
  108. data/spec/bitbucket_rest_api/response/jsonize_spec.rb +12 -0
  109. data/spec/bitbucket_rest_api/response/mashify_spec.rb +32 -0
  110. data/spec/bitbucket_rest_api/response/raise_error_spec.rb +41 -0
  111. data/spec/bitbucket_rest_api/teams_spec.rb +135 -0
  112. data/spec/bitbucket_rest_api/user_spec.rb +77 -0
  113. data/spec/bitbucket_rest_api/utils/url_spec.rb +33 -0
  114. data/spec/bitbucket_rest_api/validations/format_spec.rb +29 -0
  115. data/spec/bitbucket_rest_api/validations/presence_spec.rb +12 -0
  116. data/spec/bitbucket_rest_api/validations/required_spec.rb +43 -0
  117. data/spec/bitbucket_rest_api/validations/token_spec.rb +16 -0
  118. data/spec/bitbucket_rest_api_spec.rb +17 -0
  119. data/spec/spec_helper.rb +24 -0
  120. metadata +378 -0
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ describe BitBucket::Repos::Keys do
4
+ let(:deploy_keys) { described_class.new }
5
+ describe '.list' do
6
+ before do
7
+ expect(deploy_keys).to receive(:request).with(
8
+ :get,
9
+ '/1.0/repositories/mock_username/mock_repo/deploy-keys/',
10
+ {},
11
+ {}
12
+ ).and_return(['key1', 'key2', 'key3'])
13
+ end
14
+
15
+ context 'without a block' do
16
+ it 'should make a GET request for the deploy keys belonging to the given repo' do
17
+ deploy_keys.list('mock_username', 'mock_repo')
18
+ end
19
+ end
20
+
21
+ context 'with a block' do
22
+ it 'should make a GET request for the deploy keys belonging to the given repo' do
23
+ deploy_keys.list('mock_username', 'mock_repo') { |key| key }
24
+ end
25
+ end
26
+ end
27
+
28
+ describe '.create' do
29
+ before do
30
+ expect(deploy_keys).to receive(:request).with(
31
+ :post,
32
+ '/1.0/repositories/mock_username/mock_repo/deploy-keys/',
33
+ { 'key' => 'mock_ssh_key', 'label' => 'mock_label' },
34
+ { headers: {"Content-Type"=>"application/json"} }
35
+ )
36
+ end
37
+
38
+ it 'should make a POST request for the deploy keys belonging to the given repo' do
39
+ deploy_keys.create('mock_username', 'mock_repo', { key: 'mock_ssh_key', label: 'mock_label' })
40
+ end
41
+ end
42
+
43
+ describe '.edit' do
44
+ before do
45
+ expect(deploy_keys).to receive(:request).with(
46
+ :put,
47
+ '/1.0/repositories/mock_username/mock_repo/deploy-keys/1',
48
+ { 'key' => 'mock_ssh_key', 'label' => 'mock_label' },
49
+ {}
50
+ )
51
+ end
52
+
53
+ it 'should make a PUT request for the deploy keys belonging to the given repo' do
54
+ deploy_keys.edit('mock_username', 'mock_repo', 1, { key: 'mock_ssh_key', label: 'mock_label' })
55
+ end
56
+ end
57
+
58
+ describe '.delete' do
59
+ before do
60
+ expect(deploy_keys).to receive(:request).with(
61
+ :delete,
62
+ '/1.0/repositories/mock_username/mock_repo/deploy-keys/mock_id',
63
+ { 'key' => 'mock_ssh_key', 'label' => 'mock_label' },
64
+ {}
65
+ )
66
+ end
67
+
68
+ it 'should make a DELETE request for the deploy keys belonging to the given repo' do
69
+ deploy_keys.delete('mock_username', 'mock_repo', 'mock_id', { key: 'mock_ssh_key', label: 'mock_label' })
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,288 @@
1
+ require 'spec_helper'
2
+
3
+ describe BitBucket::Repos::PullRequest do
4
+ subject { described_class.new }
5
+ describe '#list' do
6
+ before do
7
+ expect(subject).to receive(:request).with(
8
+ :get,
9
+ '/2.0/repositories/mock_user/mock_repo/pullrequests',
10
+ {},
11
+ {}
12
+ ).and_return(['pr1', 'pr2', 'pr3'])
13
+ end
14
+
15
+ context 'without a block' do
16
+ it 'makes a GET request for all pull requests belonging to the repo' do
17
+ subject.list('mock_user', 'mock_repo')
18
+ end
19
+ end
20
+
21
+ context 'with a block' do
22
+ it 'makes a GET request for all pull requests belonging to the repo' do
23
+ subject.list('mock_user', 'mock_repo') { |pr| pr }
24
+ end
25
+ end
26
+ end
27
+
28
+ describe '#participants' do
29
+ before do
30
+ expect(subject).to receive(:request).with(
31
+ :get,
32
+ "/1.0/repositories/mock_user/mock_repo/pullrequests/mock_pull_request_id/participants",
33
+ {},
34
+ {}
35
+ ).and_return(['participant1', 'participant2', 'participant3'])
36
+ end
37
+
38
+ context 'without a block' do
39
+ it 'makes a GET request for all participants belonging to the repo' do
40
+ subject.participants('mock_user', 'mock_repo', 'mock_pull_request_id')
41
+ end
42
+ end
43
+
44
+ context 'with a block' do
45
+ it 'makes a GET request for all participants belonging to the repo' do
46
+ subject.participants('mock_user', 'mock_repo', 'mock_pull_request_id') { |p| p }
47
+ end
48
+ end
49
+ end
50
+
51
+ describe '#get' do
52
+ before do
53
+ expect(subject).to receive(:request).with(
54
+ :get,
55
+ "/2.0/repositories/mock_user/mock_repo/pullrequests/mock_pull_request_id",
56
+ {}
57
+ )
58
+ end
59
+
60
+ it 'makes a GET request for the pull request belonging to the repo' do
61
+ subject.get('mock_user', 'mock_repo', 'mock_pull_request_id')
62
+ end
63
+ end
64
+
65
+ describe '#create' do
66
+ before do
67
+ @params = {
68
+ title: "mock_pr_title",
69
+ description: "mock_pull_request_description",
70
+ source: {
71
+ branch: {
72
+ name: "mock_source_branch_name"
73
+ },
74
+ repository: {
75
+ full_name: "mock_owner/mock_repo"
76
+ }
77
+ },
78
+ destination: {
79
+ branch: {
80
+ name: "mock_destination_branch_name"
81
+ },
82
+ commit: {
83
+ hash: "mock_uuid"
84
+ }
85
+ },
86
+ close_source_branch: true
87
+ }
88
+ end
89
+
90
+ it 'makes a POST request to create a new pull request' do
91
+ expect(subject).to receive(:request).with(
92
+ :post,
93
+ '/2.0/repositories/mock_user/mock_repo/pullrequests',
94
+ @params
95
+ )
96
+
97
+ subject.create('mock_user', 'mock_repo', @params)
98
+ end
99
+
100
+ it 'validates presence of required params' do
101
+ expect do
102
+ subject.create(
103
+ 'mock_user',
104
+ 'mock_repo',
105
+ {
106
+ title: "",
107
+ description: "mock_pull_request_description",
108
+ source: {
109
+ branch: {
110
+ name: "mock_source_branch_name"
111
+ },
112
+ repository: {
113
+ full_name: "mock_owner/mock_repo"
114
+ }
115
+ },
116
+ destination: {
117
+ branch: {
118
+ name: "mock_destination_branch_name"
119
+ },
120
+ commit: {
121
+ hash: "mock_uuid"
122
+ }
123
+ },
124
+ close_source_branch: true
125
+ }
126
+ )
127
+ end.to raise_error
128
+ end
129
+ end
130
+
131
+ describe '.put' do
132
+ before do
133
+ expect(subject).to receive(:request).with(
134
+ :put,
135
+ '/2.0/repositories/mock_user/mock_repo/pullrequests/mock_id',
136
+ {}
137
+ )
138
+ end
139
+
140
+ it 'makes a PUT request for the given pull request' do
141
+ subject.update('mock_user', 'mock_repo', 'mock_id')
142
+ end
143
+ end
144
+
145
+ describe '.commits' do
146
+ before do
147
+ expect(subject).to receive(:request).with(
148
+ :get,
149
+ '/2.0/repositories/mock_user/mock_repo/pullrequests/mock_id/commits',
150
+ {}
151
+ )
152
+ end
153
+
154
+ it 'makes a GET request for the commits' do
155
+ subject.commits('mock_user', 'mock_repo', 'mock_id')
156
+ end
157
+ end
158
+
159
+ describe '.commits' do
160
+ before do
161
+ expect(subject).to receive(:request).with(
162
+ :post,
163
+ '/2.0/repositories/mock_user/mock_repo/pullrequests/mock_id/approve',
164
+ {}
165
+ )
166
+ end
167
+
168
+ it 'makes a POST request' do
169
+ subject.approve('mock_user', 'mock_repo', 'mock_id')
170
+ end
171
+ end
172
+
173
+ describe '.delete_approval' do
174
+ before do
175
+ expect(subject).to receive(:request).with(
176
+ :delete,
177
+ '/2.0/repositories/mock_user/mock_repo/pullrequests/mock_id/approve',
178
+ {}
179
+ )
180
+ end
181
+
182
+ it 'makes a DELTE request' do
183
+ subject.delete_approval('mock_user', 'mock_repo', 'mock_id')
184
+ end
185
+ end
186
+
187
+
188
+ describe '.diff' do
189
+ before do
190
+ expect(subject).to receive(:request).with(
191
+ :get,
192
+ '/2.0/repositories/mock_user/mock_repo/pullrequests/mock_id/diff',
193
+ {}
194
+ )
195
+ end
196
+
197
+ it 'makes a GET request for the diff of the pull request' do
198
+ subject.diff('mock_user', 'mock_repo', 'mock_id')
199
+ end
200
+ end
201
+
202
+ describe '.all_activity' do
203
+ before do
204
+ expect(subject).to receive(:request).with(
205
+ :get,
206
+ '/2.0/repositories/mock_user/mock_repo/pullrequests/activity',
207
+ {}
208
+ )
209
+ end
210
+
211
+ it 'makes a GET request' do
212
+ subject.all_activity('mock_user', 'mock_repo')
213
+ end
214
+ end
215
+
216
+
217
+ describe '.activity' do
218
+ before do
219
+ expect(subject).to receive(:request).with(
220
+ :get,
221
+ '/2.0/repositories/mock_user/mock_repo/pullrequests/mock_id/activity',
222
+ {}
223
+ )
224
+ end
225
+
226
+ it 'makes a GET request' do
227
+ subject.activity('mock_user', 'mock_repo', 'mock_id')
228
+ end
229
+ end
230
+
231
+
232
+ describe '.accept_and_merge' do
233
+ before do
234
+ expect(subject).to receive(:request).with(
235
+ :post,
236
+ '/2.0/repositories/mock_user/mock_repo/pullrequests/mock_id/merge',
237
+ {}
238
+ )
239
+ end
240
+
241
+ it 'makes a POST request' do
242
+ subject.merge('mock_user', 'mock_repo', 'mock_id')
243
+ end
244
+ end
245
+
246
+ describe '.decline' do
247
+ before do
248
+ expect(subject).to receive(:request).with(
249
+ :post,
250
+ '/2.0/repositories/mock_user/mock_repo/pullrequests/mock_id/decline',
251
+ {}
252
+ )
253
+ end
254
+
255
+ it 'makes a POST request' do
256
+ subject.decline('mock_user', 'mock_repo', 'mock_id')
257
+ end
258
+ end
259
+
260
+
261
+ describe '.comments' do
262
+ before do
263
+ expect(subject).to receive(:request).with(
264
+ :get,
265
+ '/2.0/repositories/mock_user/mock_repo/pullrequests/mock_id/comments',
266
+ {}
267
+ )
268
+ end
269
+
270
+ it 'makes a GET request' do
271
+ subject.comments('mock_user', 'mock_repo', 'mock_id')
272
+ end
273
+ end
274
+
275
+ describe '.comment' do
276
+ before do
277
+ expect(subject).to receive(:request).with(
278
+ :get,
279
+ '/2.0/repositories/mock_user/mock_repo/pullrequests/mock_id/comments/comment_id',
280
+ {}
281
+ )
282
+ end
283
+
284
+ it 'makes a GET request' do
285
+ subject.comment('mock_user', 'mock_repo', 'mock_id', 'comment_id')
286
+ end
287
+ end
288
+ end
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ describe BitBucket::Repos::Sources do
4
+ let(:subject) { BitBucket::Repos::Sources.new }
5
+
6
+ describe '#list' do
7
+ context 'when some parameters are missing' do
8
+ it 'raises an error' do
9
+ expect do
10
+ subject.list(
11
+ 'mock_username',
12
+ 'mock_repo'
13
+ )
14
+ end.to raise_error(ArgumentError)
15
+ end
16
+ end
17
+
18
+ context 'when path parameter is empty' do
19
+ before do
20
+ expect(subject).to receive(:request).with(
21
+ :get,
22
+ '/1.0/repositories/mock_username/mock_repo/src/moch_sha/',
23
+ {},
24
+ {}
25
+ )
26
+ end
27
+
28
+ it 'sends a GET request for a list of all source files' do
29
+ subject.list('mock_username', 'mock_repo', 'moch_sha', '')
30
+ end
31
+ end
32
+
33
+ context 'when path parameter is defined' do
34
+ before do
35
+ expect(subject).to receive(:request).with(
36
+ :get,
37
+ '/1.0/repositories/mock_username/mock_repo/src/moch_sha/app/controller',
38
+ {},
39
+ {}
40
+ )
41
+ end
42
+
43
+ it 'send a GET request for a list of the source files under the specified path' do
44
+ subject.list('mock_username', 'mock_repo', 'moch_sha', 'app/controller')
45
+ end
46
+ end
47
+ end
48
+
49
+ describe '#get' do
50
+ context 'when some parameters are missing' do
51
+ it 'raises an error' do
52
+ expect do
53
+ subject.get(
54
+ 'mock_username',
55
+ 'mock_repo',
56
+ 'moch_sha'
57
+ )
58
+ end.to raise_error(ArgumentError)
59
+ end
60
+ end
61
+
62
+ context 'when path parameter is defined' do
63
+ before do
64
+ expect(subject).to receive(:request).with(
65
+ :get,
66
+ '/1.0/repositories/mock_username/mock_repo/raw/moch_sha/app/assets/images/logo.jpg',
67
+ {},
68
+ {}
69
+ )
70
+ end
71
+
72
+ it "send a GET request for a source file's size and contents" do
73
+ subject.get('mock_username', 'mock_repo', 'moch_sha', 'app/assets/images/logo.jpg')
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,245 @@
1
+ require 'spec_helper'
2
+
3
+ describe BitBucket::Repos::Webhooks, wip: true do
4
+ subject { described_class.new }
5
+ let(:post_put_params) do
6
+ {
7
+ 'description' => 'mock_description',
8
+ 'url' => 'mock_url',
9
+ 'active' => true,
10
+ 'events' => ['repo:push']
11
+ }
12
+ end
13
+
14
+ let(:missing_key_params) do
15
+ {
16
+ 'description' => 'mock_description',
17
+ 'active' => true,
18
+ 'events' => ['repo:push']
19
+ }
20
+ end
21
+
22
+ let(:blank_value_params) do
23
+ {
24
+ 'description' => '',
25
+ 'url' => 'mock_url',
26
+ 'active' => true,
27
+ 'events' => ['repo:push']
28
+ }
29
+ end
30
+
31
+ let(:bad_event_params) do
32
+ {
33
+ 'description' => 'mock_description',
34
+ 'url' => 'mock_url',
35
+ 'active' => true,
36
+ 'events' => ['bad:event']
37
+ }
38
+ end
39
+
40
+ let(:missing_events_params) do
41
+ {
42
+ 'description' => 'mock_description',
43
+ 'url' => 'mock_url',
44
+ 'active' => true,
45
+ 'events' => []
46
+ }
47
+ end
48
+
49
+ describe '#create' do
50
+ context 'when required fields are missing from params' do
51
+ context 'when a required key is missing' do
52
+ it 'raises an instance of BitBucket::Error::RequiredParams' do
53
+ expect do
54
+ subject.create(
55
+ 'mock_username',
56
+ 'mock_repo',
57
+ missing_key_params
58
+ )
59
+ end.to raise_error(BitBucket::Error::RequiredParams)
60
+ end
61
+ end
62
+
63
+ context 'when values of required keys are blank' do
64
+ it 'raises an instance of BitBucket::Error::RequiredParams' do
65
+ expect do
66
+ subject.create(
67
+ 'mock_username',
68
+ 'mock_repo',
69
+ blank_value_params
70
+ )
71
+ end.to raise_error(
72
+ BitBucket::Error::BlankValue,
73
+ "The value for: 'description', cannot be blank :("
74
+ )
75
+ end
76
+ end
77
+ end
78
+
79
+ it 'validates the given events' do
80
+ allow(subject).to(receive(:request))
81
+
82
+ expect do
83
+ subject.create(
84
+ 'mock_username',
85
+ 'mock_repo',
86
+ bad_event_params
87
+
88
+ )
89
+ end.to raise_error(
90
+ BitBucket::Error::BadEvents,
91
+ "The event: 'bad:event', does not exist :("
92
+ )
93
+ end
94
+
95
+ it 'checks that at least one event is given' do
96
+ allow(subject).to(receive(:request))
97
+
98
+ expect do
99
+ subject.create(
100
+ 'mock_username',
101
+ 'mock_repo',
102
+ missing_events_params
103
+ )
104
+ end.to raise_error(
105
+ BitBucket::Error::NoEvents,
106
+ "At least one event is required, none given :("
107
+ )
108
+ end
109
+
110
+ it 'makes a POST request to create a specific webhook' do
111
+ expect(subject).to receive(:request).with(
112
+ :post,
113
+ '/2.0/repositories/mock_username/mock_repo/hooks',
114
+ post_put_params,
115
+ { headers: { "Content-Type" => "application/json" } }
116
+ )
117
+
118
+ subject.create(
119
+ 'mock_username',
120
+ 'mock_repo',
121
+ post_put_params
122
+ )
123
+ end
124
+ end
125
+
126
+ describe '#list' do
127
+ it 'makes a GET request for all the webhooks beloning to the given repo' do
128
+ expect(subject).to receive(:request).with(
129
+ :get,
130
+ '/2.0/repositories/mock_username/mock_repo/hooks',
131
+ {},
132
+ {}
133
+ )
134
+
135
+ subject.list('mock_username', 'mock_repo')
136
+ end
137
+ end
138
+
139
+ describe '#get' do
140
+ it 'makes a GET request for a specific webook' do
141
+ expect(subject).to receive(:request).with(
142
+ :get,
143
+ '/2.0/repositories/mock_username/mock_repo/hooks/mock_uuid',
144
+ {},
145
+ {}
146
+ )
147
+
148
+ subject.get('mock_username', 'mock_repo', 'mock_uuid')
149
+ end
150
+ end
151
+
152
+ describe '#edit' do
153
+ context 'when required fields are missing from params' do
154
+ context 'when a required key is missing' do
155
+ it 'raises an instance of BitBucket::Error::RequiredParams' do
156
+ expect do
157
+ subject.edit(
158
+ 'mock_username',
159
+ 'mock_repo',
160
+ 'mock_uuid',
161
+ missing_key_params
162
+ )
163
+ end.to raise_error(BitBucket::Error::RequiredParams)
164
+ end
165
+ end
166
+
167
+ context 'when values of required keys are blank' do
168
+ it 'raises an instance of BitBucket::Error::RequiredParams' do
169
+ expect do
170
+ subject.edit(
171
+ 'mock_username',
172
+ 'mock_repo',
173
+ 'mock_uuid',
174
+ blank_value_params
175
+ )
176
+ end.to raise_error(
177
+ BitBucket::Error::BlankValue,
178
+ "The value for: 'description', cannot be blank :("
179
+ )
180
+ end
181
+ end
182
+ end
183
+
184
+ it 'validates the existence of the given events' do
185
+ allow(subject).to(receive(:request))
186
+
187
+ expect do
188
+ subject.edit(
189
+ 'mock_username',
190
+ 'mock_repo',
191
+ 'mock_uuid',
192
+ bad_event_params
193
+ )
194
+ end.to raise_error(
195
+ BitBucket::Error::BadEvents,
196
+ "The event: 'bad:event', does not exist :("
197
+ )
198
+ end
199
+
200
+ it 'validates that at least one event is given' do
201
+ allow(subject).to(receive(:request))
202
+
203
+ expect do
204
+ subject.edit(
205
+ 'mock_username',
206
+ 'mock_repo',
207
+ 'mock_uuid',
208
+ missing_events_params
209
+ )
210
+ end.to raise_error(
211
+ BitBucket::Error::NoEvents,
212
+ "At least one event is required, none given :("
213
+ )
214
+ end
215
+
216
+ it 'makes a PUT request for the given webhook' do
217
+ expect(subject).to receive(:request).with(
218
+ :put,
219
+ '/2.0/repositories/mock_username/mock_repo/hooks/mock_uuid',
220
+ post_put_params,
221
+ { headers: { "Content-Type" => "application/json" } }
222
+ )
223
+
224
+ subject.edit(
225
+ 'mock_username',
226
+ 'mock_repo',
227
+ 'mock_uuid',
228
+ post_put_params
229
+ )
230
+ end
231
+ end
232
+
233
+ describe '#delete' do
234
+ it 'sends a DELETE request for the given webhook' do
235
+ expect(subject).to receive(:request).with(
236
+ :delete,
237
+ '/2.0/repositories/mock_username/mock_repo/hooks/mock_uuid',
238
+ {},
239
+ {}
240
+ )
241
+
242
+ subject.delete('mock_username', 'mock_repo', 'mock_uuid')
243
+ end
244
+ end
245
+ end