Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for sprints and fix complete_date #445

Merged
merged 2 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/jira-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
require 'jira/resource/issue_picker_suggestions'
require 'jira/resource/remotelink'
require 'jira/resource/sprint'
require 'jira/resource/sprint_report'
require 'jira/resource/resolution'
require 'jira/resource/issue'
require 'jira/resource/filter'
Expand Down
4 changes: 0 additions & 4 deletions lib/jira/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,6 @@ def Sprint
JIRA::Resource::SprintFactory.new(self)
end

def SprintReport
JIRA::Resource::SprintReportFactory.new(self)
end

def ServerInfo
JIRA::Resource::ServerInfoFactory.new(self)
end
Expand Down
18 changes: 7 additions & 11 deletions lib/jira/resource/sprint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,22 @@ def self.find(client, key)

# get all issues of sprint
def issues(options = {})
jql = 'sprint = ' + id.to_s
jql = "sprint = #{id.to_s}"
jql += " and updated >= '#{options[:updated]}'" if options[:updated]
Issue.jql(client, jql)
end

def add_issue(issue)
add_issues( [ issue ])
add_issues([issue])
end

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

def sprint_report
get_sprint_details_attribute('sprint_report')
end

def start_date
get_sprint_details_attribute('start_date')
end
Expand All @@ -47,6 +43,7 @@ def complete_date
def get_sprint_details_attribute(attribute_name)
attribute = instance_variable_get("@#{attribute_name}")
return attribute if attribute

get_sprint_details
instance_variable_get("@#{attribute_name}")
end
Expand All @@ -61,10 +58,9 @@ def get_sprint_details
end
json = self.class.parse_json(response.body)

@start_date = json['sprint']['startDate'] && Date.parse(json['sprint']['startDate'])
@end_date = json['sprint']['endDate'] && Date.parse(json['sprint']['endDate'])
@completed_date = json['sprint']['completeDate'] && Date.parse(json['sprint']['completeDate'])
@sprint_report = client.SprintReport.build(json['contents'])
@start_date = json['startDate'] && Date.parse(json['startDate'])
@end_date = json['endDate'] && Date.parse(json['endDate'])
@complete_date = json['completeDate'] && Date.parse(json['completeDate'])
end

def save(attrs = {}, _path = nil)
Expand Down
8 changes: 0 additions & 8 deletions lib/jira/resource/sprint_report.rb

This file was deleted.

27 changes: 18 additions & 9 deletions spec/jira/resource/sprint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@

describe JIRA::Resource::Sprint do
let(:client) do
client = double(options: { site: 'https://foo.bar.com', context_path: '/jira' })
client = double(options: { rest_base_path: '/jira/rest/api/2', context_path: '/jira' })
allow(client).to receive(:Sprint).and_return(JIRA::Resource::SprintFactory.new(client))
client
end
let(:sprint) { described_class.new(client) }
let(:agile_sprint_path) { "#{sprint.client.options[:context_path]}/rest/agile/1.0/sprint/#{sprint.id}" }
let(:agile_sprint_path) { "/jira/rest/agile/1.0/sprint/#{sprint.id}" }
let(:response) { double }

describe 'get_sprint_details' do
let(:sprint) { JIRA::Resource::Sprint.find(client, '1') }
it 'check each of the date attributes' do
allow(client).to receive(:get).and_return(double(body: get_mock_response('sprint/1.json')))

expect(sprint.start_date).to eq Date.parse('2024-01-01T03:20:00.000Z')
expect(sprint.end_date).to eq Date.parse('2024-01-15T03:20:00.000Z')
expect(sprint.complete_date).to eq Date.parse('2024-01-16T03:48:00.000Z')
end
end

describe '::find' do
let(:response) { double('Response', body: '{"some_detail":"some detail"}') }
Expand Down Expand Up @@ -91,21 +103,19 @@
let(:issue_id) { 1001 }
let(:post_issue_path) do
described_class.agile_path(client, sprint.id)
"/jira/rest/agile/1.0/sprint//issue"
'/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]}
{ "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)

Expand All @@ -119,7 +129,7 @@
let(:issue_ids) { [ 1001, 1012 ] }
let(:post_issue_path) do
described_class.agile_path(client, sprint.id)
"/jira/rest/agile/1.0/sprint//issue"
'/jira/rest/agile/1.0/sprint//issue'
end
let(:issues) do
issue_ids.map do |issue_id|
Expand All @@ -129,12 +139,11 @@
end
end
let(:post_issue_input) do
{"issues": issue_ids}
{ "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)

Expand Down
13 changes: 13 additions & 0 deletions spec/mock_responses/sprint/1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"id": 1,
"self": "https://localhost:2990/jira/rest/agile/1.0/sprint/1",
"state": "closed",
"name": "SP Sprint 1",
"startDate": "2024-01-01T03:20:00.000Z",
"endDate": "2024-01-15T03:20:00.000Z",
"completeDate": "2024-01-16T03:48:00.000Z",
"createdDate": "2024-01-01T00:00:00.000Z",
"originBoardId": 1,
"goal": "",
"rapidview_id": 1
}