zk-jira-ruby 2.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.travis.yml +9 -0
- data/Gemfile +14 -0
- data/Guardfile +14 -0
- data/LICENSE +19 -0
- data/README.md +427 -0
- data/Rakefile +31 -0
- data/example.rb +232 -0
- data/http-basic-example.rb +113 -0
- data/jira-ruby.gemspec +35 -0
- data/lib/jira/base.rb +525 -0
- data/lib/jira/base_factory.rb +46 -0
- data/lib/jira/client.rb +315 -0
- data/lib/jira/has_many_proxy.rb +42 -0
- data/lib/jira/http_client.rb +112 -0
- data/lib/jira/http_error.rb +14 -0
- data/lib/jira/jwt_client.rb +67 -0
- data/lib/jira/oauth_client.rb +114 -0
- data/lib/jira/railtie.rb +10 -0
- data/lib/jira/request_client.rb +31 -0
- data/lib/jira/resource/agile.rb +79 -0
- data/lib/jira/resource/applinks.rb +39 -0
- data/lib/jira/resource/attachment.rb +50 -0
- data/lib/jira/resource/board.rb +91 -0
- data/lib/jira/resource/board_configuration.rb +9 -0
- data/lib/jira/resource/comment.rb +12 -0
- data/lib/jira/resource/component.rb +8 -0
- data/lib/jira/resource/createmeta.rb +44 -0
- data/lib/jira/resource/field.rb +83 -0
- data/lib/jira/resource/filter.rb +15 -0
- data/lib/jira/resource/issue.rb +141 -0
- data/lib/jira/resource/issuelink.rb +20 -0
- data/lib/jira/resource/issuelinktype.rb +14 -0
- data/lib/jira/resource/issuetype.rb +8 -0
- data/lib/jira/resource/priority.rb +8 -0
- data/lib/jira/resource/project.rb +41 -0
- data/lib/jira/resource/rapidview.rb +67 -0
- data/lib/jira/resource/remotelink.rb +26 -0
- data/lib/jira/resource/resolution.rb +8 -0
- data/lib/jira/resource/serverinfo.rb +18 -0
- data/lib/jira/resource/sprint.rb +105 -0
- data/lib/jira/resource/sprint_report.rb +8 -0
- data/lib/jira/resource/status.rb +8 -0
- data/lib/jira/resource/transition.rb +29 -0
- data/lib/jira/resource/user.rb +30 -0
- data/lib/jira/resource/version.rb +66 -0
- data/lib/jira/resource/watcher.rb +35 -0
- data/lib/jira/resource/webhook.rb +37 -0
- data/lib/jira/resource/worklog.rb +14 -0
- data/lib/jira/tasks.rb +0 -0
- data/lib/jira/version.rb +3 -0
- data/lib/jira-ruby.rb +49 -0
- data/lib/tasks/generate.rake +18 -0
- data/spec/integration/attachment_spec.rb +32 -0
- data/spec/integration/comment_spec.rb +52 -0
- data/spec/integration/component_spec.rb +39 -0
- data/spec/integration/field_spec.rb +32 -0
- data/spec/integration/issue_spec.rb +93 -0
- data/spec/integration/issuelinktype_spec.rb +26 -0
- data/spec/integration/issuetype_spec.rb +24 -0
- data/spec/integration/priority_spec.rb +24 -0
- data/spec/integration/project_spec.rb +49 -0
- data/spec/integration/rapidview_spec.rb +74 -0
- data/spec/integration/resolution_spec.rb +26 -0
- data/spec/integration/status_spec.rb +24 -0
- data/spec/integration/transition_spec.rb +49 -0
- data/spec/integration/user_spec.rb +41 -0
- data/spec/integration/version_spec.rb +39 -0
- data/spec/integration/watcher_spec.rb +62 -0
- data/spec/integration/webhook.rb +25 -0
- data/spec/integration/worklog_spec.rb +51 -0
- data/spec/jira/base_factory_spec.rb +45 -0
- data/spec/jira/base_spec.rb +598 -0
- data/spec/jira/client_spec.rb +291 -0
- data/spec/jira/has_many_proxy_spec.rb +46 -0
- data/spec/jira/http_client_spec.rb +328 -0
- data/spec/jira/http_error_spec.rb +24 -0
- data/spec/jira/jwt_uri_builder_spec.rb +59 -0
- data/spec/jira/oauth_client_spec.rb +162 -0
- data/spec/jira/request_client_spec.rb +41 -0
- data/spec/jira/resource/agile_spec.rb +135 -0
- data/spec/jira/resource/attachment_spec.rb +138 -0
- data/spec/jira/resource/board_spec.rb +224 -0
- data/spec/jira/resource/createmeta_spec.rb +258 -0
- data/spec/jira/resource/field_spec.rb +85 -0
- data/spec/jira/resource/filter_spec.rb +97 -0
- data/spec/jira/resource/issue_spec.rb +227 -0
- data/spec/jira/resource/issuelink_spec.rb +14 -0
- data/spec/jira/resource/project_factory_spec.rb +11 -0
- data/spec/jira/resource/project_spec.rb +123 -0
- data/spec/jira/resource/sprint_spec.rb +90 -0
- data/spec/jira/resource/user_factory_spec.rb +31 -0
- data/spec/jira/resource/worklog_spec.rb +22 -0
- data/spec/mock_responses/board/1.json +33 -0
- data/spec/mock_responses/board/1_issues.json +62 -0
- data/spec/mock_responses/component/10000.invalid.put.json +5 -0
- data/spec/mock_responses/component/10000.json +39 -0
- data/spec/mock_responses/component/10000.put.json +39 -0
- data/spec/mock_responses/component.post.json +28 -0
- data/spec/mock_responses/empty_issues.json +8 -0
- data/spec/mock_responses/field/1.json +15 -0
- data/spec/mock_responses/field.json +32 -0
- data/spec/mock_responses/issue/10002/attachments/10000.json +20 -0
- data/spec/mock_responses/issue/10002/comment/10000.json +29 -0
- data/spec/mock_responses/issue/10002/comment/10000.put.json +29 -0
- data/spec/mock_responses/issue/10002/comment.json +65 -0
- data/spec/mock_responses/issue/10002/comment.post.json +29 -0
- data/spec/mock_responses/issue/10002/transitions.json +49 -0
- data/spec/mock_responses/issue/10002/transitions.post.json +1 -0
- data/spec/mock_responses/issue/10002/watchers.json +13 -0
- data/spec/mock_responses/issue/10002/worklog/10000.json +31 -0
- data/spec/mock_responses/issue/10002/worklog/10000.put.json +30 -0
- data/spec/mock_responses/issue/10002/worklog.json +98 -0
- data/spec/mock_responses/issue/10002/worklog.post.json +30 -0
- data/spec/mock_responses/issue/10002.invalid.put.json +6 -0
- data/spec/mock_responses/issue/10002.json +126 -0
- data/spec/mock_responses/issue/10002.put.missing_field_update.json +6 -0
- data/spec/mock_responses/issue.json +1108 -0
- data/spec/mock_responses/issue.post.json +5 -0
- data/spec/mock_responses/issueLinkType/10000.json +7 -0
- data/spec/mock_responses/issueLinkType.json +25 -0
- data/spec/mock_responses/issuetype/5.json +8 -0
- data/spec/mock_responses/issuetype.json +42 -0
- data/spec/mock_responses/jira/rest/webhooks/1.0/webhook/2.json +11 -0
- data/spec/mock_responses/jira/rest/webhooks/1.0/webhook.json +11 -0
- data/spec/mock_responses/priority/1.json +8 -0
- data/spec/mock_responses/priority.json +42 -0
- data/spec/mock_responses/project/SAMPLEPROJECT.issues.json +1108 -0
- data/spec/mock_responses/project/SAMPLEPROJECT.json +84 -0
- data/spec/mock_responses/project.json +12 -0
- data/spec/mock_responses/rapidview/SAMPLEPROJECT.issues.full.json +276 -0
- data/spec/mock_responses/rapidview/SAMPLEPROJECT.issues.json +111 -0
- data/spec/mock_responses/rapidview/SAMPLEPROJECT.json +6 -0
- data/spec/mock_responses/rapidview.json +10 -0
- data/spec/mock_responses/resolution/1.json +7 -0
- data/spec/mock_responses/resolution.json +15 -0
- data/spec/mock_responses/sprint/1_issues.json +125 -0
- data/spec/mock_responses/status/1.json +7 -0
- data/spec/mock_responses/status.json +37 -0
- data/spec/mock_responses/user_username=admin.json +17 -0
- data/spec/mock_responses/version/10000.invalid.put.json +5 -0
- data/spec/mock_responses/version/10000.json +11 -0
- data/spec/mock_responses/version/10000.put.json +7 -0
- data/spec/mock_responses/version.post.json +7 -0
- data/spec/mock_responses/webhook/webhook.json +11 -0
- data/spec/mock_responses/webhook.json +11 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/support/clients_helper.rb +16 -0
- data/spec/support/matchers/have_attributes.rb +11 -0
- data/spec/support/matchers/have_many.rb +9 -0
- data/spec/support/matchers/have_one.rb +5 -0
- data/spec/support/shared_examples/integration.rb +177 -0
- metadata +491 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe JIRA::HTTPError do
|
4
|
+
let(:response) do
|
5
|
+
response = double('response')
|
6
|
+
allow(response).to receive(:code).and_return(401)
|
7
|
+
allow(response).to receive(:message).and_return('A MESSAGE WOO')
|
8
|
+
response
|
9
|
+
end
|
10
|
+
|
11
|
+
subject { described_class.new(response) }
|
12
|
+
|
13
|
+
it 'takes the response object as an argument' do
|
14
|
+
expect(subject.response).to eq(response)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'has a code method' do
|
18
|
+
expect(subject.code).to eq(response.code)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'returns code and class from message' do
|
22
|
+
expect(subject.message).to eq(response.message)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe JIRA::JwtClient::JwtUriBuilder do
|
4
|
+
subject(:url_builder) do
|
5
|
+
JIRA::JwtClient::JwtUriBuilder.new(url, http_method, shared_secret, site, issuer)
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:url) { '/foo' }
|
9
|
+
let(:http_method) { :get }
|
10
|
+
let(:shared_secret) { 'shared_secret' }
|
11
|
+
let(:site) { 'http://localhost:2990' }
|
12
|
+
let(:issuer) { nil }
|
13
|
+
|
14
|
+
describe '#build' do
|
15
|
+
subject { url_builder.build }
|
16
|
+
|
17
|
+
it 'includes the jwt param' do
|
18
|
+
expect(subject).to include('?jwt=')
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when the url already contains params' do
|
22
|
+
let(:url) { '/foo?expand=projects.issuetypes.fields' }
|
23
|
+
|
24
|
+
it 'includes the jwt param' do
|
25
|
+
expect(subject).to include('&jwt=')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'with a complete url' do
|
30
|
+
let(:url) { 'http://localhost:2990/rest/api/2/issue/createmeta' }
|
31
|
+
|
32
|
+
it 'includes the jwt param' do
|
33
|
+
expect(subject).to include('?jwt=')
|
34
|
+
end
|
35
|
+
|
36
|
+
it { is_expected.to start_with('/') }
|
37
|
+
|
38
|
+
it 'contains only one ?' do
|
39
|
+
expect(subject.count('?')).to eq(1)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'with a complete url containing a param' do
|
44
|
+
let(:url) do
|
45
|
+
'http://localhost:2990/rest/api/2/issue/createmeta?expand=projects.issuetypes.fields'
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'includes the jwt param' do
|
49
|
+
expect(subject).to include('&jwt=')
|
50
|
+
end
|
51
|
+
|
52
|
+
it { is_expected.to start_with('/') }
|
53
|
+
|
54
|
+
it 'contains only one ?' do
|
55
|
+
expect(subject.count('?')).to eq(1)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe JIRA::OauthClient do
|
4
|
+
let(:oauth_client) do
|
5
|
+
options = { consumer_key: 'foo', consumer_secret: 'bar' }
|
6
|
+
options = JIRA::Client::DEFAULT_OPTIONS.merge(options)
|
7
|
+
JIRA::OauthClient.new(options)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:response) do
|
11
|
+
response = double('response')
|
12
|
+
allow(response).to receive(:is_a?).with(Net::HTTPSuccess).and_return(true)
|
13
|
+
response
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'authenticating with oauth' do
|
17
|
+
it 'prepends the context path to all authorization and rest paths' do
|
18
|
+
options = %i[request_token_path authorize_path access_token_path]
|
19
|
+
defaults = JIRA::Client::DEFAULT_OPTIONS.merge(JIRA::OauthClient::DEFAULT_OPTIONS)
|
20
|
+
options.each do |key|
|
21
|
+
expect(oauth_client.options[key]).to eq(defaults[:context_path] + defaults[key])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'creates a Oauth::Consumer on initialize' do
|
26
|
+
expect(oauth_client.consumer.class).to eq(OAuth::Consumer)
|
27
|
+
expect(oauth_client.consumer.key).to eq(oauth_client.key)
|
28
|
+
expect(oauth_client.consumer.secret).to eq(oauth_client.secret)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns an OAuth request_token' do
|
32
|
+
# Cannot just check for method delegation as http connection will be attempted
|
33
|
+
request_token = OAuth::RequestToken.new(oauth_client.consumer)
|
34
|
+
allow(oauth_client).to receive(:get_request_token).and_return(request_token)
|
35
|
+
expect(oauth_client.get_request_token).to eq(request_token)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'allows setting the request token' do
|
39
|
+
token = double
|
40
|
+
expect(OAuth::RequestToken).to receive(:new).with(oauth_client.consumer, 'foo', 'bar').and_return(token)
|
41
|
+
|
42
|
+
request_token = oauth_client.set_request_token('foo', 'bar')
|
43
|
+
|
44
|
+
expect(request_token).to eq(token)
|
45
|
+
expect(oauth_client.request_token).to eq(token)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'allows setting the consumer key' do
|
49
|
+
expect(oauth_client.key).to eq('foo')
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'allows setting the consumer secret' do
|
53
|
+
expect(oauth_client.secret).to eq('bar')
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'the access token' do
|
57
|
+
it 'initializes' do
|
58
|
+
request_token = OAuth::RequestToken.new(oauth_client.consumer)
|
59
|
+
allow(oauth_client).to receive(:get_request_token).and_return(request_token)
|
60
|
+
mock_access_token = double
|
61
|
+
expect(request_token).to receive(:get_access_token).with(oauth_verifier: 'abc123').and_return(mock_access_token)
|
62
|
+
oauth_client.init_access_token(oauth_verifier: 'abc123')
|
63
|
+
expect(oauth_client.access_token).to eq(mock_access_token)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'raises an exception when accessing without initialisation' do
|
67
|
+
expect do
|
68
|
+
oauth_client.access_token
|
69
|
+
end.to raise_exception(JIRA::OauthClient::UninitializedAccessTokenError,
|
70
|
+
'init_access_token must be called before using the client')
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'allows setting the access token' do
|
74
|
+
token = double
|
75
|
+
expect(OAuth::AccessToken).to receive(:new).with(oauth_client.consumer, 'foo', 'bar').and_return(token)
|
76
|
+
|
77
|
+
access_token = oauth_client.set_access_token('foo', 'bar')
|
78
|
+
|
79
|
+
expect(access_token).to eq(token)
|
80
|
+
expect(oauth_client.access_token).to eq(token)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe 'http' do
|
85
|
+
let(:headers) { double }
|
86
|
+
let(:access_token) { double }
|
87
|
+
let(:body) { nil }
|
88
|
+
|
89
|
+
before do
|
90
|
+
allow(oauth_client).to receive(:access_token).and_return(access_token)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'responds to the http methods' do
|
94
|
+
%i[delete get head].each do |method|
|
95
|
+
expect(access_token).to receive(method).with('/path', headers).and_return(response)
|
96
|
+
oauth_client.make_request(method, '/path', '', headers)
|
97
|
+
end
|
98
|
+
%i[post put].each do |method|
|
99
|
+
expect(access_token).to receive(method).with('/path', '', headers).and_return(response)
|
100
|
+
oauth_client.make_request(method, '/path', '', headers)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'performs a request' do
|
105
|
+
expect(access_token).to receive(:send).with(:get, '/foo', headers).and_return(response)
|
106
|
+
|
107
|
+
|
108
|
+
oauth_client.request(:get, '/foo', body, headers)
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'for a multipart request' do
|
112
|
+
subject { oauth_client.make_multipart_request('/path', data, headers) }
|
113
|
+
|
114
|
+
let(:data) { {} }
|
115
|
+
let(:headers) { {} }
|
116
|
+
|
117
|
+
it 'signs the access_token and performs the request' do
|
118
|
+
expect(access_token).to receive(:sign!).with(an_instance_of(Net::HTTP::Post::Multipart))
|
119
|
+
expect(oauth_client.consumer).to receive_message_chain(:http, :request).with(an_instance_of(Net::HTTP::Post::Multipart))
|
120
|
+
|
121
|
+
subject
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe 'auth type is oauth_2legged' do
|
127
|
+
let(:oauth__2legged_client) do
|
128
|
+
options = { consumer_key: 'foo', consumer_secret: 'bar', auth_type: :oauth_2legged }
|
129
|
+
options = JIRA::Client::DEFAULT_OPTIONS.merge(options)
|
130
|
+
JIRA::OauthClient.new(options)
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'responds to the http methods adding oauth_token parameter' do
|
134
|
+
headers = double
|
135
|
+
mock_access_token = double
|
136
|
+
allow(oauth__2legged_client).to receive(:access_token).and_return(mock_access_token)
|
137
|
+
%i[delete get head].each do |method|
|
138
|
+
expect(mock_access_token).to receive(method).with('/path?oauth_token=', headers).and_return(response)
|
139
|
+
oauth__2legged_client.make_request(method, '/path', '', headers)
|
140
|
+
end
|
141
|
+
%i[post put].each do |method|
|
142
|
+
expect(mock_access_token).to receive(method).with('/path?oauth_token=', '', headers).and_return(response)
|
143
|
+
oauth__2legged_client.make_request(method, '/path', '', headers)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'responds to the http methods adding oauth_token parameter to any existing parameters' do
|
148
|
+
headers = double
|
149
|
+
mock_access_token = double
|
150
|
+
allow(oauth__2legged_client).to receive(:access_token).and_return(mock_access_token)
|
151
|
+
%i[delete get head].each do |method|
|
152
|
+
expect(mock_access_token).to receive(method).with('/path?any_param=toto&oauth_token=', headers).and_return(response)
|
153
|
+
oauth__2legged_client.make_request(method, '/path?any_param=toto', '', headers)
|
154
|
+
end
|
155
|
+
%i[post put].each do |method|
|
156
|
+
expect(mock_access_token).to receive(method).with('/path?any_param=toto&oauth_token=', '', headers).and_return(response)
|
157
|
+
oauth__2legged_client.make_request(method, '/path?any_param=toto', '', headers)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe JIRA::RequestClient do
|
4
|
+
let(:request_client) { JIRA::RequestClient.new }
|
5
|
+
|
6
|
+
describe '#request' do
|
7
|
+
subject(:request) { request_client.request(:get, '/foo', '', {}) }
|
8
|
+
|
9
|
+
context 'when doing a request fails' do
|
10
|
+
let(:response) { double }
|
11
|
+
|
12
|
+
before do
|
13
|
+
allow(response).to receive(:kind_of?).with(Net::HTTPSuccess).and_return(false)
|
14
|
+
allow(request_client).to receive(:make_request).with(:get, '/foo', '', {}).and_return(response)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'raises an exception' do
|
18
|
+
expect{ subject }.to raise_exception(JIRA::HTTPError)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#request_multipart' do
|
24
|
+
subject(:request) { request_client.request_multipart('/foo', data, {}) }
|
25
|
+
|
26
|
+
let(:data) { double }
|
27
|
+
|
28
|
+
context 'when doing a request fails' do
|
29
|
+
let(:response) { double }
|
30
|
+
|
31
|
+
before do
|
32
|
+
allow(response).to receive(:kind_of?).with(Net::HTTPSuccess).and_return(false)
|
33
|
+
allow(request_client).to receive(:make_multipart_request).with('/foo', data, {}).and_return(response)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'raises an exception' do
|
37
|
+
expect{ subject }.to raise_exception(JIRA::HTTPError)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe JIRA::Resource::Agile do
|
4
|
+
let(:client) do
|
5
|
+
client = double(options: { rest_base_path: '/jira/rest/api/2', context_path: '/jira' })
|
6
|
+
allow(client).to receive(:Issue).and_return(JIRA::Resource::IssueFactory.new(client))
|
7
|
+
client
|
8
|
+
end
|
9
|
+
let(:response) { double }
|
10
|
+
|
11
|
+
describe '#all' do
|
12
|
+
it 'should query url without parameters' do
|
13
|
+
expect(client).to receive(:get).with('/jira/rest/agile/1.0/board').and_return(response)
|
14
|
+
expect(response).to receive(:body).and_return(get_mock_response('board/1.json'))
|
15
|
+
|
16
|
+
JIRA::Resource::Agile.all(client)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#get_backlog_issues' do
|
21
|
+
it 'should query the url without parameters' do
|
22
|
+
expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/backlog?maxResults=100').and_return(response)
|
23
|
+
expect(response).to receive(:body).and_return(get_mock_response('board/1.json'))
|
24
|
+
|
25
|
+
JIRA::Resource::Agile.get_backlog_issues(client, 1)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#get_board_issues' do
|
30
|
+
it 'should query correct url without parameters' do
|
31
|
+
expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/issue?').and_return(response)
|
32
|
+
expect(response).to receive(:body).and_return(get_mock_response('board/1_issues.json'))
|
33
|
+
|
34
|
+
expect(client).to receive(:get).with('/jira/rest/api/2/search?jql=id+IN%2810546%2C+10547%2C+10556%2C+10557%2C+10558%2C+10559%2C+10600%2C+10601%2C+10604%29').and_return(response)
|
35
|
+
expect(response).to receive(:body).and_return(get_mock_response('board/1_issues.json'))
|
36
|
+
|
37
|
+
issues = JIRA::Resource::Agile.get_board_issues(client, 1)
|
38
|
+
expect(issues).to be_an(Array)
|
39
|
+
expect(issues.size).to eql(9)
|
40
|
+
|
41
|
+
issues.each do |issue|
|
42
|
+
expect(issue.class).to eq(JIRA::Resource::Issue)
|
43
|
+
expect(issue.expanded?).to be_falsey
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should query correct url with parameters' do
|
48
|
+
expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/issue?startAt=50').and_return(response)
|
49
|
+
expect(response).to receive(:body).and_return(get_mock_response('board/1_issues.json'))
|
50
|
+
|
51
|
+
expect(client).to receive(:get).with('/jira/rest/api/2/search?jql=id+IN%2810546%2C+10547%2C+10556%2C+10557%2C+10558%2C+10559%2C+10600%2C+10601%2C+10604%29').and_return(response)
|
52
|
+
expect(response).to receive(:body).and_return(get_mock_response('board/1_issues.json'))
|
53
|
+
|
54
|
+
issues = JIRA::Resource::Agile.get_board_issues(client, 1, startAt: 50)
|
55
|
+
expect(issues).to be_an(Array)
|
56
|
+
expect(issues.size).to eql(9)
|
57
|
+
|
58
|
+
issues.each do |issue|
|
59
|
+
expect(issue.class).to eq(JIRA::Resource::Issue)
|
60
|
+
expect(issue.expanded?).to be_falsey
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#get_sprints' do
|
66
|
+
it 'should query correct url without parameters' do
|
67
|
+
expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/sprint?maxResults=100').and_return(response)
|
68
|
+
expect(response).to receive(:body).and_return(get_mock_response('board/1.json'))
|
69
|
+
|
70
|
+
JIRA::Resource::Agile.get_sprints(client, 1)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should query correct url with parameters' do
|
74
|
+
expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/sprint?startAt=50&maxResults=100').and_return(response)
|
75
|
+
expect(response).to receive(:body).and_return(get_mock_response('board/1.json'))
|
76
|
+
|
77
|
+
JIRA::Resource::Agile.get_sprints(client, 1, startAt: 50)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should work with pagination starting at 0' do
|
81
|
+
expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/sprint?maxResults=1&startAt=0').and_return(response)
|
82
|
+
expect(response).to receive(:body).and_return(get_mock_response('board/1.json'))
|
83
|
+
|
84
|
+
JIRA::Resource::Agile.get_sprints(client, 1, maxResults: 1, startAt: 0)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should work with pagination not starting at 0' do
|
88
|
+
expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/sprint?maxResults=1&startAt=1').and_return(response)
|
89
|
+
expect(response).to receive(:body).and_return(get_mock_response('board/1.json'))
|
90
|
+
|
91
|
+
JIRA::Resource::Agile.get_sprints(client, 1, maxResults: 1, startAt: 1)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe '#get_sprint_issues' do
|
96
|
+
it 'should query correct url without parameters' do
|
97
|
+
expect(client).to receive(:get).with('/jira/rest/agile/1.0/sprint/1/issue?maxResults=100').and_return(response)
|
98
|
+
expect(response).to receive(:body).and_return(get_mock_response('sprint/1_issues.json'))
|
99
|
+
|
100
|
+
JIRA::Resource::Agile.get_sprint_issues(client, 1)
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should query correct url with parameters' do
|
104
|
+
expect(client).to receive(:get).with('/jira/rest/agile/1.0/sprint/1/issue?startAt=50&maxResults=100').and_return(response)
|
105
|
+
expect(response).to receive(:body).and_return(get_mock_response('sprint/1_issues.json'))
|
106
|
+
|
107
|
+
JIRA::Resource::Agile.get_sprint_issues(client, 1, startAt: 50)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe '#get_projects_full' do
|
112
|
+
it 'should query correct url without parameters' do
|
113
|
+
expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/project/full').and_return(response)
|
114
|
+
expect(response).to receive(:body).and_return(get_mock_response('board/1.json'))
|
115
|
+
|
116
|
+
JIRA::Resource::Agile.get_projects_full(client, 1)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe '#get_projects' do
|
121
|
+
it 'should query correct url without parameters' do
|
122
|
+
expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/project?maxResults=100').and_return(response)
|
123
|
+
expect(response).to receive(:body).and_return(get_mock_response('board/1.json'))
|
124
|
+
|
125
|
+
JIRA::Resource::Agile.get_projects(client, 1)
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'should query correct url with parameters' do
|
129
|
+
expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/project?startAt=50&maxResults=100').and_return(response)
|
130
|
+
expect(response).to receive(:body).and_return(get_mock_response('board/1.json'))
|
131
|
+
|
132
|
+
JIRA::Resource::Agile.get_projects(client, 1, startAt: 50)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe JIRA::Resource::Attachment do
|
4
|
+
subject(:attachment) do
|
5
|
+
JIRA::Resource::Attachment.new(
|
6
|
+
client,
|
7
|
+
issue: JIRA::Resource::Issue.new(client),
|
8
|
+
attrs: { 'author' => { 'foo' => 'bar' } }
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:client) do
|
13
|
+
double(
|
14
|
+
'client',
|
15
|
+
options: {
|
16
|
+
rest_base_path: '/jira/rest/api/2'
|
17
|
+
},
|
18
|
+
request_client: double(
|
19
|
+
options: {
|
20
|
+
username: 'username',
|
21
|
+
password: 'password'
|
22
|
+
}
|
23
|
+
)
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'relationships' do
|
28
|
+
it 'has an author' do
|
29
|
+
expect(subject).to have_one(:author, JIRA::Resource::User)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'has the correct author name' do
|
33
|
+
expect(subject.author.foo).to eq('bar')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '.meta' do
|
38
|
+
subject { JIRA::Resource::Attachment.meta(client) }
|
39
|
+
|
40
|
+
let(:response) do
|
41
|
+
double(
|
42
|
+
'response',
|
43
|
+
body: '{"enabled":true,"uploadLimit":10485760}'
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'returns meta information about attachment upload' do
|
48
|
+
expect(client).to receive(:get).with('/jira/rest/api/2/attachment/meta').and_return(response)
|
49
|
+
|
50
|
+
subject
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'the factory delegates correctly' do
|
54
|
+
subject { JIRA::Resource::AttachmentFactory.new(client) }
|
55
|
+
|
56
|
+
it 'delegates #meta to to target class' do
|
57
|
+
expect(subject).to respond_to(:meta)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#save' do
|
63
|
+
subject { attachment.save('file' => path_to_file) }
|
64
|
+
let(:path_to_file) { './spec/mock_responses/issue.json' }
|
65
|
+
let(:response) do
|
66
|
+
double(
|
67
|
+
body: [
|
68
|
+
{
|
69
|
+
"id": 10_001,
|
70
|
+
"self": 'http://www.example.com/jira/rest/api/2.0/attachments/10000',
|
71
|
+
"filename": 'picture.jpg',
|
72
|
+
"created": '2017-07-19T12:23:06.572+0000',
|
73
|
+
"size": 23_123,
|
74
|
+
"mimeType": 'image/jpeg'
|
75
|
+
}
|
76
|
+
].to_json
|
77
|
+
)
|
78
|
+
end
|
79
|
+
let(:issue) { JIRA::Resource::Issue.new(client) }
|
80
|
+
|
81
|
+
before do
|
82
|
+
allow(client).to receive(:post_multipart).and_return(response)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'successfully update the attachment' do
|
86
|
+
subject
|
87
|
+
|
88
|
+
expect(attachment.filename).to eq 'picture.jpg'
|
89
|
+
expect(attachment.mimeType).to eq 'image/jpeg'
|
90
|
+
expect(attachment.size).to eq 23_123
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '#save!' do
|
95
|
+
subject { attachment.save!('file' => path_to_file) }
|
96
|
+
|
97
|
+
let(:path_to_file) { './spec/mock_responses/issue.json' }
|
98
|
+
let(:response) do
|
99
|
+
double(
|
100
|
+
body: [
|
101
|
+
{
|
102
|
+
"id": 10_001,
|
103
|
+
"self": 'http://www.example.com/jira/rest/api/2.0/attachments/10000',
|
104
|
+
"filename": 'picture.jpg',
|
105
|
+
"created": '2017-07-19T12:23:06.572+0000',
|
106
|
+
"size": 23_123,
|
107
|
+
"mimeType": 'image/jpeg'
|
108
|
+
}
|
109
|
+
].to_json
|
110
|
+
)
|
111
|
+
end
|
112
|
+
let(:issue) { JIRA::Resource::Issue.new(client) }
|
113
|
+
|
114
|
+
before do
|
115
|
+
allow(client).to receive(:post_multipart).and_return(response)
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'successfully update the attachment' do
|
119
|
+
subject
|
120
|
+
|
121
|
+
expect(attachment.filename).to eq 'picture.jpg'
|
122
|
+
expect(attachment.mimeType).to eq 'image/jpeg'
|
123
|
+
expect(attachment.size).to eq 23_123
|
124
|
+
end
|
125
|
+
|
126
|
+
context 'when passing in a symbol as file key' do
|
127
|
+
subject { attachment.save!(file: path_to_file) }
|
128
|
+
|
129
|
+
it 'successfully update the attachment' do
|
130
|
+
subject
|
131
|
+
|
132
|
+
expect(attachment.filename).to eq 'picture.jpg'
|
133
|
+
expect(attachment.mimeType).to eq 'image/jpeg'
|
134
|
+
expect(attachment.size).to eq 23_123
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|