gitlab-org--gitlab-foss/spec/requests/api/labels_spec.rb

171 lines
5.5 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe API::API, api: true do
include ApiHelpers
let(:user) { create(:user) }
let(:project) { create(:project, creator_id: user.id, namespace: user.namespace) }
let!(:label1) { create(:label, title: 'label1', project: project) }
before do
project.team << [user, :master]
end
describe 'GET /projects/:id/labels' do
it 'should return project labels' do
get api("/projects/#{project.id}/labels", user)
response.status.should == 200
json_response.should be_an Array
json_response.size.should == 1
json_response.first['name'].should == label1.name
end
end
2014-08-12 08:16:25 -04:00
describe 'POST /projects/:id/labels' do
it 'should return created label' do
post api("/projects/#{project.id}/labels", user),
name: 'Foo',
color: '#FFAABB'
response.status.should == 201
json_response['name'].should == 'Foo'
json_response['color'].should == '#FFAABB'
end
it 'should return a 400 bad request if name not given' do
post api("/projects/#{project.id}/labels", user), color: '#FFAABB'
response.status.should == 400
end
it 'should return a 400 bad request if color not given' do
post api("/projects/#{project.id}/labels", user), name: 'Foobar'
response.status.should == 400
end
2014-08-17 18:25:49 -04:00
it 'should return 400 for invalid color' do
2014-08-12 08:16:25 -04:00
post api("/projects/#{project.id}/labels", user),
name: 'Foo',
color: '#FFAA'
2014-08-17 18:25:49 -04:00
response.status.should == 400
json_response['message']['color'].should == ['is invalid']
2014-08-12 08:16:25 -04:00
end
it 'should return 400 for too long color code' do
post api("/projects/#{project.id}/labels", user),
name: 'Foo',
color: '#FFAAFFFF'
response.status.should == 400
json_response['message']['color'].should == ['is invalid']
end
2014-08-17 18:25:49 -04:00
it 'should return 400 for invalid name' do
2014-08-12 08:16:25 -04:00
post api("/projects/#{project.id}/labels", user),
name: '?',
color: '#FFAABB'
2014-08-17 18:25:49 -04:00
response.status.should == 400
json_response['message']['title'].should == ['is invalid']
2014-08-12 08:16:25 -04:00
end
it 'should return 409 if label already exists' do
post api("/projects/#{project.id}/labels", user),
name: 'label1',
color: '#FFAABB'
response.status.should == 409
json_response['message'].should == 'Label already exists'
end
end
describe 'DELETE /projects/:id/labels' do
it 'should return 200 for existing label' do
2014-08-13 06:23:51 -04:00
delete api("/projects/#{project.id}/labels", user), name: 'label1'
2014-08-12 08:16:25 -04:00
response.status.should == 200
end
it 'should return 404 for non existing label' do
2014-08-13 06:23:51 -04:00
delete api("/projects/#{project.id}/labels", user), name: 'label2'
2014-08-12 08:16:25 -04:00
response.status.should == 404
json_response['message'].should == '404 Label Not Found'
2014-08-12 08:16:25 -04:00
end
it 'should return 400 for wrong parameters' do
delete api("/projects/#{project.id}/labels", user)
response.status.should == 400
end
end
2014-08-13 06:23:51 -04:00
describe 'PUT /projects/:id/labels' do
it 'should return 200 if name and colors are changed' do
put api("/projects/#{project.id}/labels", user),
name: 'label1',
new_name: 'New Label',
color: '#FFFFFF'
response.status.should == 200
json_response['name'].should == 'New Label'
json_response['color'].should == '#FFFFFF'
end
it 'should return 200 if name is changed' do
put api("/projects/#{project.id}/labels", user),
name: 'label1',
new_name: 'New Label'
response.status.should == 200
json_response['name'].should == 'New Label'
json_response['color'].should == label1.color
end
it 'should return 200 if colors is changed' do
put api("/projects/#{project.id}/labels", user),
name: 'label1',
color: '#FFFFFF'
response.status.should == 200
json_response['name'].should == label1.name
json_response['color'].should == '#FFFFFF'
end
it 'should return 404 if label does not exist' do
put api("/projects/#{project.id}/labels", user),
name: 'label2',
new_name: 'label3'
response.status.should == 404
end
it 'should return 400 if no label name given' do
put api("/projects/#{project.id}/labels", user), new_name: 'label2'
response.status.should == 400
json_response['message'].should == '400 (Bad request) "name" not given'
2014-08-13 06:23:51 -04:00
end
it 'should return 400 if no new parameters given' do
put api("/projects/#{project.id}/labels", user), name: 'label1'
response.status.should == 400
json_response['message'].should == 'Required parameters '\
'"new_name" or "color" missing'
2014-08-13 06:23:51 -04:00
end
2014-08-17 18:25:49 -04:00
it 'should return 400 for invalid name' do
2014-08-13 06:23:51 -04:00
put api("/projects/#{project.id}/labels", user),
name: 'label1',
new_name: '?',
color: '#FFFFFF'
2014-08-17 18:25:49 -04:00
response.status.should == 400
json_response['message']['title'].should == ['is invalid']
2014-08-13 06:23:51 -04:00
end
2014-08-17 18:25:49 -04:00
it 'should return 400 for invalid name' do
2014-08-13 06:23:51 -04:00
put api("/projects/#{project.id}/labels", user),
name: 'label1',
color: '#FF'
2014-08-17 18:25:49 -04:00
response.status.should == 400
json_response['message']['color'].should == ['is invalid']
2014-08-13 06:23:51 -04:00
end
it 'should return 400 for too long color code' do
post api("/projects/#{project.id}/labels", user),
name: 'Foo',
color: '#FFAAFFFF'
response.status.should == 400
json_response['message']['color'].should == ['is invalid']
end
2014-08-13 06:23:51 -04:00
end
end