2012-11-27 14:43:39 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2014-04-11 15:45:56 -04:00
|
|
|
describe API::API, api: true do
|
2012-11-27 14:43:39 -05:00
|
|
|
include ApiHelpers
|
|
|
|
let(:user) { create(:user) }
|
2016-05-16 15:43:19 -04:00
|
|
|
let!(:project) { create(:project, :public, namespace: user.namespace) }
|
2012-11-27 14:43:39 -05:00
|
|
|
let!(:issue) { create(:issue, project: project, author: user) }
|
2013-04-25 10:15:33 -04:00
|
|
|
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project, author: user) }
|
2013-03-25 03:20:14 -04:00
|
|
|
let!(:snippet) { create(:project_snippet, project: project, author: user) }
|
2012-11-27 14:43:39 -05:00
|
|
|
let!(:issue_note) { create(:note, noteable: issue, project: project, author: user) }
|
2013-01-31 01:42:11 -05:00
|
|
|
let!(:merge_request_note) { create(:note, noteable: merge_request, project: project, author: user) }
|
2012-11-27 14:43:39 -05:00
|
|
|
let!(:snippet_note) { create(:note, noteable: snippet, project: project, author: user) }
|
2016-01-13 13:42:36 -05:00
|
|
|
|
|
|
|
# For testing the cross-reference of a private issue in a public issue
|
|
|
|
let(:private_user) { create(:user) }
|
2016-01-14 04:04:48 -05:00
|
|
|
let(:private_project) do
|
2016-01-13 13:42:36 -05:00
|
|
|
create(:project, namespace: private_user.namespace).
|
|
|
|
tap { |p| p.team << [private_user, :master] }
|
2016-01-14 04:04:48 -05:00
|
|
|
end
|
|
|
|
let(:private_issue) { create(:issue, project: private_project) }
|
|
|
|
|
2016-01-13 13:42:36 -05:00
|
|
|
let(:ext_proj) { create(:project, :public) }
|
|
|
|
let(:ext_issue) { create(:issue, project: ext_proj) }
|
|
|
|
|
2016-01-14 04:04:48 -05:00
|
|
|
let!(:cross_reference_note) do
|
2016-01-13 13:42:36 -05:00
|
|
|
create :note,
|
|
|
|
noteable: ext_issue, project: ext_proj,
|
|
|
|
note: "mentioned in issue #{private_issue.to_reference(ext_proj)}",
|
|
|
|
system: true
|
2016-01-14 04:04:48 -05:00
|
|
|
end
|
2016-01-13 13:42:36 -05:00
|
|
|
|
2013-01-04 11:50:31 -05:00
|
|
|
before { project.team << [user, :reporter] }
|
2012-11-27 14:43:39 -05:00
|
|
|
|
|
|
|
describe "GET /projects/:id/noteable/:noteable_id/notes" do
|
2016-01-14 06:08:44 -05:00
|
|
|
it_behaves_like 'a paginated resources' do
|
|
|
|
let(:request) { get api("/projects/#{project.id}/issues/#{issue.id}/notes", user) }
|
|
|
|
end
|
|
|
|
|
2012-11-27 14:43:39 -05:00
|
|
|
context "when noteable is an Issue" do
|
2012-11-29 14:33:41 -05:00
|
|
|
it "should return an array of issue notes" do
|
2012-11-27 14:43:39 -05:00
|
|
|
get api("/projects/#{project.id}/issues/#{issue.id}/notes", user)
|
2016-05-10 15:06:02 -04:00
|
|
|
|
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).to be_an Array
|
|
|
|
expect(json_response.first['body']).to eq(issue_note.note)
|
2012-11-27 14:43:39 -05:00
|
|
|
end
|
2013-02-06 10:34:06 -05:00
|
|
|
|
|
|
|
it "should return a 404 error when issue id not found" do
|
2016-04-26 12:55:38 -04:00
|
|
|
get api("/projects/#{project.id}/issues/12345/notes", user)
|
2016-05-10 15:06:02 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2013-02-06 10:34:06 -05:00
|
|
|
end
|
2016-01-13 13:42:36 -05:00
|
|
|
|
2016-05-16 15:43:19 -04:00
|
|
|
context "and current user cannot view the notes" do
|
2016-01-13 13:42:36 -05:00
|
|
|
it "should return an empty array" do
|
|
|
|
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes", user)
|
2016-05-10 15:06:02 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2016-01-13 13:42:36 -05:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response).to be_empty
|
|
|
|
end
|
|
|
|
|
2016-05-09 18:35:37 -04:00
|
|
|
context "and issue is confidential" do
|
|
|
|
before { ext_issue.update_attributes(confidential: true) }
|
|
|
|
|
|
|
|
it "returns 404" do
|
|
|
|
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes", user)
|
2016-05-10 15:06:02 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2016-05-09 18:35:37 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-13 13:42:36 -05:00
|
|
|
context "and current user can view the note" do
|
|
|
|
it "should return an empty array" do
|
|
|
|
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes", private_user)
|
2016-05-10 15:06:02 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2016-01-13 13:42:36 -05:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.first['body']).to eq(cross_reference_note.note)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-11-27 14:43:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when noteable is a Snippet" do
|
2012-11-29 14:33:41 -05:00
|
|
|
it "should return an array of snippet notes" do
|
2012-11-27 14:43:39 -05:00
|
|
|
get api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user)
|
2016-05-10 15:06:02 -04:00
|
|
|
|
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).to be_an Array
|
|
|
|
expect(json_response.first['body']).to eq(snippet_note.note)
|
2012-11-27 14:43:39 -05:00
|
|
|
end
|
2013-02-06 10:34:06 -05:00
|
|
|
|
|
|
|
it "should return a 404 error when snippet id not found" do
|
|
|
|
get api("/projects/#{project.id}/snippets/42/notes", user)
|
2016-05-10 15:06:02 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2013-02-06 10:34:06 -05:00
|
|
|
end
|
2016-05-09 18:35:37 -04:00
|
|
|
|
|
|
|
it "returns 404 when not authorized" do
|
|
|
|
get api("/projects/#{project.id}/snippets/#{snippet.id}/notes", private_user)
|
2016-05-10 15:06:02 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2016-05-09 18:35:37 -04:00
|
|
|
end
|
2012-11-27 14:43:39 -05:00
|
|
|
end
|
2013-01-31 01:42:11 -05:00
|
|
|
|
|
|
|
context "when noteable is a Merge Request" do
|
|
|
|
it "should return an array of merge_requests notes" do
|
|
|
|
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/notes", user)
|
2016-05-10 15:06:02 -04:00
|
|
|
|
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).to be_an Array
|
|
|
|
expect(json_response.first['body']).to eq(merge_request_note.note)
|
2013-01-31 01:42:11 -05:00
|
|
|
end
|
2013-02-20 16:17:05 -05:00
|
|
|
|
|
|
|
it "should return a 404 error if merge request id not found" do
|
|
|
|
get api("/projects/#{project.id}/merge_requests/4444/notes", user)
|
2016-05-10 15:06:02 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2013-02-20 16:17:05 -05:00
|
|
|
end
|
2016-05-09 18:35:37 -04:00
|
|
|
|
|
|
|
it "returns 404 when not authorized" do
|
|
|
|
get api("/projects/#{project.id}/merge_requests/4444/notes", private_user)
|
2016-05-10 15:06:02 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2016-05-09 18:35:37 -04:00
|
|
|
end
|
2013-02-20 16:17:05 -05:00
|
|
|
end
|
2012-11-27 14:43:39 -05:00
|
|
|
end
|
2012-11-29 14:33:41 -05:00
|
|
|
|
|
|
|
describe "GET /projects/:id/noteable/:noteable_id/notes/:note_id" do
|
|
|
|
context "when noteable is an Issue" do
|
|
|
|
it "should return an issue note by id" do
|
|
|
|
get api("/projects/#{project.id}/issues/#{issue.id}/notes/#{issue_note.id}", user)
|
2016-05-10 15:06:02 -04:00
|
|
|
|
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['body']).to eq(issue_note.note)
|
2012-11-29 14:33:41 -05:00
|
|
|
end
|
2013-02-06 10:34:06 -05:00
|
|
|
|
|
|
|
it "should return a 404 error if issue note not found" do
|
2016-04-26 12:55:38 -04:00
|
|
|
get api("/projects/#{project.id}/issues/#{issue.id}/notes/12345", user)
|
2016-05-10 15:06:02 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2013-02-06 10:34:06 -05:00
|
|
|
end
|
2016-01-13 13:42:36 -05:00
|
|
|
|
2016-05-16 15:43:19 -04:00
|
|
|
context "and current user cannot view the note" do
|
2016-01-13 13:42:36 -05:00
|
|
|
it "should return a 404 error" do
|
|
|
|
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes/#{cross_reference_note.id}", user)
|
2016-05-10 15:06:02 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2016-01-13 13:42:36 -05:00
|
|
|
end
|
|
|
|
|
2016-05-16 15:43:19 -04:00
|
|
|
context "when issue is confidential" do
|
|
|
|
before { issue.update_attributes(confidential: true) }
|
|
|
|
|
|
|
|
it "returns 404" do
|
|
|
|
get api("/projects/#{project.id}/issues/#{issue.id}/notes/#{issue_note.id}", private_user)
|
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2016-05-16 15:43:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-13 13:42:36 -05:00
|
|
|
context "and current user can view the note" do
|
|
|
|
it "should return an issue note by id" do
|
|
|
|
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.id}/notes/#{cross_reference_note.id}", private_user)
|
2016-05-10 15:06:02 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2016-01-13 13:42:36 -05:00
|
|
|
expect(json_response['body']).to eq(cross_reference_note.note)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-11-29 14:33:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when noteable is a Snippet" do
|
|
|
|
it "should return a snippet note by id" do
|
|
|
|
get api("/projects/#{project.id}/snippets/#{snippet.id}/notes/#{snippet_note.id}", user)
|
2016-05-10 15:06:02 -04:00
|
|
|
|
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['body']).to eq(snippet_note.note)
|
2012-11-29 14:33:41 -05:00
|
|
|
end
|
2013-02-06 10:34:06 -05:00
|
|
|
|
|
|
|
it "should return a 404 error if snippet note not found" do
|
2016-04-26 12:55:38 -04:00
|
|
|
get api("/projects/#{project.id}/snippets/#{snippet.id}/notes/12345", user)
|
2016-05-10 15:06:02 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2013-02-06 10:34:06 -05:00
|
|
|
end
|
2012-11-29 14:33:41 -05:00
|
|
|
end
|
|
|
|
end
|
2012-11-29 15:06:24 -05:00
|
|
|
|
|
|
|
describe "POST /projects/:id/noteable/:noteable_id/notes" do
|
|
|
|
context "when noteable is an Issue" do
|
|
|
|
it "should create a new issue note" do
|
|
|
|
post api("/projects/#{project.id}/issues/#{issue.id}/notes", user), body: 'hi!'
|
2016-05-10 15:06:02 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(201)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response['body']).to eq('hi!')
|
|
|
|
expect(json_response['author']['username']).to eq(user.username)
|
2012-11-29 15:06:24 -05:00
|
|
|
end
|
2013-02-20 16:17:05 -05:00
|
|
|
|
|
|
|
it "should return a 400 bad request error if body not given" do
|
|
|
|
post api("/projects/#{project.id}/issues/#{issue.id}/notes", user)
|
2016-05-10 15:06:02 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(400)
|
2013-02-20 16:17:05 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return a 401 unauthorized error if user not authenticated" do
|
|
|
|
post api("/projects/#{project.id}/issues/#{issue.id}/notes"), body: 'hi!'
|
2016-05-10 15:06:02 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(401)
|
2013-02-20 16:17:05 -05:00
|
|
|
end
|
2016-04-05 14:04:11 -04:00
|
|
|
|
|
|
|
context 'when an admin or owner makes the request' do
|
|
|
|
it 'accepts the creation date to be set' do
|
|
|
|
creation_time = 2.weeks.ago
|
|
|
|
post api("/projects/#{project.id}/issues/#{issue.id}/notes", user),
|
|
|
|
body: 'hi!', created_at: creation_time
|
2016-05-10 15:06:02 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(201)
|
2016-04-05 14:04:11 -04:00
|
|
|
expect(json_response['body']).to eq('hi!')
|
|
|
|
expect(json_response['author']['username']).to eq(user.username)
|
|
|
|
expect(Time.parse(json_response['created_at'])).to be_within(1.second).of(creation_time)
|
|
|
|
end
|
|
|
|
end
|
2012-11-29 15:06:24 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when noteable is a Snippet" do
|
|
|
|
it "should create a new snippet note" do
|
|
|
|
post api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user), body: 'hi!'
|
2016-05-10 15:06:02 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(201)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response['body']).to eq('hi!')
|
|
|
|
expect(json_response['author']['username']).to eq(user.username)
|
2012-11-29 15:06:24 -05:00
|
|
|
end
|
2013-02-20 16:17:05 -05:00
|
|
|
|
|
|
|
it "should return a 400 bad request error if body not given" do
|
|
|
|
post api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user)
|
2016-05-10 15:06:02 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(400)
|
2013-02-20 16:17:05 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return a 401 unauthorized error if user not authenticated" do
|
|
|
|
post api("/projects/#{project.id}/snippets/#{snippet.id}/notes"), body: 'hi!'
|
2016-05-10 15:06:02 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(401)
|
2013-02-20 16:17:05 -05:00
|
|
|
end
|
|
|
|
end
|
2016-04-26 12:55:38 -04:00
|
|
|
|
|
|
|
context 'when user does not have access to create noteable' do
|
|
|
|
let(:private_issue) { create(:issue, project: create(:project, :private)) }
|
|
|
|
|
|
|
|
##
|
|
|
|
# We are posting to project user has access to, but we use issue id
|
|
|
|
# from a different project, see #15577
|
|
|
|
#
|
|
|
|
before do
|
|
|
|
post api("/projects/#{project.id}/issues/#{private_issue.id}/notes", user),
|
|
|
|
body: 'Hi!'
|
|
|
|
end
|
|
|
|
|
2016-04-25 07:19:57 -04:00
|
|
|
it 'responds with resource not found error' do
|
|
|
|
expect(response.status).to eq 404
|
2016-04-26 12:55:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create new note' do
|
|
|
|
expect(private_issue.notes.reload).to be_empty
|
|
|
|
end
|
|
|
|
end
|
2012-11-29 15:06:24 -05:00
|
|
|
end
|
2013-10-04 15:11:50 -04:00
|
|
|
|
|
|
|
describe "POST /projects/:id/noteable/:noteable_id/notes to test observer on create" do
|
|
|
|
it "should create an activity event when an issue note is created" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(Event).to receive(:create)
|
2013-10-04 15:11:50 -04:00
|
|
|
|
|
|
|
post api("/projects/#{project.id}/issues/#{issue.id}/notes", user), body: 'hi!'
|
|
|
|
end
|
|
|
|
end
|
2014-09-02 11:12:13 -04:00
|
|
|
|
|
|
|
describe 'PUT /projects/:id/noteable/:noteable_id/notes/:note_id' do
|
|
|
|
context 'when noteable is an Issue' do
|
|
|
|
it 'should return modified note' do
|
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}/"\
|
|
|
|
"notes/#{issue_note.id}", user), body: 'Hello!'
|
2016-05-10 15:06:02 -04:00
|
|
|
|
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['body']).to eq('Hello!')
|
2014-09-02 11:12:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return a 404 error when note id not found' do
|
2016-04-26 12:55:38 -04:00
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}/notes/12345", user),
|
2014-09-02 11:12:13 -04:00
|
|
|
body: 'Hello!'
|
2016-05-10 15:06:02 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2014-09-02 11:12:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return a 400 bad request error if body not given' do
|
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}/"\
|
|
|
|
"notes/#{issue_note.id}", user)
|
2016-05-10 15:06:02 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(400)
|
2014-09-02 11:12:13 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when noteable is a Snippet' do
|
|
|
|
it 'should return modified note' do
|
|
|
|
put api("/projects/#{project.id}/snippets/#{snippet.id}/"\
|
|
|
|
"notes/#{snippet_note.id}", user), body: 'Hello!'
|
2016-05-10 15:06:02 -04:00
|
|
|
|
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['body']).to eq('Hello!')
|
2014-09-02 11:12:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return a 404 error when note id not found' do
|
|
|
|
put api("/projects/#{project.id}/snippets/#{snippet.id}/"\
|
2016-04-26 12:55:38 -04:00
|
|
|
"notes/12345", user), body: "Hello!"
|
2016-05-10 15:06:02 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2014-09-02 11:12:13 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when noteable is a Merge Request' do
|
|
|
|
it 'should return modified note' do
|
|
|
|
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/"\
|
|
|
|
"notes/#{merge_request_note.id}", user), body: 'Hello!'
|
2016-05-10 15:06:02 -04:00
|
|
|
|
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['body']).to eq('Hello!')
|
2014-09-02 11:12:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return a 404 error when note id not found' do
|
|
|
|
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/"\
|
2016-04-26 12:55:38 -04:00
|
|
|
"notes/12345", user), body: "Hello!"
|
2016-05-10 15:06:02 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2014-09-02 11:12:13 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-06 13:04:17 -04:00
|
|
|
describe 'DELETE /projects/:id/noteable/:noteable_id/notes/:note_id' do
|
2016-04-05 19:21:02 -04:00
|
|
|
context 'when noteable is an Issue' do
|
2016-04-12 09:43:29 -04:00
|
|
|
it 'deletes a note' do
|
2016-04-05 19:21:02 -04:00
|
|
|
delete api("/projects/#{project.id}/issues/#{issue.id}/"\
|
|
|
|
"notes/#{issue_note.id}", user)
|
2016-04-06 13:04:17 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2016-04-06 13:04:17 -04:00
|
|
|
# Check if note is really deleted
|
|
|
|
delete api("/projects/#{project.id}/issues/#{issue.id}/"\
|
|
|
|
"notes/#{issue_note.id}", user)
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2016-04-05 19:21:02 -04:00
|
|
|
end
|
|
|
|
|
2016-04-12 09:43:29 -04:00
|
|
|
it 'returns a 404 error when note id not found' do
|
2016-04-26 12:55:38 -04:00
|
|
|
delete api("/projects/#{project.id}/issues/#{issue.id}/notes/12345", user)
|
2016-04-06 13:04:17 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2016-04-05 19:21:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when noteable is a Snippet' do
|
2016-04-12 09:43:29 -04:00
|
|
|
it 'deletes a note' do
|
2016-04-05 19:21:02 -04:00
|
|
|
delete api("/projects/#{project.id}/snippets/#{snippet.id}/"\
|
|
|
|
"notes/#{snippet_note.id}", user)
|
2016-04-06 13:04:17 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2016-04-06 13:04:17 -04:00
|
|
|
# Check if note is really deleted
|
|
|
|
delete api("/projects/#{project.id}/snippets/#{snippet.id}/"\
|
|
|
|
"notes/#{snippet_note.id}", user)
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2016-04-05 19:21:02 -04:00
|
|
|
end
|
|
|
|
|
2016-04-12 09:43:29 -04:00
|
|
|
it 'returns a 404 error when note id not found' do
|
2016-04-05 19:21:02 -04:00
|
|
|
delete api("/projects/#{project.id}/snippets/#{snippet.id}/"\
|
2016-04-26 12:55:38 -04:00
|
|
|
"notes/12345", user)
|
2016-04-06 13:04:17 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2016-04-05 19:21:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when noteable is a Merge Request' do
|
2016-04-12 09:43:29 -04:00
|
|
|
it 'deletes a note' do
|
2016-04-05 19:21:02 -04:00
|
|
|
delete api("/projects/#{project.id}/merge_requests/"\
|
|
|
|
"#{merge_request.id}/notes/#{merge_request_note.id}", user)
|
2016-04-06 13:04:17 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2016-04-06 13:04:17 -04:00
|
|
|
# Check if note is really deleted
|
|
|
|
delete api("/projects/#{project.id}/merge_requests/"\
|
|
|
|
"#{merge_request.id}/notes/#{merge_request_note.id}", user)
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2016-04-05 19:21:02 -04:00
|
|
|
end
|
|
|
|
|
2016-04-12 09:43:29 -04:00
|
|
|
it 'returns a 404 error when note id not found' do
|
2016-04-05 19:21:02 -04:00
|
|
|
delete api("/projects/#{project.id}/merge_requests/"\
|
2016-04-26 12:55:38 -04:00
|
|
|
"#{merge_request.id}/notes/12345", user)
|
2016-04-06 13:04:17 -04:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2016-04-05 19:21:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-11-27 14:43:39 -05:00
|
|
|
end
|