Commit 6f70084c authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'group_label_api_fix' into 'master'

Fixed label groups subscription API to be consistent with the WebUI

See merge request gitlab-org/gitlab!64360
parents 8fd46077 07d9f424
......@@ -18,7 +18,9 @@ module API
end
expose :subscribed do |label, options|
label.subscribed?(options[:current_user], options[:parent])
label.subscribed?(options[:current_user]) || (
options[:parent].is_a?(::Project) && label.subscribed?(options[:current_user], options[:parent])
)
end
end
end
......
......@@ -29,6 +29,32 @@ RSpec.describe API::GroupLabels do
let(:expected_labels) { [group_label1.name] }
it_behaves_like 'fetches labels'
context 'and is subscribed' do
before do
group_label1.subscribe(user)
end
it 'returns true' do
get api("/groups/#{group.id}/labels?search=#{group_label1.name}", user)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response[0]['subscribed']).to be true
end
end
context 'and is unsubscribed' do
before do
group_label1.unsubscribe(user)
end
it 'returns false' do
get api("/groups/#{group.id}/labels?search=#{group_label1.name}", user)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response[0]['subscribed']).to be false
end
end
end
context 'when the with_counts parameter is set' do
......
......@@ -200,6 +200,36 @@ RSpec.describe API::Labels do
expect(json_response.map { |l| l['name'] }).to match_array([group_label.name, priority_label.name, label1.name])
end
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
context 'when the with_counts parameter is set' do
before do
create(:labeled_issue, project: project, labels: [group_label], author: user)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment