2012-07-24 08:19:51 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2014-04-11 15:45:56 -04:00
|
|
|
describe API::API, api: true do
|
2012-08-25 13:31:50 -04:00
|
|
|
include ApiHelpers
|
2012-11-05 22:31:55 -05:00
|
|
|
let(:user) { create(:user) }
|
2013-01-02 12:32:34 -05:00
|
|
|
let!(:project) { create(:project, namespace: user.namespace ) }
|
2014-09-04 18:01:12 -04:00
|
|
|
let!(:closed_issue) do
|
|
|
|
create :closed_issue,
|
|
|
|
author: user,
|
|
|
|
assignee: user,
|
|
|
|
project: project,
|
|
|
|
state: :closed,
|
|
|
|
milestone: milestone
|
|
|
|
end
|
|
|
|
let!(:issue) do
|
|
|
|
create :issue,
|
|
|
|
author: user,
|
|
|
|
assignee: user,
|
|
|
|
project: project,
|
|
|
|
milestone: milestone
|
|
|
|
end
|
2014-08-14 04:17:52 -04:00
|
|
|
let!(:label) do
|
|
|
|
create(:label, title: 'label', color: '#FFAABB', project: project)
|
|
|
|
end
|
2014-08-14 10:17:19 -04:00
|
|
|
let!(:label_link) { create(:label_link, label: label, target: issue) }
|
2014-09-04 18:01:12 -04:00
|
|
|
let!(:milestone) { create(:milestone, title: '1.0.0', project: project) }
|
|
|
|
let!(:empty_milestone) do
|
|
|
|
create(:milestone, title: '2.0.0', project: project)
|
|
|
|
end
|
2014-08-14 04:17:52 -04:00
|
|
|
|
2013-01-04 11:50:31 -05:00
|
|
|
before { project.team << [user, :reporter] }
|
2012-07-24 08:19:51 -04:00
|
|
|
|
|
|
|
describe "GET /issues" do
|
2012-09-12 08:11:56 -04:00
|
|
|
context "when unauthenticated" do
|
|
|
|
it "should return authentication error" do
|
|
|
|
get api("/issues")
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(401)
|
2012-09-12 08:11:56 -04:00
|
|
|
end
|
2012-07-24 08:19:51 -04:00
|
|
|
end
|
|
|
|
|
2012-09-12 08:11:56 -04:00
|
|
|
context "when authenticated" do
|
2012-07-24 08:19:51 -04:00
|
|
|
it "should return an array of issues" do
|
2012-08-25 13:43:55 -04:00
|
|
|
get api("/issues", user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.first['title']).to eq(issue.title)
|
2012-07-24 08:19:51 -04:00
|
|
|
end
|
2013-10-29 05:41:20 -04:00
|
|
|
|
|
|
|
it "should add pagination headers" do
|
|
|
|
get api("/issues?per_page=3", user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.headers['Link']).to eq(
|
2013-10-29 05:41:20 -04:00
|
|
|
'<http://www.example.com/api/v3/issues?page=1&per_page=3>; rel="first", <http://www.example.com/api/v3/issues?page=1&per_page=3>; rel="last"'
|
2015-02-12 13:17:35 -05:00
|
|
|
)
|
2013-10-29 05:41:20 -04:00
|
|
|
end
|
2014-08-14 06:41:16 -04:00
|
|
|
|
|
|
|
it 'should return an array of closed issues' do
|
|
|
|
get api('/issues?state=closed', user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(1)
|
|
|
|
expect(json_response.first['id']).to eq(closed_issue.id)
|
2014-08-14 06:41:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return an array of opened issues' do
|
|
|
|
get api('/issues?state=opened', user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(1)
|
|
|
|
expect(json_response.first['id']).to eq(issue.id)
|
2014-08-14 06:41:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return an array of all issues' do
|
|
|
|
get api('/issues?state=all', user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(2)
|
|
|
|
expect(json_response.first['id']).to eq(issue.id)
|
|
|
|
expect(json_response.second['id']).to eq(closed_issue.id)
|
2014-08-14 06:41:16 -04:00
|
|
|
end
|
2014-08-14 10:17:19 -04:00
|
|
|
|
|
|
|
it 'should return an array of labeled issues' do
|
|
|
|
get api("/issues?labels=#{label.title}", user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(1)
|
|
|
|
expect(json_response.first['labels']).to eq([label.title])
|
2014-08-14 10:17:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return an array of labeled issues when at least one label matches' do
|
|
|
|
get api("/issues?labels=#{label.title},foo,bar", user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(1)
|
|
|
|
expect(json_response.first['labels']).to eq([label.title])
|
2014-08-14 10:17:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return an empty array if no issue matches labels' do
|
|
|
|
get api('/issues?labels=foo,bar', user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(0)
|
2014-08-14 10:17:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return an array of labeled issues matching given state' do
|
|
|
|
get api("/issues?labels=#{label.title}&state=opened", user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(1)
|
|
|
|
expect(json_response.first['labels']).to eq([label.title])
|
|
|
|
expect(json_response.first['state']).to eq('opened')
|
2014-08-14 10:17:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return an empty array if no issue matches labels and state filters' do
|
|
|
|
get api("/issues?labels=#{label.title}&state=closed", user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(0)
|
2014-08-14 10:17:19 -04:00
|
|
|
end
|
2012-07-24 08:19:51 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "GET /projects/:id/issues" do
|
2014-09-04 18:01:12 -04:00
|
|
|
let(:base_url) { "/projects/#{project.id}" }
|
|
|
|
let(:title) { milestone.title }
|
|
|
|
|
2012-07-24 08:19:51 -04:00
|
|
|
it "should return project issues" do
|
2014-09-04 18:01:12 -04:00
|
|
|
get api("#{base_url}/issues", user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.first['title']).to eq(issue.title)
|
2012-07-24 08:19:51 -04:00
|
|
|
end
|
2014-08-14 10:17:19 -04:00
|
|
|
|
|
|
|
it 'should return an array of labeled project issues' do
|
2014-09-04 18:01:12 -04:00
|
|
|
get api("#{base_url}/issues?labels=#{label.title}", user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(1)
|
|
|
|
expect(json_response.first['labels']).to eq([label.title])
|
2014-08-14 10:17:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return an array of labeled project issues when at least one label matches' do
|
2014-09-04 18:01:12 -04:00
|
|
|
get api("#{base_url}/issues?labels=#{label.title},foo,bar", user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(1)
|
|
|
|
expect(json_response.first['labels']).to eq([label.title])
|
2014-08-14 10:17:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return an empty array if no project issue matches labels' do
|
2014-09-04 18:01:12 -04:00
|
|
|
get api("#{base_url}/issues?labels=foo,bar", user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(0)
|
2014-09-04 18:01:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return an empty array if no issue matches milestone' do
|
|
|
|
get api("#{base_url}/issues?milestone=#{empty_milestone.title}", user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(0)
|
2014-08-14 10:17:19 -04:00
|
|
|
end
|
2014-09-04 18:01:12 -04:00
|
|
|
|
|
|
|
it 'should return an empty array if milestone does not exist' do
|
|
|
|
get api("#{base_url}/issues?milestone=foo", user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(0)
|
2014-09-04 18:01:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return an array of issues in given milestone' do
|
|
|
|
get api("#{base_url}/issues?milestone=#{title}", user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(2)
|
|
|
|
expect(json_response.first['id']).to eq(issue.id)
|
|
|
|
expect(json_response.second['id']).to eq(closed_issue.id)
|
2014-09-04 18:01:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return an array of issues matching state in milestone' do
|
|
|
|
get api("#{base_url}/issues?milestone=#{milestone.title}"\
|
|
|
|
'&state=closed', user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.length).to eq(1)
|
|
|
|
expect(json_response.first['id']).to eq(closed_issue.id)
|
2014-09-04 18:01:12 -04:00
|
|
|
end
|
2012-07-24 08:19:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "GET /projects/:id/issues/:issue_id" do
|
|
|
|
it "should return a project issue by id" do
|
2013-01-02 12:46:06 -05:00
|
|
|
get api("/projects/#{project.id}/issues/#{issue.id}", user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response['title']).to eq(issue.title)
|
|
|
|
expect(json_response['iid']).to eq(issue.iid)
|
2012-07-24 08:19:51 -04:00
|
|
|
end
|
2013-02-27 08:36:20 -05:00
|
|
|
|
2015-01-17 17:45:39 -05:00
|
|
|
it 'should return a project issue by iid' do
|
|
|
|
get api("/projects/#{project.id}/issues?iid=#{issue.iid}", user)
|
2015-06-13 18:24:51 -04:00
|
|
|
expect(response.status).to eq 200
|
|
|
|
expect(json_response.first['title']).to eq issue.title
|
|
|
|
expect(json_response.first['id']).to eq issue.id
|
|
|
|
expect(json_response.first['iid']).to eq issue.iid
|
2015-01-17 17:45:39 -05:00
|
|
|
end
|
|
|
|
|
2013-02-27 08:36:20 -05:00
|
|
|
it "should return 404 if issue id not found" do
|
|
|
|
get api("/projects/#{project.id}/issues/54321", user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(404)
|
2013-02-27 08:36:20 -05:00
|
|
|
end
|
2012-07-24 08:19:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "POST /projects/:id/issues" do
|
|
|
|
it "should create a new project issue" do
|
2013-01-02 12:46:06 -05:00
|
|
|
post api("/projects/#{project.id}/issues", user),
|
2012-08-10 18:07:50 -04:00
|
|
|
title: 'new issue', labels: 'label, label2'
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(201)
|
|
|
|
expect(json_response['title']).to eq('new issue')
|
|
|
|
expect(json_response['description']).to be_nil
|
|
|
|
expect(json_response['labels']).to eq(['label', 'label2'])
|
2012-07-24 08:19:51 -04:00
|
|
|
end
|
2013-02-27 08:36:20 -05:00
|
|
|
|
|
|
|
it "should return a 400 bad request if title not given" do
|
|
|
|
post api("/projects/#{project.id}/issues", user), labels: 'label, label2'
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(400)
|
2013-02-27 08:36:20 -05:00
|
|
|
end
|
2014-08-14 04:17:52 -04:00
|
|
|
|
2014-08-17 16:22:01 -04:00
|
|
|
it 'should return 400 on invalid label names' do
|
2014-08-14 04:17:52 -04:00
|
|
|
post api("/projects/#{project.id}/issues", user),
|
|
|
|
title: 'new issue',
|
|
|
|
labels: 'label, ?'
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(400)
|
|
|
|
expect(json_response['message']['labels']['?']['title']).to eq(['is invalid'])
|
2014-08-14 04:17:52 -04:00
|
|
|
end
|
2014-08-18 14:09:09 -04:00
|
|
|
|
|
|
|
it 'should return 400 if title is too long' do
|
|
|
|
post api("/projects/#{project.id}/issues", user),
|
|
|
|
title: 'g' * 256
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(400)
|
|
|
|
expect(json_response['message']['title']).to eq([
|
2014-08-18 14:09:09 -04:00
|
|
|
'is too long (maximum is 255 characters)'
|
2015-02-12 13:17:35 -05:00
|
|
|
])
|
2014-08-18 14:09:09 -04:00
|
|
|
end
|
2012-07-24 08:19:51 -04:00
|
|
|
end
|
|
|
|
|
2013-02-18 04:10:58 -05:00
|
|
|
describe "PUT /projects/:id/issues/:issue_id to update only title" do
|
2012-07-24 08:19:51 -04:00
|
|
|
it "should update a project issue" do
|
2013-01-02 12:46:06 -05:00
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}", user),
|
2013-02-18 04:10:58 -05:00
|
|
|
title: 'updated title'
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
2013-02-18 04:10:58 -05:00
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response['title']).to eq('updated title')
|
2013-02-18 04:10:58 -05:00
|
|
|
end
|
2013-02-27 08:36:20 -05:00
|
|
|
|
|
|
|
it "should return 404 error if issue id not found" do
|
|
|
|
put api("/projects/#{project.id}/issues/44444", user),
|
|
|
|
title: 'updated title'
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(404)
|
2013-02-27 08:36:20 -05:00
|
|
|
end
|
2014-08-14 04:17:52 -04:00
|
|
|
|
2014-08-17 16:22:01 -04:00
|
|
|
it 'should return 400 on invalid label names' do
|
2014-08-14 04:17:52 -04:00
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}", user),
|
|
|
|
title: 'updated title',
|
|
|
|
labels: 'label, ?'
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(400)
|
|
|
|
expect(json_response['message']['labels']['?']['title']).to eq(['is invalid'])
|
2014-08-17 16:22:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PUT /projects/:id/issues/:issue_id to update labels' do
|
|
|
|
let!(:label) { create(:label, title: 'dummy', project: project) }
|
|
|
|
let!(:label_link) { create(:label_link, label: label, target: issue) }
|
|
|
|
|
|
|
|
it 'should not update labels if not present' do
|
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}", user),
|
|
|
|
title: 'updated title'
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response['labels']).to eq([label.title])
|
2014-08-17 16:22:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should remove all labels' do
|
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}", user),
|
|
|
|
labels: ''
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response['labels']).to eq([])
|
2014-08-17 16:22:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should update labels' do
|
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}", user),
|
|
|
|
labels: 'foo,bar'
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response['labels']).to include 'foo'
|
|
|
|
expect(json_response['labels']).to include 'bar'
|
2014-08-17 16:22:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return 400 on invalid label names' do
|
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}", user),
|
|
|
|
labels: 'label, ?'
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(400)
|
|
|
|
expect(json_response['message']['labels']['?']['title']).to eq(['is invalid'])
|
2014-08-17 16:22:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should allow special label names' do
|
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}", user),
|
|
|
|
labels: 'label:foo, label-bar,label_bar,label/bar'
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response['labels']).to include 'label:foo'
|
|
|
|
expect(json_response['labels']).to include 'label-bar'
|
|
|
|
expect(json_response['labels']).to include 'label_bar'
|
|
|
|
expect(json_response['labels']).to include 'label/bar'
|
2014-08-14 04:17:52 -04:00
|
|
|
end
|
2014-08-18 14:09:09 -04:00
|
|
|
|
|
|
|
it 'should return 400 if title is too long' do
|
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}", user),
|
|
|
|
title: 'g' * 256
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(400)
|
|
|
|
expect(json_response['message']['title']).to eq([
|
2014-08-18 14:09:09 -04:00
|
|
|
'is too long (maximum is 255 characters)'
|
2015-02-12 13:17:35 -05:00
|
|
|
])
|
2014-08-18 14:09:09 -04:00
|
|
|
end
|
2013-02-18 04:10:58 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "PUT /projects/:id/issues/:issue_id to update state and label" do
|
|
|
|
it "should update a project issue" do
|
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}", user),
|
|
|
|
labels: 'label2', state_event: "close"
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
2013-02-18 04:10:58 -05:00
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response['labels']).to include 'label2'
|
|
|
|
expect(json_response['state']).to eq "closed"
|
2012-07-24 08:19:51 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "DELETE /projects/:id/issues/:issue_id" do
|
|
|
|
it "should delete a project issue" do
|
2013-01-02 12:46:06 -05:00
|
|
|
delete api("/projects/#{project.id}/issues/#{issue.id}", user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(405)
|
2012-07-24 08:19:51 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|