Skip to content

Commit

Permalink
Merge pull request #418 from marlinpierce/kostyasha-patch-1
Browse files Browse the repository at this point in the history
Allow adding multiple issues
  • Loading branch information
bobbrodie authored Apr 1, 2024
2 parents c04e6df + 2a1313e commit 69857f6
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/jira/resource/sprint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ def issues(options = {})
end

def add_issue(issue)
request_body = { issues: [issue.id] }.to_json
response = client.post("#{agile_path}/issue", request_body)
add_issues( [ issue ])
end

def add_issues(issues)
issue_ids = issues.map{ |issue| issue.id }
request_body = { issues: issue_ids }.to_json
client.post("#{agile_path}/issue", request_body)
true
end

Expand Down
57 changes: 57 additions & 0 deletions spec/jira/resource/sprint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,62 @@
end
end
end

context 'an issue exists' do
let(:issue_id) { 1001 }
let(:post_issue_path) do
described_class.agile_path(client, sprint.id)
"/jira/rest/agile/1.0/sprint//issue"
end
let(:issue) do
issue = double
allow(issue).to receive(:id).and_return(issue_id)
issue
end
let(:post_issue_input) do
{"issues":[issue.id]}
end


describe '#add_issu' do
context 'when an issue is passed' do

it 'posts with the issue id' do
expect(client).to receive(:post).with(post_issue_path, post_issue_input.to_json)

sprint.add_issue(issue)
end
end
end
end

context 'multiple issues exists' do
let(:issue_ids) { [ 1001, 1012 ] }
let(:post_issue_path) do
described_class.agile_path(client, sprint.id)
"/jira/rest/agile/1.0/sprint//issue"
end
let(:issues) do
issue_ids.map do |issue_id|
issue = double
allow(issue).to receive(:id).and_return(issue_id)
issue
end
end
let(:post_issue_input) do
{"issues": issue_ids}
end

describe '#add_issues' do
context 'when an issue is passed' do

it 'posts with the issue id' do
expect(client).to receive(:post).with(post_issue_path, post_issue_input.to_json)

sprint.add_issues(issues)
end
end
end
end
end
end

0 comments on commit 69857f6

Please sign in to comment.