Commit bb6549c5 authored by Lucas Zampieri's avatar Lucas Zampieri

Added spec tests to labels API /search reponse

Added tests on group and project labels API to test subscription response.
Changelog: fixed
Signed-off-by: default avatarLucas Zampieri <lzampier@redhat.com>
parent 28e95f25
......@@ -18,8 +18,7 @@ module API
end
expose :subscribed do |label, options|
if label.subscribed?(options[:current_user]) ||
label.subscribed?(options[:current_user], options[:parent])
if label.subscribed?(options[:current_user]) || label.subscribed?(options[:current_user], options[:parent])
true
else
false
......
......@@ -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 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 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 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 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