2019-12-26 22:10:19 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe API::Labels do
|
2019-12-21 20:55:43 +05:30
|
|
|
def put_labels_api(route_type, user, spec_params, request_params = {})
|
|
|
|
if route_type == :deprecated
|
|
|
|
put api("/projects/#{project.id}/labels", user),
|
|
|
|
params: request_params.merge(spec_params)
|
|
|
|
else
|
|
|
|
label_id = spec_params[:name] || spec_params[:label_id]
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
put api("/projects/#{project.id}/labels/#{ERB::Util.url_encode(label_id)}", user),
|
2019-12-21 20:55:43 +05:30
|
|
|
params: request_params.merge(spec_params.except(:name, :id))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
let_it_be(:valid_label_title_1) { 'Label foo & bar:subgroup::v.1' }
|
|
|
|
let_it_be(:valid_label_title_1_esc) { ERB::Util.url_encode(valid_label_title_1) }
|
|
|
|
let_it_be(:valid_label_title_2) { 'Label bar & foo:subgroup::v.2' }
|
|
|
|
let_it_be(:valid_group_label_title_1) { 'Group label foobar:sub::v.1' }
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
let(:user) { create(:user) }
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:project) { create(:project, creator_id: user.id, namespace: user.namespace) }
|
2021-03-11 19:13:27 +05:30
|
|
|
let!(:label1) { create(:label, description: 'the best label v.1', title: valid_label_title_1, project: project) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let!(:priority_label) { create(:label, title: 'bug', project: project, priority: 3) }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
route_types = [:deprecated, :rest]
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
shared_examples 'label update API' do
|
|
|
|
route_types.each do |route_type|
|
|
|
|
it "returns 200 if name is changed (#{route_type} route)" do
|
2021-03-11 19:13:27 +05:30
|
|
|
put_labels_api(route_type, user, spec_params, new_name: valid_label_title_2)
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(json_response['name']).to eq(valid_label_title_2)
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(json_response['color']).to eq(label1.color)
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
it "returns 200 if colors is changed (#{route_type} route)" do
|
|
|
|
put_labels_api(route_type, user, spec_params, color: '#FFFFFF')
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(json_response['name']).to eq(label1.name)
|
|
|
|
expect(json_response['color']).to eq('#FFFFFF')
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
it "returns 200 if a priority is added (#{route_type} route)" do
|
|
|
|
put_labels_api(route_type, user, spec_params, priority: 3)
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(json_response['name']).to eq(label1.name)
|
|
|
|
expect(json_response['priority']).to eq(3)
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
it "returns 400 if no new parameters given (#{route_type} route)" do
|
|
|
|
put_labels_api(route_type, user, spec_params)
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2021-09-04 01:27:46 +05:30
|
|
|
expect(json_response['error']).to eq('new_name, color, description, priority are missing, '\
|
2019-12-21 20:55:43 +05:30
|
|
|
'at least one parameter must be provided')
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
it "returns 400 when color code is too short (#{route_type} route)" do
|
|
|
|
put_labels_api(route_type, user, spec_params, color: '#FF')
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(json_response['message']['color']).to eq(['must be a valid color code'])
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
it "returns 400 for too long color code (#{route_type} route)" do
|
|
|
|
put_labels_api(route_type, user, spec_params, color: '#FFAAFFFF')
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(json_response['message']['color']).to eq(['must be a valid color code'])
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
it "returns 400 for invalid priority (#{route_type} route)" do
|
|
|
|
put_labels_api(route_type, user, spec_params, priority: 'foo')
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
it "returns 200 if name and colors and description are changed (#{route_type} route)" do
|
2021-03-11 19:13:27 +05:30
|
|
|
put_labels_api(route_type, user, spec_params, new_name: valid_label_title_2, color: '#FFFFFF', description: 'test')
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(json_response['name']).to eq(valid_label_title_2)
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(json_response['color']).to eq('#FFFFFF')
|
|
|
|
expect(json_response['description']).to eq('test')
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
it "returns 400 for invalid name (#{route_type} route)" do
|
|
|
|
put_labels_api(route_type, user, spec_params, new_name: ',', color: '#FFFFFF')
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(json_response['message']['title']).to eq(['is invalid'])
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
it "returns 200 if description is changed (#{route_type} route)" do
|
|
|
|
put_labels_api(route_type, user, spec_params, description: 'test')
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(json_response['id']).to eq(expected_response_label_id)
|
|
|
|
expect(json_response['description']).to eq('test')
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
it "returns 200 if priority is changed (#{route_type} route)" do
|
|
|
|
put_labels_api(route_type, user, spec_params, priority: 10)
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(json_response['id']).to eq(expected_response_label_id)
|
|
|
|
expect(json_response['priority']).to eq(10)
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
it 'returns 200 if a priority is removed (deprecated route)' do
|
|
|
|
label = find_by_spec_params(spec_params)
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(label).not_to be_nil
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
label.priorities.create!(project: label.project, priority: 1)
|
2019-12-21 20:55:43 +05:30
|
|
|
label.save!
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
request_params = {
|
2019-12-21 20:55:43 +05:30
|
|
|
priority: nil
|
2019-12-04 20:38:33 +05:30
|
|
|
}.merge(spec_params)
|
|
|
|
|
|
|
|
put api("/projects/#{project.id}/labels", user),
|
|
|
|
params: request_params
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(json_response['id']).to eq(expected_response_label_id)
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(json_response['priority']).to be_nil
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
it 'returns 200 if a priority is removed (rest route)' do
|
2019-12-04 20:38:33 +05:30
|
|
|
label = find_by_spec_params(spec_params)
|
|
|
|
expect(label).not_to be_nil
|
2019-12-21 20:55:43 +05:30
|
|
|
label_id = spec_params[:name] || spec_params[:label_id]
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
label.priorities.create!(project: label.project, priority: 1)
|
2019-12-04 20:38:33 +05:30
|
|
|
label.save!
|
|
|
|
|
|
|
|
request_params = {
|
|
|
|
priority: nil
|
2019-12-21 20:55:43 +05:30
|
|
|
}.merge(spec_params.except(:name, :id))
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
put api("/projects/#{project.id}/labels/#{ERB::Util.url_encode(label_id)}", user),
|
2019-12-04 20:38:33 +05:30
|
|
|
params: request_params
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(json_response['id']).to eq(expected_response_label_id)
|
|
|
|
expect(json_response['priority']).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_by_spec_params(params)
|
|
|
|
if params.key?(:label_id)
|
|
|
|
Label.find(params[:label_id])
|
|
|
|
else
|
|
|
|
Label.find_by(name: params[:name])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'label delete API' do
|
2019-12-21 20:55:43 +05:30
|
|
|
it 'returns 204 for existing label (deprecated route)' do
|
2019-12-04 20:38:33 +05:30
|
|
|
delete api("/projects/#{project.id}/labels", user), params: spec_params
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:no_content)
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
it 'returns 204 for existing label (rest route)' do
|
|
|
|
label_id = spec_params[:name] || spec_params[:label_id]
|
2021-03-11 19:13:27 +05:30
|
|
|
delete api("/projects/#{project.id}/labels/#{ERB::Util.url_encode(label_id)}", user), params: spec_params.except(:name, :label_id)
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:no_content)
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
before do
|
2018-11-18 11:00:15 +05:30
|
|
|
project.add_maintainer(user)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET /projects/:id/labels' do
|
2021-01-29 00:20:46 +05:30
|
|
|
let_it_be(:group) { create(:group) }
|
2021-03-11 19:13:27 +05:30
|
|
|
let_it_be(:group_label) { create(:group_label, title: valid_group_label_title_1, group: group) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
before do
|
|
|
|
project.update!(group: group)
|
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
it 'returns all available labels to the project' do
|
2014-09-02 18:07:02 +05:30
|
|
|
get api("/projects/#{project.id}/labels", user)
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(response).to include_pagination_headers
|
2019-10-12 21:52:04 +05:30
|
|
|
expect(json_response).to all(match_schema('public_api/v4/labels/project_label'))
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(json_response.size).to eq(3)
|
|
|
|
expect(json_response.map { |l| l['name'] }).to match_array([group_label.name, priority_label.name, label1.name])
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
context 'when search param is provided' do
|
|
|
|
context 'and user is subscribed' do
|
|
|
|
before do
|
|
|
|
priority_label.subscribe(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns subscribed true' do
|
|
|
|
get api("/projects/#{project.id}/labels?search=#{priority_label.name}", user)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(json_response[0]['name']).to eq(priority_label.name)
|
|
|
|
expect(json_response[0]['subscribed']).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and user is not subscribed' do
|
|
|
|
before do
|
|
|
|
priority_label.unsubscribe(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns subscribed false' do
|
|
|
|
get api("/projects/#{project.id}/labels?search=#{priority_label.name}", user)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(json_response[0]['name']).to eq(priority_label.name)
|
|
|
|
expect(json_response[0]['subscribed']).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
context 'when the with_counts parameter is set' do
|
|
|
|
before do
|
|
|
|
create(:labeled_issue, project: project, labels: [group_label], author: user)
|
|
|
|
create(:labeled_issue, project: project, labels: [label1], author: user, state: :closed)
|
|
|
|
create(:labeled_merge_request, labels: [priority_label], author: user, source_project: project )
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes counts in the response' do
|
|
|
|
get api("/projects/#{project.id}/labels", user), params: { with_counts: true }
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-10-12 21:52:04 +05:30
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
expect(json_response).to all(match_schema('public_api/v4/labels/project_label_with_counts'))
|
|
|
|
expect(json_response.size).to eq(3)
|
|
|
|
expect(json_response.map { |l| l['name'] }).to match_array([group_label.name, priority_label.name, label1.name])
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
label1_response = json_response.find { |l| l['name'] == label1.title }
|
|
|
|
group_label_response = json_response.find { |l| l['name'] == group_label.title }
|
|
|
|
priority_label_response = json_response.find { |l| l['name'] == priority_label.title }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
expect(label1_response).to include('open_issues_count' => 0,
|
|
|
|
'closed_issues_count' => 1,
|
|
|
|
'open_merge_requests_count' => 0,
|
|
|
|
'name' => label1.name,
|
2021-03-11 19:13:27 +05:30
|
|
|
'description' => label1.description,
|
2019-10-12 21:52:04 +05:30
|
|
|
'color' => a_string_matching(/^#\h{6}$/),
|
|
|
|
'text_color' => a_string_matching(/^#\h{6}$/),
|
|
|
|
'priority' => nil,
|
|
|
|
'subscribed' => false,
|
|
|
|
'is_project_label' => true)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
expect(group_label_response).to include('open_issues_count' => 1,
|
|
|
|
'closed_issues_count' => 0,
|
|
|
|
'open_merge_requests_count' => 0,
|
|
|
|
'name' => group_label.name,
|
|
|
|
'description' => nil,
|
|
|
|
'color' => a_string_matching(/^#\h{6}$/),
|
|
|
|
'text_color' => a_string_matching(/^#\h{6}$/),
|
|
|
|
'priority' => nil,
|
|
|
|
'subscribed' => false,
|
|
|
|
'is_project_label' => false)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
expect(priority_label_response).to include('open_issues_count' => 0,
|
|
|
|
'closed_issues_count' => 0,
|
|
|
|
'open_merge_requests_count' => 1,
|
|
|
|
'name' => priority_label.name,
|
|
|
|
'description' => nil,
|
|
|
|
'color' => a_string_matching(/^#\h{6}$/),
|
|
|
|
'text_color' => a_string_matching(/^#\h{6}$/),
|
|
|
|
'priority' => 3,
|
|
|
|
'subscribed' => false,
|
|
|
|
'is_project_label' => true)
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
context 'with subgroups' do
|
|
|
|
let_it_be(:subgroup) { create(:group, parent: group) }
|
|
|
|
let_it_be(:subgroup_label) { create(:group_label, title: 'support label', group: subgroup) }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
subgroup.add_owner(user)
|
|
|
|
project.update!(group: subgroup)
|
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
context 'when the include_ancestor_groups parameter is not set' do
|
|
|
|
let(:request) { get api("/projects/#{project.id}/labels", user) }
|
|
|
|
let(:expected_labels) { [priority_label.name, group_label.name, subgroup_label.name, label1.name] }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it_behaves_like 'fetches labels'
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
context 'when search param is provided' do
|
|
|
|
let(:request) { get api("/projects/#{project.id}/labels?search=lab", user) }
|
|
|
|
let(:expected_labels) { [group_label.name, subgroup_label.name, label1.name] }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it_behaves_like 'fetches labels'
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
context 'when the include_ancestor_groups parameter is set to false' do
|
|
|
|
let(:request) { get api("/projects/#{project.id}/labels", user), params: { include_ancestor_groups: false } }
|
|
|
|
let(:expected_labels) { [subgroup_label.name, priority_label.name, label1.name] }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it_behaves_like 'fetches labels'
|
|
|
|
|
|
|
|
context 'when search param is provided' do
|
|
|
|
let(:request) { get api("/projects/#{project.id}/labels?search=lab", user), params: { include_ancestor_groups: false } }
|
|
|
|
let(:expected_labels) { [subgroup_label.name, label1.name] }
|
|
|
|
|
|
|
|
it_behaves_like 'fetches labels'
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST /projects/:id/labels' do
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'returns created label when all params' do
|
2016-06-02 11:05:42 +05:30
|
|
|
post api("/projects/#{project.id}/labels", user),
|
2019-02-15 15:39:39 +05:30
|
|
|
params: {
|
2021-03-11 19:13:27 +05:30
|
|
|
name: valid_label_title_2,
|
2019-02-15 15:39:39 +05:30
|
|
|
color: '#FFAABB',
|
|
|
|
description: 'test',
|
2021-09-04 01:27:46 +05:30
|
|
|
priority: 2
|
2019-02-15 15:39:39 +05:30
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:created)
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(json_response['name']).to eq(valid_label_title_2)
|
2016-06-02 11:05:42 +05:30
|
|
|
expect(json_response['color']).to eq('#FFAABB')
|
|
|
|
expect(json_response['description']).to eq('test')
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(json_response['priority']).to eq(2)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'returns created label when only required params' do
|
2014-09-02 18:07:02 +05:30
|
|
|
post api("/projects/#{project.id}/labels", user),
|
2019-02-15 15:39:39 +05:30
|
|
|
params: {
|
2021-03-11 19:13:27 +05:30
|
|
|
name: valid_label_title_2,
|
2019-02-15 15:39:39 +05:30
|
|
|
color: '#FFAABB'
|
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:created)
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(json_response['name']).to eq(valid_label_title_2)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(json_response['color']).to eq('#FFAABB')
|
|
|
|
expect(json_response['description']).to be_nil
|
|
|
|
expect(json_response['priority']).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a prioritized label' do
|
|
|
|
post api("/projects/#{project.id}/labels", user),
|
2019-02-15 15:39:39 +05:30
|
|
|
params: {
|
2021-03-11 19:13:27 +05:30
|
|
|
name: valid_label_title_2,
|
2019-02-15 15:39:39 +05:30
|
|
|
color: '#FFAABB',
|
|
|
|
priority: 3
|
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:created)
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(json_response['name']).to eq(valid_label_title_2)
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(json_response['color']).to eq('#FFAABB')
|
2016-06-02 11:05:42 +05:30
|
|
|
expect(json_response['description']).to be_nil
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(json_response['priority']).to eq(3)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'returns a 400 bad request if name not given' do
|
2019-02-15 15:39:39 +05:30
|
|
|
post api("/projects/#{project.id}/labels", user), params: { color: '#FFAABB' }
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'returns a 400 bad request if color not given' do
|
2019-02-15 15:39:39 +05:30
|
|
|
post api("/projects/#{project.id}/labels", user), params: { name: 'Foobar' }
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'returns 400 for invalid color' do
|
2014-09-02 18:07:02 +05:30
|
|
|
post api("/projects/#{project.id}/labels", user),
|
2019-02-15 15:39:39 +05:30
|
|
|
params: {
|
2021-03-11 19:13:27 +05:30
|
|
|
name: valid_label_title_2,
|
2019-02-15 15:39:39 +05:30
|
|
|
color: '#FFAA'
|
|
|
|
}
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2015-12-23 02:04:40 +05:30
|
|
|
expect(json_response['message']['color']).to eq(['must be a valid color code'])
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'returns 400 for too long color code' do
|
2014-09-02 18:07:02 +05:30
|
|
|
post api("/projects/#{project.id}/labels", user),
|
2019-02-15 15:39:39 +05:30
|
|
|
params: {
|
2021-03-11 19:13:27 +05:30
|
|
|
name: valid_label_title_2,
|
2019-02-15 15:39:39 +05:30
|
|
|
color: '#FFAAFFFF'
|
|
|
|
}
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2015-12-23 02:04:40 +05:30
|
|
|
expect(json_response['message']['color']).to eq(['must be a valid color code'])
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'returns 400 for invalid name' do
|
2014-09-02 18:07:02 +05:30
|
|
|
post api("/projects/#{project.id}/labels", user),
|
2019-02-15 15:39:39 +05:30
|
|
|
params: {
|
|
|
|
name: ',',
|
|
|
|
color: '#FFAABB'
|
|
|
|
}
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(json_response['message']['title']).to eq(['is invalid'])
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2016-11-24 13:41:30 +05:30
|
|
|
it 'returns 409 if label already exists in group' do
|
|
|
|
group = create(:group)
|
|
|
|
group_label = create(:group_label, group: group)
|
2021-04-29 21:17:54 +05:30
|
|
|
project.update!(group: group)
|
2016-11-24 13:41:30 +05:30
|
|
|
|
|
|
|
post api("/projects/#{project.id}/labels", user),
|
2019-02-15 15:39:39 +05:30
|
|
|
params: {
|
|
|
|
name: group_label.name,
|
|
|
|
color: '#FFAABB'
|
|
|
|
}
|
2016-11-24 13:41:30 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:conflict)
|
2016-11-24 13:41:30 +05:30
|
|
|
expect(json_response['message']).to eq('Label already exists')
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'returns 400 for invalid priority' do
|
|
|
|
post api("/projects/#{project.id}/labels", user),
|
2019-02-15 15:39:39 +05:30
|
|
|
params: {
|
2021-03-11 19:13:27 +05:30
|
|
|
name: valid_label_title_2,
|
2019-02-15 15:39:39 +05:30
|
|
|
color: '#FFAAFFFF',
|
|
|
|
priority: 'foo'
|
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2016-11-24 13:41:30 +05:30
|
|
|
it 'returns 409 if label already exists in project' do
|
2014-09-02 18:07:02 +05:30
|
|
|
post api("/projects/#{project.id}/labels", user),
|
2019-02-15 15:39:39 +05:30
|
|
|
params: {
|
2021-03-11 19:13:27 +05:30
|
|
|
name: valid_label_title_1,
|
2019-02-15 15:39:39 +05:30
|
|
|
color: '#FFAABB'
|
|
|
|
}
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:conflict)
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(json_response['message']).to eq('Label already exists')
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'DELETE /projects/:id/labels' do
|
2019-12-04 20:38:33 +05:30
|
|
|
it_behaves_like 'label delete API' do
|
2021-03-11 19:13:27 +05:30
|
|
|
let(:spec_params) { { name: valid_label_title_1 } }
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it_behaves_like 'label delete API' do
|
|
|
|
let(:spec_params) { { label_id: label1.id } }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'returns 404 for non existing label' do
|
2021-03-11 19:13:27 +05:30
|
|
|
delete api("/projects/#{project.id}/labels", user), params: { name: 'unknown' }
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(json_response['message']).to eq('404 Label Not Found')
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'returns 400 for wrong parameters' do
|
2014-09-02 18:07:02 +05:30
|
|
|
delete api("/projects/#{project.id}/labels", user)
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'fails if label_id and name are given in params' do
|
|
|
|
delete api("/projects/#{project.id}/labels", user),
|
|
|
|
params: {
|
|
|
|
label_id: label1.id,
|
|
|
|
name: priority_label.name
|
|
|
|
}
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like '412 response' do
|
|
|
|
let(:request) { api("/projects/#{project.id}/labels", user) }
|
2021-03-11 19:13:27 +05:30
|
|
|
let(:params) { { name: valid_label_title_1 } }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PUT /projects/:id/labels' do
|
2019-12-04 20:38:33 +05:30
|
|
|
context 'when using name' do
|
|
|
|
it_behaves_like 'label update API' do
|
2021-03-11 19:13:27 +05:30
|
|
|
let(:spec_params) { { name: valid_label_title_1 } }
|
2019-12-04 20:38:33 +05:30
|
|
|
let(:expected_response_label_id) { label1.id }
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
context 'when using label_id' do
|
|
|
|
it_behaves_like 'label update API' do
|
|
|
|
let(:spec_params) { { label_id: label1.id } }
|
|
|
|
let(:expected_response_label_id) { label1.id }
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it 'returns 404 if label does not exist' do
|
2014-09-02 18:07:02 +05:30
|
|
|
put api("/projects/#{project.id}/labels", user),
|
2019-02-15 15:39:39 +05:30
|
|
|
params: {
|
2021-03-11 19:13:27 +05:30
|
|
|
name: valid_label_title_2,
|
2019-12-04 20:38:33 +05:30
|
|
|
new_name: 'label3'
|
2019-02-15 15:39:39 +05:30
|
|
|
}
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it 'returns 404 if label by id does not exist' do
|
2016-06-02 11:05:42 +05:30
|
|
|
put api("/projects/#{project.id}/labels", user),
|
2019-02-15 15:39:39 +05:30
|
|
|
params: {
|
2019-12-04 20:38:33 +05:30
|
|
|
label_id: 0,
|
|
|
|
new_name: 'label3'
|
2019-02-15 15:39:39 +05:30
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it 'returns 400 if no label name and id is given' do
|
|
|
|
put api("/projects/#{project.id}/labels", user), params: { new_name: 'label2' }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(json_response['error']).to eq('label_id, name are missing, exactly one parameter must be provided')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it 'fails if label_id and name are given in params' do
|
2017-08-17 22:00:37 +05:30
|
|
|
put api("/projects/#{project.id}/labels", user),
|
2019-02-15 15:39:39 +05:30
|
|
|
params: {
|
2019-12-04 20:38:33 +05:30
|
|
|
label_id: label1.id,
|
2019-02-15 15:39:39 +05:30
|
|
|
name: priority_label.name,
|
2019-12-04 20:38:33 +05:30
|
|
|
new_name: 'New Label'
|
2019-02-15 15:39:39 +05:30
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
describe 'PUT /projects/:id/labels/promote' do
|
2021-01-29 00:20:46 +05:30
|
|
|
let_it_be(:group) { create(:group) }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
before do
|
|
|
|
group.add_owner(user)
|
|
|
|
project.update!(group: group)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it 'returns 200 if label is promoted' do
|
|
|
|
put api("/projects/#{project.id}/labels/promote", user), params: { name: label1.name }
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(json_response['name']).to eq(label1.name)
|
|
|
|
expect(json_response['color']).to eq(label1.color)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
context 'if group label already exists' do
|
|
|
|
let!(:group_label) { create(:group_label, title: label1.name, group: group) }
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it 'returns a status of 200' do
|
|
|
|
put api("/projects/#{project.id}/labels/promote", user), params: { name: label1.name }
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not change the group label count' do
|
|
|
|
expect { put api("/projects/#{project.id}/labels/promote", user), params: { name: label1.name } }
|
|
|
|
.not_to change(group.labels, :count)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not change the group label max (reuses the same ID)' do
|
|
|
|
expect { put api("/projects/#{project.id}/labels/promote", user), params: { name: label1.name } }
|
|
|
|
.not_to change(group.labels, :max)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'changes the project label count' do
|
|
|
|
expect { put api("/projects/#{project.id}/labels/promote", user), params: { name: label1.name } }
|
|
|
|
.to change(project.labels, :count).by(-1)
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it 'returns 403 if guest promotes label' do
|
|
|
|
guest = create(:user)
|
|
|
|
project.add_guest(guest)
|
|
|
|
|
|
|
|
put api("/projects/#{project.id}/labels/promote", guest), params: { name: label1.name }
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
it 'returns 403 if reporter promotes label' do
|
|
|
|
reporter = create(:user)
|
|
|
|
project.add_reporter(reporter)
|
|
|
|
|
|
|
|
put api("/projects/#{project.id}/labels/promote", reporter), params: { name: label1.name }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it 'returns 404 if label does not exist' do
|
|
|
|
put api("/projects/#{project.id}/labels/promote", user), params: { name: 'unknown' }
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it 'returns 400 if no label name given' do
|
|
|
|
put api("/projects/#{project.id}/labels/promote", user)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(json_response['error']).to eq('name is missing')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2022-01-26 12:08:38 +05:30
|
|
|
|
|
|
|
it 'returns 400 if project does not have a group' do
|
|
|
|
project = create(:project, creator_id: user.id, namespace: user.namespace)
|
|
|
|
put api("/projects/#{project.id}/labels/promote", user), params: { name: label1.name }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe "POST /projects/:id/labels/:label_id/subscribe" do
|
2016-06-02 11:05:42 +05:30
|
|
|
context "when label_id is a label title" do
|
2016-09-13 17:45:13 +05:30
|
|
|
it "subscribes to the label" do
|
2021-03-11 19:13:27 +05:30
|
|
|
post api("/projects/#{project.id}/labels/#{valid_label_title_1_esc}/subscribe", user)
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:created)
|
2016-06-02 11:05:42 +05:30
|
|
|
expect(json_response["name"]).to eq(label1.title)
|
|
|
|
expect(json_response["subscribed"]).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when label_id is a label ID" do
|
2016-09-13 17:45:13 +05:30
|
|
|
it "subscribes to the label" do
|
2017-08-17 22:00:37 +05:30
|
|
|
post api("/projects/#{project.id}/labels/#{label1.id}/subscribe", user)
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:created)
|
2016-06-02 11:05:42 +05:30
|
|
|
expect(json_response["name"]).to eq(label1.title)
|
|
|
|
expect(json_response["subscribed"]).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when user is already subscribed to label" do
|
2017-09-10 17:25:29 +05:30
|
|
|
before do
|
|
|
|
label1.subscribe(user, project)
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "returns 304" do
|
2017-08-17 22:00:37 +05:30
|
|
|
post api("/projects/#{project.id}/labels/#{label1.id}/subscribe", user)
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_modified)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when label ID is not found" do
|
2016-09-13 17:45:13 +05:30
|
|
|
it "returns 404 error" do
|
2020-04-22 19:07:51 +05:30
|
|
|
post api("/projects/#{project.id}/labels/#{non_existing_record_id}/subscribe", user)
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe "POST /projects/:id/labels/:label_id/unsubscribe" do
|
2017-09-10 17:25:29 +05:30
|
|
|
before do
|
|
|
|
label1.subscribe(user, project)
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
context "when label_id is a label title" do
|
2016-09-13 17:45:13 +05:30
|
|
|
it "unsubscribes from the label" do
|
2021-03-11 19:13:27 +05:30
|
|
|
post api("/projects/#{project.id}/labels/#{valid_label_title_1_esc}/unsubscribe", user)
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:created)
|
2016-06-02 11:05:42 +05:30
|
|
|
expect(json_response["name"]).to eq(label1.title)
|
|
|
|
expect(json_response["subscribed"]).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when label_id is a label ID" do
|
2016-09-13 17:45:13 +05:30
|
|
|
it "unsubscribes from the label" do
|
2017-08-17 22:00:37 +05:30
|
|
|
post api("/projects/#{project.id}/labels/#{label1.id}/unsubscribe", user)
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:created)
|
2016-06-02 11:05:42 +05:30
|
|
|
expect(json_response["name"]).to eq(label1.title)
|
|
|
|
expect(json_response["subscribed"]).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when user is already unsubscribed from label" do
|
2017-09-10 17:25:29 +05:30
|
|
|
before do
|
|
|
|
label1.unsubscribe(user, project)
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "returns 304" do
|
2017-08-17 22:00:37 +05:30
|
|
|
post api("/projects/#{project.id}/labels/#{label1.id}/unsubscribe", user)
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_modified)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when label ID is not found" do
|
2016-09-13 17:45:13 +05:30
|
|
|
it "returns 404 error" do
|
2020-04-22 19:07:51 +05:30
|
|
|
post api("/projects/#{project.id}/labels/#{non_existing_record_id}/unsubscribe", user)
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|