2014-07-30 09:05:43 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-04-21 16:32:02 -04:00
|
|
|
describe API::Labels do
|
2014-07-30 09:05:43 -04:00
|
|
|
let(:user) { create(:user) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project, creator_id: user.id, namespace: user.namespace) }
|
2014-07-30 09:05:43 -04:00
|
|
|
let!(:label1) { create(:label, title: 'label1', project: project) }
|
2016-09-29 10:33:38 -04:00
|
|
|
let!(:priority_label) { create(:label, title: 'bug', project: project, priority: 3) }
|
2014-07-30 09:05:43 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
project.team << [user, :master]
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET /projects/:id/labels' do
|
2016-10-13 17:53:06 -04:00
|
|
|
it 'returns all available labels to the project' do
|
|
|
|
group = create(:group)
|
2016-11-09 13:21:52 -05:00
|
|
|
group_label = create(:group_label, title: 'feature', group: group)
|
2016-10-13 17:53:06 -04:00
|
|
|
project.update(group: group)
|
2016-11-14 09:52:43 -05:00
|
|
|
create(:labeled_issue, project: project, labels: [group_label], author: user)
|
|
|
|
create(:labeled_issue, project: project, labels: [label1], author: user, state: :closed)
|
2016-11-15 05:45:57 -05:00
|
|
|
create(:labeled_merge_request, labels: [priority_label], author: user, source_project: project )
|
|
|
|
|
2017-02-22 12:46:57 -05:00
|
|
|
expected_keys = %w(
|
2017-02-22 13:03:32 -05:00
|
|
|
id name color description
|
|
|
|
open_issues_count closed_issues_count open_merge_requests_count
|
|
|
|
subscribed priority
|
|
|
|
)
|
2016-10-13 17:53:06 -04:00
|
|
|
|
2014-07-30 09:05:43 -04:00
|
|
|
get api("/projects/#{project.id}/labels", user)
|
2016-10-13 17:53:06 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2017-01-24 15:49:10 -05:00
|
|
|
expect(response).to include_pagination_headers
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response).to be_an Array
|
2016-09-29 10:33:38 -04:00
|
|
|
expect(json_response.size).to eq(3)
|
2016-11-04 07:52:38 -04:00
|
|
|
expect(json_response.first.keys).to match_array expected_keys
|
2016-09-29 10:33:38 -04:00
|
|
|
expect(json_response.map { |l| l['name'] }).to match_array([group_label.name, priority_label.name, label1.name])
|
2016-11-14 09:52:43 -05:00
|
|
|
|
2016-11-15 03:50:39 -05:00
|
|
|
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 }
|
2016-11-14 09:52:43 -05:00
|
|
|
|
|
|
|
expect(label1_response['open_issues_count']).to eq(0)
|
|
|
|
expect(label1_response['closed_issues_count']).to eq(1)
|
2016-11-15 05:45:57 -05:00
|
|
|
expect(label1_response['open_merge_requests_count']).to eq(0)
|
2016-11-14 09:52:43 -05:00
|
|
|
expect(label1_response['name']).to eq(label1.name)
|
|
|
|
expect(label1_response['color']).to be_present
|
|
|
|
expect(label1_response['description']).to be_nil
|
|
|
|
expect(label1_response['priority']).to be_nil
|
|
|
|
expect(label1_response['subscribed']).to be_falsey
|
2016-11-15 05:45:57 -05:00
|
|
|
|
|
|
|
expect(group_label_response['open_issues_count']).to eq(1)
|
|
|
|
expect(group_label_response['closed_issues_count']).to eq(0)
|
|
|
|
expect(group_label_response['open_merge_requests_count']).to eq(0)
|
|
|
|
expect(group_label_response['name']).to eq(group_label.name)
|
|
|
|
expect(group_label_response['color']).to be_present
|
|
|
|
expect(group_label_response['description']).to be_nil
|
|
|
|
expect(group_label_response['priority']).to be_nil
|
|
|
|
expect(group_label_response['subscribed']).to be_falsey
|
|
|
|
|
|
|
|
expect(priority_label_response['open_issues_count']).to eq(0)
|
|
|
|
expect(priority_label_response['closed_issues_count']).to eq(0)
|
|
|
|
expect(priority_label_response['open_merge_requests_count']).to eq(1)
|
|
|
|
expect(priority_label_response['name']).to eq(priority_label.name)
|
|
|
|
expect(priority_label_response['color']).to be_present
|
|
|
|
expect(priority_label_response['description']).to be_nil
|
|
|
|
expect(priority_label_response['priority']).to eq(3)
|
|
|
|
expect(priority_label_response['subscribed']).to be_falsey
|
2014-07-30 09:05:43 -04:00
|
|
|
end
|
|
|
|
end
|
2014-08-12 08:16:25 -04:00
|
|
|
|
|
|
|
describe 'POST /projects/:id/labels' do
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns created label when all params' do
|
2016-03-24 14:38:37 -04:00
|
|
|
post api("/projects/#{project.id}/labels", user),
|
|
|
|
name: 'Foo',
|
|
|
|
color: '#FFAABB',
|
2016-09-29 10:33:38 -04:00
|
|
|
description: 'test',
|
|
|
|
priority: 2
|
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(201)
|
2016-03-24 14:38:37 -04:00
|
|
|
expect(json_response['name']).to eq('Foo')
|
|
|
|
expect(json_response['color']).to eq('#FFAABB')
|
|
|
|
expect(json_response['description']).to eq('test')
|
2016-09-29 10:33:38 -04:00
|
|
|
expect(json_response['priority']).to eq(2)
|
2016-03-24 14:38:37 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns created label when only required params' do
|
2014-08-12 08:16:25 -04:00
|
|
|
post api("/projects/#{project.id}/labels", user),
|
2016-06-16 19:09:13 -04:00
|
|
|
name: 'Foo & Bar',
|
2014-08-12 08:16:25 -04:00
|
|
|
color: '#FFAABB'
|
2016-09-29 10:33:38 -04:00
|
|
|
|
2016-06-16 19:09:13 -04:00
|
|
|
expect(response.status).to eq(201)
|
|
|
|
expect(json_response['name']).to eq('Foo & Bar')
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response['color']).to eq('#FFAABB')
|
2016-03-24 14:38:37 -04:00
|
|
|
expect(json_response['description']).to be_nil
|
2016-09-29 10:33:38 -04:00
|
|
|
expect(json_response['priority']).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a prioritized label' do
|
|
|
|
post api("/projects/#{project.id}/labels", user),
|
|
|
|
name: 'Foo & Bar',
|
|
|
|
color: '#FFAABB',
|
|
|
|
priority: 3
|
|
|
|
|
|
|
|
expect(response.status).to eq(201)
|
|
|
|
expect(json_response['name']).to eq('Foo & Bar')
|
|
|
|
expect(json_response['color']).to eq('#FFAABB')
|
|
|
|
expect(json_response['description']).to be_nil
|
|
|
|
expect(json_response['priority']).to eq(3)
|
2014-08-12 08:16:25 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns a 400 bad request if name not given' do
|
2014-08-12 08:16:25 -04:00
|
|
|
post api("/projects/#{project.id}/labels", user), color: '#FFAABB'
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(400)
|
2014-08-12 08:16:25 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns a 400 bad request if color not given' do
|
2014-08-12 08:16:25 -04:00
|
|
|
post api("/projects/#{project.id}/labels", user), name: 'Foobar'
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(400)
|
2014-08-12 08:16:25 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns 400 for invalid color' do
|
2014-08-12 08:16:25 -04:00
|
|
|
post api("/projects/#{project.id}/labels", user),
|
|
|
|
name: 'Foo',
|
|
|
|
color: '#FFAA'
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(400)
|
2015-12-01 18:53:44 -05:00
|
|
|
expect(json_response['message']['color']).to eq(['must be a valid color code'])
|
2014-08-12 08:16:25 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns 400 for too long color code' do
|
2014-08-17 16:22:01 -04:00
|
|
|
post api("/projects/#{project.id}/labels", user),
|
|
|
|
name: 'Foo',
|
|
|
|
color: '#FFAAFFFF'
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(400)
|
2015-12-01 18:53:44 -05:00
|
|
|
expect(json_response['message']['color']).to eq(['must be a valid color code'])
|
2014-08-17 16:22:01 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns 400 for invalid name' do
|
2014-08-12 08:16:25 -04:00
|
|
|
post api("/projects/#{project.id}/labels", user),
|
2016-06-16 19:09:13 -04:00
|
|
|
name: ',',
|
2014-08-12 08:16:25 -04:00
|
|
|
color: '#FFAABB'
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(400)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response['message']['title']).to eq(['is invalid'])
|
2014-08-12 08:16:25 -04:00
|
|
|
end
|
|
|
|
|
2016-10-20 06:15:29 -04:00
|
|
|
it 'returns 409 if label already exists in group' do
|
|
|
|
group = create(:group)
|
|
|
|
group_label = create(:group_label, group: group)
|
|
|
|
project.update(group: group)
|
|
|
|
|
|
|
|
post api("/projects/#{project.id}/labels", user),
|
|
|
|
name: group_label.name,
|
|
|
|
color: '#FFAABB'
|
|
|
|
|
|
|
|
expect(response).to have_http_status(409)
|
|
|
|
expect(json_response['message']).to eq('Label already exists')
|
|
|
|
end
|
|
|
|
|
2016-09-29 10:33:38 -04:00
|
|
|
it 'returns 400 for invalid priority' do
|
|
|
|
post api("/projects/#{project.id}/labels", user),
|
|
|
|
name: 'Foo',
|
|
|
|
color: '#FFAAFFFF',
|
|
|
|
priority: 'foo'
|
|
|
|
|
|
|
|
expect(response).to have_http_status(400)
|
|
|
|
end
|
|
|
|
|
2016-10-20 06:15:29 -04:00
|
|
|
it 'returns 409 if label already exists in project' do
|
2014-08-12 08:16:25 -04:00
|
|
|
post api("/projects/#{project.id}/labels", user),
|
|
|
|
name: 'label1',
|
|
|
|
color: '#FFAABB'
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(409)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response['message']).to eq('Label already exists')
|
2014-08-12 08:16:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'DELETE /projects/:id/labels' do
|
2017-02-20 13:18:12 -05:00
|
|
|
it 'returns 204 for existing label' do
|
2014-08-13 06:23:51 -04:00
|
|
|
delete api("/projects/#{project.id}/labels", user), name: 'label1'
|
2017-02-20 13:18:12 -05:00
|
|
|
|
|
|
|
expect(response).to have_http_status(204)
|
2014-08-12 08:16:25 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns 404 for non existing label' do
|
2014-08-13 06:23:51 -04:00
|
|
|
delete api("/projects/#{project.id}/labels", user), name: 'label2'
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response['message']).to eq('404 Label Not Found')
|
2014-08-12 08:16:25 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns 400 for wrong parameters' do
|
2014-08-12 08:16:25 -04:00
|
|
|
delete api("/projects/#{project.id}/labels", user)
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(400)
|
2014-08-12 08:16:25 -04:00
|
|
|
end
|
|
|
|
end
|
2014-08-13 06:23:51 -04:00
|
|
|
|
|
|
|
describe 'PUT /projects/:id/labels' do
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns 200 if name and colors and description are changed' do
|
2014-08-13 06:23:51 -04:00
|
|
|
put api("/projects/#{project.id}/labels", user),
|
|
|
|
name: 'label1',
|
|
|
|
new_name: 'New Label',
|
2016-03-24 14:38:37 -04:00
|
|
|
color: '#FFFFFF',
|
|
|
|
description: 'test'
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response['name']).to eq('New Label')
|
|
|
|
expect(json_response['color']).to eq('#FFFFFF')
|
2016-03-24 14:38:37 -04:00
|
|
|
expect(json_response['description']).to eq('test')
|
2014-08-13 06:23:51 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns 200 if name is changed' do
|
2014-08-13 06:23:51 -04:00
|
|
|
put api("/projects/#{project.id}/labels", user),
|
|
|
|
name: 'label1',
|
|
|
|
new_name: 'New Label'
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response['name']).to eq('New Label')
|
|
|
|
expect(json_response['color']).to eq(label1.color)
|
2014-08-13 06:23:51 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns 200 if colors is changed' do
|
2014-08-13 06:23:51 -04:00
|
|
|
put api("/projects/#{project.id}/labels", user),
|
|
|
|
name: 'label1',
|
|
|
|
color: '#FFFFFF'
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response['name']).to eq(label1.name)
|
|
|
|
expect(json_response['color']).to eq('#FFFFFF')
|
2014-08-13 06:23:51 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns 200 if description is changed' do
|
2016-03-24 14:38:37 -04:00
|
|
|
put api("/projects/#{project.id}/labels", user),
|
2016-09-29 10:33:38 -04:00
|
|
|
name: 'bug',
|
2016-03-24 14:38:37 -04:00
|
|
|
description: 'test'
|
2016-09-29 10:33:38 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2016-09-29 10:33:38 -04:00
|
|
|
expect(json_response['name']).to eq(priority_label.name)
|
2016-03-24 14:38:37 -04:00
|
|
|
expect(json_response['description']).to eq('test')
|
2016-09-29 10:33:38 -04:00
|
|
|
expect(json_response['priority']).to eq(3)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 200 if priority is changed' do
|
|
|
|
put api("/projects/#{project.id}/labels", user),
|
|
|
|
name: 'bug',
|
|
|
|
priority: 10
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response['name']).to eq(priority_label.name)
|
|
|
|
expect(json_response['priority']).to eq(10)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 200 if a priority is added' do
|
|
|
|
put api("/projects/#{project.id}/labels", user),
|
|
|
|
name: 'label1',
|
|
|
|
priority: 3
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response['name']).to eq(label1.name)
|
|
|
|
expect(json_response['priority']).to eq(3)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 200 if the priority is removed' do
|
|
|
|
put api("/projects/#{project.id}/labels", user),
|
|
|
|
name: priority_label.name,
|
|
|
|
priority: nil
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response['name']).to eq(priority_label.name)
|
|
|
|
expect(json_response['priority']).to be_nil
|
2016-03-24 14:38:37 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns 404 if label does not exist' do
|
2014-08-13 06:23:51 -04:00
|
|
|
put api("/projects/#{project.id}/labels", user),
|
|
|
|
name: 'label2',
|
|
|
|
new_name: 'label3'
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2014-08-13 06:23:51 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns 400 if no label name given' do
|
2014-08-13 06:23:51 -04:00
|
|
|
put api("/projects/#{project.id}/labels", user), new_name: 'label2'
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(400)
|
2016-10-24 08:05:33 -04:00
|
|
|
expect(json_response['error']).to eq('name is missing')
|
2014-08-13 06:23:51 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns 400 if no new parameters given' do
|
2014-08-13 06:23:51 -04:00
|
|
|
put api("/projects/#{project.id}/labels", user), name: 'label1'
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(400)
|
2016-09-29 10:33:38 -04:00
|
|
|
expect(json_response['error']).to eq('new_name, color, description, priority are missing, '\
|
2016-10-24 08:05:33 -04:00
|
|
|
'at least one parameter must be provided')
|
2014-08-13 06:23:51 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns 400 for invalid name' do
|
2014-08-13 06:23:51 -04:00
|
|
|
put api("/projects/#{project.id}/labels", user),
|
|
|
|
name: 'label1',
|
2016-06-16 19:09:13 -04:00
|
|
|
new_name: ',',
|
2014-08-13 06:23:51 -04:00
|
|
|
color: '#FFFFFF'
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(400)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response['message']['title']).to eq(['is invalid'])
|
2014-08-13 06:23:51 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns 400 when color code is too short' do
|
2014-08-13 06:23:51 -04:00
|
|
|
put api("/projects/#{project.id}/labels", user),
|
|
|
|
name: 'label1',
|
|
|
|
color: '#FF'
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(400)
|
2015-12-01 18:53:44 -05:00
|
|
|
expect(json_response['message']['color']).to eq(['must be a valid color code'])
|
2014-08-13 06:23:51 -04:00
|
|
|
end
|
2014-08-17 16:22:01 -04:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns 400 for too long color code' do
|
2014-08-17 16:22:01 -04:00
|
|
|
post api("/projects/#{project.id}/labels", user),
|
|
|
|
name: 'Foo',
|
|
|
|
color: '#FFAAFFFF'
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(400)
|
2015-12-01 18:53:44 -05:00
|
|
|
expect(json_response['message']['color']).to eq(['must be a valid color code'])
|
2014-08-17 16:22:01 -04:00
|
|
|
end
|
2016-09-29 10:33:38 -04:00
|
|
|
|
|
|
|
it 'returns 400 for invalid priority' do
|
|
|
|
post api("/projects/#{project.id}/labels", user),
|
|
|
|
name: 'Foo',
|
|
|
|
priority: 'foo'
|
|
|
|
|
|
|
|
expect(response).to have_http_status(400)
|
|
|
|
end
|
2014-08-13 06:23:51 -04:00
|
|
|
end
|
2016-05-12 16:48:09 -04:00
|
|
|
|
2017-02-17 04:45:05 -05:00
|
|
|
describe "POST /projects/:id/labels/:label_id/subscribe" do
|
2016-05-12 16:48:09 -04:00
|
|
|
context "when label_id is a label title" do
|
2016-08-01 11:00:44 -04:00
|
|
|
it "subscribes to the label" do
|
2017-02-17 04:45:05 -05:00
|
|
|
post api("/projects/#{project.id}/labels/#{label1.title}/subscribe", user)
|
2016-05-12 16:48:09 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(201)
|
2016-05-12 16:48:09 -04:00
|
|
|
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-08-01 11:00:44 -04:00
|
|
|
it "subscribes to the label" do
|
2017-02-17 04:45:05 -05:00
|
|
|
post api("/projects/#{project.id}/labels/#{label1.id}/subscribe", user)
|
2016-05-12 16:48:09 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(201)
|
2016-05-12 16:48:09 -04:00
|
|
|
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-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
label1.subscribe(user, project)
|
|
|
|
end
|
2016-05-12 16:48:09 -04:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "returns 304" do
|
2017-02-17 04:45:05 -05:00
|
|
|
post api("/projects/#{project.id}/labels/#{label1.id}/subscribe", user)
|
2016-05-12 16:48:09 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(304)
|
2016-05-12 16:48:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when label ID is not found" do
|
2016-08-01 11:00:44 -04:00
|
|
|
it "returns 404 error" do
|
2017-02-17 04:45:05 -05:00
|
|
|
post api("/projects/#{project.id}/labels/1234/subscribe", user)
|
2016-05-12 16:48:09 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2016-05-12 16:48:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-17 04:45:05 -05:00
|
|
|
describe "POST /projects/:id/labels/:label_id/unsubscribe" do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
label1.subscribe(user, project)
|
|
|
|
end
|
2016-05-12 16:48:09 -04:00
|
|
|
|
|
|
|
context "when label_id is a label title" do
|
2016-08-01 11:00:44 -04:00
|
|
|
it "unsubscribes from the label" do
|
2017-02-17 04:45:05 -05:00
|
|
|
post api("/projects/#{project.id}/labels/#{label1.title}/unsubscribe", user)
|
2016-05-12 16:48:09 -04:00
|
|
|
|
2017-02-17 04:45:05 -05:00
|
|
|
expect(response).to have_http_status(201)
|
2016-05-12 16:48:09 -04:00
|
|
|
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-08-01 11:00:44 -04:00
|
|
|
it "unsubscribes from the label" do
|
2017-02-17 04:45:05 -05:00
|
|
|
post api("/projects/#{project.id}/labels/#{label1.id}/unsubscribe", user)
|
2016-05-12 16:48:09 -04:00
|
|
|
|
2017-02-17 04:45:05 -05:00
|
|
|
expect(response).to have_http_status(201)
|
2016-05-12 16:48:09 -04:00
|
|
|
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-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
label1.unsubscribe(user, project)
|
|
|
|
end
|
2016-05-12 16:48:09 -04:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "returns 304" do
|
2017-02-17 04:45:05 -05:00
|
|
|
post api("/projects/#{project.id}/labels/#{label1.id}/unsubscribe", user)
|
2016-05-12 16:48:09 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(304)
|
2016-05-12 16:48:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when label ID is not found" do
|
2016-08-01 11:00:44 -04:00
|
|
|
it "returns 404 error" do
|
2017-02-17 04:45:05 -05:00
|
|
|
post api("/projects/#{project.id}/labels/1234/unsubscribe", user)
|
2016-05-12 16:48:09 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2016-05-12 16:48:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-07-30 09:05:43 -04:00
|
|
|
end
|