jira-ruby 1.6.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -82,28 +82,45 @@ describe JIRA::OauthClient do
82
82
  end
83
83
 
84
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
+
85
93
  it 'responds to the http methods' do
86
- headers = double
87
- mock_access_token = double
88
- allow(oauth_client).to receive(:access_token).and_return(mock_access_token)
89
94
  %i[delete get head].each do |method|
90
- expect(mock_access_token).to receive(method).with('/path', headers).and_return(response)
95
+ expect(access_token).to receive(method).with('/path', headers).and_return(response)
91
96
  oauth_client.make_request(method, '/path', '', headers)
92
97
  end
93
98
  %i[post put].each do |method|
94
- expect(mock_access_token).to receive(method).with('/path', '', headers).and_return(response)
99
+ expect(access_token).to receive(method).with('/path', '', headers).and_return(response)
95
100
  oauth_client.make_request(method, '/path', '', headers)
96
101
  end
97
102
  end
98
103
 
99
104
  it 'performs a request' do
100
- body = nil
101
- headers = double
102
- access_token = double
103
105
  expect(access_token).to receive(:send).with(:get, '/foo', headers).and_return(response)
104
- allow(oauth_client).to receive(:access_token).and_return(access_token)
106
+
107
+
105
108
  oauth_client.request(:get, '/foo', body, headers)
106
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
107
124
  end
108
125
 
109
126
  describe 'auth type is oauth_2legged' do
@@ -142,4 +159,4 @@ describe JIRA::OauthClient do
142
159
  end
143
160
  end
144
161
  end
145
- end
162
+ end
@@ -1,14 +1,41 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe JIRA::RequestClient do
4
- it 'raises an exception for non success responses' do
5
- response = double
6
- allow(response).to receive(:kind_of?).with(Net::HTTPSuccess).and_return(false)
7
- rc = JIRA::RequestClient.new
8
- expect(rc).to receive(:make_request).with(:get, '/foo', '', {}).and_return(response)
9
-
10
- expect do
11
- rc.request(:get, '/foo', '', {})
12
- end.to raise_exception(JIRA::HTTPError)
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
13
40
  end
14
- end
41
+ end
@@ -1,6 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
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
+
4
12
  let(:client) do
5
13
  double(
6
14
  'client',
@@ -17,42 +25,78 @@ describe JIRA::Resource::Attachment do
17
25
  end
18
26
 
19
27
  describe 'relationships' do
20
- subject do
21
- JIRA::Resource::Attachment.new(client,
22
- issue: JIRA::Resource::Issue.new(client),
23
- attrs: { 'author' => { 'foo' => 'bar' } })
28
+ it 'has an author' do
29
+ expect(subject).to have_one(:author, JIRA::Resource::User)
24
30
  end
25
31
 
26
- it 'has the correct relationships' do
27
- expect(subject).to have_one(:author, JIRA::Resource::User)
32
+ it 'has the correct author name' do
28
33
  expect(subject.author.foo).to eq('bar')
29
34
  end
30
35
  end
31
36
 
32
- describe '#meta' do
37
+ describe '.meta' do
38
+ subject { JIRA::Resource::Attachment.meta(client) }
39
+
33
40
  let(:response) do
34
41
  double(
35
- 'response',
36
- body: '{"enabled":true,"uploadLimit":10485760}'
42
+ 'response',
43
+ body: '{"enabled":true,"uploadLimit":10485760}'
37
44
  )
38
45
  end
39
46
 
40
47
  it 'returns meta information about attachment upload' do
41
48
  expect(client).to receive(:get).with('/jira/rest/api/2/attachment/meta').and_return(response)
42
- JIRA::Resource::Attachment.meta(client)
49
+
50
+ subject
43
51
  end
44
52
 
45
- subject { JIRA::Resource::AttachmentFactory.new(client) }
53
+ context 'the factory delegates correctly' do
54
+ subject { JIRA::Resource::AttachmentFactory.new(client) }
46
55
 
47
- it 'delegates #meta to to target class' do
48
- expect(subject).to respond_to(:meta)
56
+ it 'delegates #meta to to target class' do
57
+ expect(subject).to respond_to(:meta)
58
+ end
49
59
  end
50
60
  end
51
61
 
52
- describe '#save!' do
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
+
53
85
  it 'successfully update the attachment' do
54
- basic_auth_http_conn = double
55
- response = double(
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(
56
100
  body: [
57
101
  {
58
102
  "id": 10_001,
@@ -64,18 +108,31 @@ describe JIRA::Resource::Attachment do
64
108
  }
65
109
  ].to_json
66
110
  )
111
+ end
112
+ let(:issue) { JIRA::Resource::Issue.new(client) }
67
113
 
68
- allow(client.request_client).to receive(:basic_auth_http_conn).and_return(basic_auth_http_conn)
69
- allow(basic_auth_http_conn).to receive(:request).and_return(response)
114
+ before do
115
+ allow(client).to receive(:post_multipart).and_return(response)
116
+ end
70
117
 
71
- issue = JIRA::Resource::Issue.new(client)
72
- path_to_file = './spec/mock_responses/issue.json'
73
- attachment = JIRA::Resource::Attachment.new(client, issue: issue)
74
- attachment.save!('file' => path_to_file)
118
+ it 'successfully update the attachment' do
119
+ subject
75
120
 
76
121
  expect(attachment.filename).to eq 'picture.jpg'
77
122
  expect(attachment.mimeType).to eq 'image/jpeg'
78
123
  expect(attachment.size).to eq 23_123
79
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
80
137
  end
81
138
  end
@@ -89,7 +89,7 @@ eos
89
89
 
90
90
  allow(issues_response).to receive(:body).and_return(api_json_issues)
91
91
  allow(board).to receive(:id).and_return(84)
92
- expect(client).to receive(:get).with('/rest/agile/1.0/board/84/issue?')
92
+ expect(client).to receive(:get).with('/rest/agile/1.0/board/84/issue')
93
93
  .and_return(issues_response)
94
94
  expect(client).to receive(:Issue).and_return(JIRA::Resource::IssueFactory.new(client))
95
95
 
@@ -172,4 +172,53 @@ eos
172
172
  expect(client).to receive(:Sprint).twice.and_return(JIRA::Resource::SprintFactory.new(client))
173
173
  expect(board.sprints.size).to be(2)
174
174
  end
175
+
176
+ it 'should get board configuration for a board' do
177
+ response = double
178
+
179
+ api_json = <<-eos
180
+ {
181
+ "id":1,
182
+ "name":"My Board",
183
+ "type":"kanban",
184
+ "self":"https://mycompany.atlassian.net/rest/agile/1.0/board/1/configuration",
185
+ "location":{
186
+ "type":"project",
187
+ "key":"MYPROJ",
188
+ "id":"10000",
189
+ "self":"https://mycompany.atlassian.net/rest/api/2/project/10000",
190
+ "name":"My Project"
191
+ },
192
+ "filter":{
193
+ "id":"10000",
194
+ "self":"https://mycompany.atlassian.net/rest/api/2/filter/10000"
195
+ },
196
+ "subQuery":{
197
+ "query":"resolution = EMPTY OR resolution != EMPTY AND resolutiondate >= -5d"
198
+ },
199
+ "columnConfig":{
200
+ "columns":[
201
+ {
202
+ "name":"Backlog",
203
+ "statuses":[
204
+ {
205
+ "id":"10000",
206
+ "self":"https://mycompany.atlassian.net/rest/api/2/status/10000"
207
+ }
208
+ ]
209
+ }
210
+ ],
211
+ "constraintType":"issueCount"
212
+ },
213
+ "ranking":{
214
+ "rankCustomFieldId":10011
215
+ }
216
+ }
217
+ eos
218
+ allow(response).to receive(:body).and_return(api_json)
219
+ allow(board).to receive(:id).and_return(84)
220
+ expect(client).to receive(:get).with('/rest/agile/1.0/board/84/configuration').and_return(response)
221
+ expect(client).to receive(:BoardConfiguration).and_return(JIRA::Resource::BoardConfigurationFactory.new(client))
222
+ expect(board.configuration).not_to be(nil)
223
+ end
175
224
  end
@@ -1,12 +1,25 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe JIRA::Resource::Sprint do
4
- describe 'peristence' do
5
- let(:sprint) { described_class.new(client) }
6
- let(:client) { double('Client', options: { site: 'https://foo.bar.com' }) }
4
+ let(:client) do
5
+ client = double(options: { site: 'https://foo.bar.com', context_path: '/jira' })
6
+ allow(client).to receive(:Sprint).and_return(JIRA::Resource::SprintFactory.new(client))
7
+ client
8
+ end
9
+ let(:sprint) { described_class.new(client) }
10
+ let(:agile_sprint_path) { "#{sprint.client.options[:context_path]}/rest/agile/1.0/sprint/#{sprint.id}" }
7
11
 
12
+ describe '::find' do
13
+ let(:response) { double('Response', body: '{"some_detail":"some detail"}') }
14
+
15
+ it 'fetches the sprint from JIRA' do
16
+ expect(client).to receive(:get).with('/jira/rest/agile/1.0/sprint/111').and_return(response)
17
+ expect(JIRA::Resource::Sprint.find(client, '111')).to be_a(JIRA::Resource::Sprint)
18
+ end
19
+ end
20
+
21
+ describe 'peristence' do
8
22
  describe '#save' do
9
- let(:agile_sprint_url) { "#{sprint.client.options[:site]}/rest/agile/1.0/sprint/#{sprint.id}" }
10
23
  let(:instance_attrs) { { start_date: '2016-06-01' } }
11
24
 
12
25
  before do
@@ -17,7 +30,7 @@ describe JIRA::Resource::Sprint do
17
30
  let(:given_attrs) { { start_date: '2016-06-10' } }
18
31
 
19
32
  it 'calls save on the super class with the given attributes & agile url' do
20
- expect_any_instance_of(JIRA::Base).to receive(:save).with(given_attrs, agile_sprint_url)
33
+ expect_any_instance_of(JIRA::Base).to receive(:save).with(given_attrs, agile_sprint_path)
21
34
 
22
35
  sprint.save(given_attrs)
23
36
  end
@@ -25,7 +38,7 @@ describe JIRA::Resource::Sprint do
25
38
 
26
39
  context 'when attributes are not specified' do
27
40
  it 'calls save on the super class with the instance attributes & agile url' do
28
- expect_any_instance_of(JIRA::Base).to receive(:save).with(instance_attrs, agile_sprint_url)
41
+ expect_any_instance_of(JIRA::Base).to receive(:save).with(instance_attrs, agile_sprint_path)
29
42
 
30
43
  sprint.save
31
44
  end
@@ -33,7 +46,7 @@ describe JIRA::Resource::Sprint do
33
46
 
34
47
  context 'when providing the path argument' do
35
48
  it 'ignores it' do
36
- expect_any_instance_of(JIRA::Base).to receive(:save).with(instance_attrs, agile_sprint_url)
49
+ expect_any_instance_of(JIRA::Base).to receive(:save).with(instance_attrs, agile_sprint_path)
37
50
 
38
51
  sprint.save({}, 'mavenlink.com')
39
52
  end
@@ -41,7 +54,6 @@ describe JIRA::Resource::Sprint do
41
54
  end
42
55
 
43
56
  describe '#save!' do
44
- let(:agile_sprint_url) { "#{sprint.client.options[:site]}/rest/agile/1.0/sprint/#{sprint.id}" }
45
57
  let(:instance_attrs) { { start_date: '2016-06-01' } }
46
58
 
47
59
  before do
@@ -52,7 +64,7 @@ describe JIRA::Resource::Sprint do
52
64
  let(:given_attrs) { { start_date: '2016-06-10' } }
53
65
 
54
66
  it 'calls save! on the super class with the given attributes & agile url' do
55
- expect_any_instance_of(JIRA::Base).to receive(:save!).with(given_attrs, agile_sprint_url)
67
+ expect_any_instance_of(JIRA::Base).to receive(:save!).with(given_attrs, agile_sprint_path)
56
68
 
57
69
  sprint.save!(given_attrs)
58
70
  end
@@ -60,7 +72,7 @@ describe JIRA::Resource::Sprint do
60
72
 
61
73
  context 'when attributes are not specified' do
62
74
  it 'calls save! on the super class with the instance attributes & agile url' do
63
- expect_any_instance_of(JIRA::Base).to receive(:save!).with(instance_attrs, agile_sprint_url)
75
+ expect_any_instance_of(JIRA::Base).to receive(:save!).with(instance_attrs, agile_sprint_path)
64
76
 
65
77
  sprint.save!
66
78
  end
@@ -68,7 +80,7 @@ describe JIRA::Resource::Sprint do
68
80
 
69
81
  context 'when providing the path argument' do
70
82
  it 'ignores it' do
71
- expect_any_instance_of(JIRA::Base).to receive(:save!).with(instance_attrs, agile_sprint_url)
83
+ expect_any_instance_of(JIRA::Base).to receive(:save!).with(instance_attrs, agile_sprint_path)
72
84
 
73
85
  sprint.save!({}, 'mavenlink.com')
74
86
  end