debian-mirror-gitlab/spec/requests/api/notes_spec.rb

606 lines
22 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
require 'spec_helper'
2017-08-17 22:00:37 +05:30
describe API::Notes do
2014-09-02 18:07:02 +05:30
let(:user) { create(:user) }
2017-09-10 17:25:29 +05:30
let!(:project) { create(:project, :public, namespace: user.namespace) }
2014-09-02 18:07:02 +05:30
let!(:issue) { create(:issue, project: project, author: user) }
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project, author: user) }
let!(:snippet) { create(:project_snippet, project: project, author: user) }
let!(:issue_note) { create(:note, noteable: issue, project: project, author: user) }
let!(:merge_request_note) { create(:note, noteable: merge_request, project: project, author: user) }
let!(:snippet_note) { create(:note, noteable: snippet, project: project, author: user) }
# For testing the cross-reference of a private issue in a public issue
let(:private_user) { create(:user) }
let(:private_project) do
2017-09-10 17:25:29 +05:30
create(:project, namespace: private_user.namespace)
2018-03-17 18:26:18 +05:30
.tap { |p| p.add_master(private_user) }
end
let(:private_issue) { create(:issue, project: private_project) }
2017-09-10 17:25:29 +05:30
let(:ext_proj) { create(:project, :public) }
let(:ext_issue) { create(:issue, project: ext_proj) }
let!(:cross_reference_note) do
create :note,
noteable: ext_issue, project: ext_proj,
2017-08-17 22:00:37 +05:30
note: "mentioned in issue #{private_issue.to_reference(ext_proj)}",
system: true
end
2017-09-10 17:25:29 +05:30
before do
2018-03-17 18:26:18 +05:30
project.add_reporter(user)
2017-09-10 17:25:29 +05:30
end
2014-09-02 18:07:02 +05:30
describe "GET /projects/:id/noteable/:noteable_id/notes" do
context "when noteable is an Issue" do
2018-03-17 18:26:18 +05:30
context 'sorting' do
before do
create_list(:note, 3, noteable: issue, project: project, author: user)
end
it 'sorts by created_at in descending order by default' do
get api("/projects/#{project.id}/issues/#{issue.iid}/notes", user)
response_dates = json_response.map { |noteable| noteable['created_at'] }
expect(json_response.length).to eq(4)
expect(response_dates).to eq(response_dates.sort.reverse)
end
it 'sorts by ascending order when requested' do
get api("/projects/#{project.id}/issues/#{issue.iid}/notes?sort=asc", user)
response_dates = json_response.map { |noteable| noteable['created_at'] }
expect(json_response.length).to eq(4)
expect(response_dates).to eq(response_dates.sort)
end
it 'sorts by updated_at in descending order when requested' do
get api("/projects/#{project.id}/issues/#{issue.iid}/notes?order_by=updated_at", user)
response_dates = json_response.map { |noteable| noteable['updated_at'] }
expect(json_response.length).to eq(4)
expect(response_dates).to eq(response_dates.sort.reverse)
end
it 'sorts by updated_at in ascending order when requested' do
get api("/projects/#{project.id}/issues/#{issue.iid}/notes??order_by=updated_at&sort=asc", user)
response_dates = json_response.map { |noteable| noteable['updated_at'] }
expect(json_response.length).to eq(4)
expect(response_dates).to eq(response_dates.sort)
end
end
2016-09-13 17:45:13 +05:30
it "returns an array of issue notes" do
2017-08-17 22:00:37 +05:30
get api("/projects/#{project.id}/issues/#{issue.iid}/notes", user)
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2017-08-17 22:00:37 +05:30
expect(response).to include_pagination_headers
2015-04-26 12:48:37 +05:30
expect(json_response).to be_an Array
expect(json_response.first['body']).to eq(issue_note.note)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "returns a 404 error when issue id not found" do
2016-06-02 11:05:42 +05:30
get api("/projects/#{project.id}/issues/12345/notes", user)
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
2014-09-02 18:07:02 +05:30
end
2016-06-02 11:05:42 +05:30
context "and current user cannot view the notes" do
2016-09-13 17:45:13 +05:30
it "returns an empty array" do
2017-08-17 22:00:37 +05:30
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.iid}/notes", user)
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2017-08-17 22:00:37 +05:30
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response).to be_empty
end
2016-06-02 11:05:42 +05:30
context "and issue is confidential" do
2017-09-10 17:25:29 +05:30
before do
ext_issue.update_attributes(confidential: true)
end
2016-06-02 11:05:42 +05:30
it "returns 404" do
2017-08-17 22:00:37 +05:30
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.iid}/notes", user)
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
2016-06-02 11:05:42 +05:30
end
end
context "and current user can view the note" do
2016-09-13 17:45:13 +05:30
it "returns an empty array" do
2017-08-17 22:00:37 +05:30
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.iid}/notes", private_user)
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2017-08-17 22:00:37 +05:30
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.first['body']).to eq(cross_reference_note.note)
end
end
end
2014-09-02 18:07:02 +05:30
end
context "when noteable is a Snippet" do
2018-03-17 18:26:18 +05:30
context 'sorting' do
before do
create_list(:note, 3, noteable: snippet, project: project, author: user)
end
it 'sorts by created_at in descending order by default' do
get api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user)
response_dates = json_response.map { |noteable| noteable['created_at'] }
expect(json_response.length).to eq(4)
expect(response_dates).to eq(response_dates.sort.reverse)
end
it 'sorts by ascending order when requested' do
get api("/projects/#{project.id}/snippets/#{snippet.id}/notes?sort=asc", user)
response_dates = json_response.map { |noteable| noteable['created_at'] }
expect(json_response.length).to eq(4)
expect(response_dates).to eq(response_dates.sort)
end
it 'sorts by updated_at in descending order when requested' do
get api("/projects/#{project.id}/snippets/#{snippet.id}/notes?order_by=updated_at", user)
response_dates = json_response.map { |noteable| noteable['updated_at'] }
expect(json_response.length).to eq(4)
expect(response_dates).to eq(response_dates.sort.reverse)
end
it 'sorts by updated_at in ascending order when requested' do
get api("/projects/#{project.id}/snippets/#{snippet.id}/notes??order_by=updated_at&sort=asc", user)
response_dates = json_response.map { |noteable| noteable['updated_at'] }
expect(json_response.length).to eq(4)
expect(response_dates).to eq(response_dates.sort)
end
end
2016-09-13 17:45:13 +05:30
it "returns an array of snippet notes" do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user)
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2017-08-17 22:00:37 +05:30
expect(response).to include_pagination_headers
2015-04-26 12:48:37 +05:30
expect(json_response).to be_an Array
expect(json_response.first['body']).to eq(snippet_note.note)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "returns a 404 error when snippet id not found" do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/snippets/42/notes", user)
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
2016-06-02 11:05:42 +05:30
end
it "returns 404 when not authorized" do
get api("/projects/#{project.id}/snippets/#{snippet.id}/notes", private_user)
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
2014-09-02 18:07:02 +05:30
end
end
context "when noteable is a Merge Request" do
2018-03-17 18:26:18 +05:30
context 'sorting' do
before do
create_list(:note, 3, noteable: merge_request, project: project, author: user)
end
it 'sorts by created_at in descending order by default' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/notes", user)
response_dates = json_response.map { |noteable| noteable['created_at'] }
expect(json_response.length).to eq(4)
expect(response_dates).to eq(response_dates.sort.reverse)
end
it 'sorts by ascending order when requested' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/notes?sort=asc", user)
response_dates = json_response.map { |noteable| noteable['created_at'] }
expect(json_response.length).to eq(4)
expect(response_dates).to eq(response_dates.sort)
end
it 'sorts by updated_at in descending order when requested' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/notes?order_by=updated_at", user)
response_dates = json_response.map { |noteable| noteable['updated_at'] }
expect(json_response.length).to eq(4)
expect(response_dates).to eq(response_dates.sort.reverse)
end
it 'sorts by updated_at in ascending order when requested' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/notes??order_by=updated_at&sort=asc", user)
response_dates = json_response.map { |noteable| noteable['updated_at'] }
expect(json_response.length).to eq(4)
expect(response_dates).to eq(response_dates.sort)
end
end
2016-09-13 17:45:13 +05:30
it "returns an array of merge_requests notes" do
2017-08-17 22:00:37 +05:30
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/notes", user)
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2017-08-17 22:00:37 +05:30
expect(response).to include_pagination_headers
2015-04-26 12:48:37 +05:30
expect(json_response).to be_an Array
expect(json_response.first['body']).to eq(merge_request_note.note)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "returns a 404 error if merge request id not found" do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/merge_requests/4444/notes", user)
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
2016-06-02 11:05:42 +05:30
end
it "returns 404 when not authorized" do
get api("/projects/#{project.id}/merge_requests/4444/notes", private_user)
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
2014-09-02 18:07:02 +05:30
end
end
end
describe "GET /projects/:id/noteable/:noteable_id/notes/:note_id" do
context "when noteable is an Issue" do
2016-09-13 17:45:13 +05:30
it "returns an issue note by id" do
2017-08-17 22:00:37 +05:30
get api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{issue_note.id}", user)
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2015-04-26 12:48:37 +05:30
expect(json_response['body']).to eq(issue_note.note)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "returns a 404 error if issue note not found" do
2017-08-17 22:00:37 +05:30
get api("/projects/#{project.id}/issues/#{issue.iid}/notes/12345", user)
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
2014-09-02 18:07:02 +05:30
end
2016-06-02 11:05:42 +05:30
context "and current user cannot view the note" do
2016-09-13 17:45:13 +05:30
it "returns a 404 error" do
2017-08-17 22:00:37 +05:30
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.iid}/notes/#{cross_reference_note.id}", user)
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
end
2016-06-02 11:05:42 +05:30
context "when issue is confidential" do
2017-09-10 17:25:29 +05:30
before do
issue.update_attributes(confidential: true)
end
2016-06-02 11:05:42 +05:30
it "returns 404" do
2017-08-17 22:00:37 +05:30
get api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{issue_note.id}", private_user)
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
2016-06-02 11:05:42 +05:30
end
end
context "and current user can view the note" do
2016-09-13 17:45:13 +05:30
it "returns an issue note by id" do
2017-08-17 22:00:37 +05:30
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.iid}/notes/#{cross_reference_note.id}", private_user)
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
expect(json_response['body']).to eq(cross_reference_note.note)
end
end
end
2014-09-02 18:07:02 +05:30
end
context "when noteable is a Snippet" do
2016-09-13 17:45:13 +05:30
it "returns a snippet note by id" do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/snippets/#{snippet.id}/notes/#{snippet_note.id}", user)
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2015-04-26 12:48:37 +05:30
expect(json_response['body']).to eq(snippet_note.note)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "returns a 404 error if snippet note not found" do
2016-06-02 11:05:42 +05:30
get api("/projects/#{project.id}/snippets/#{snippet.id}/notes/12345", user)
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
2014-09-02 18:07:02 +05:30
end
end
end
describe "POST /projects/:id/noteable/:noteable_id/notes" do
context "when noteable is an Issue" do
2016-09-13 17:45:13 +05:30
it "creates a new issue note" do
2017-08-17 22:00:37 +05:30
post api("/projects/#{project.id}/issues/#{issue.iid}/notes", user), body: 'hi!'
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(201)
2015-04-26 12:48:37 +05:30
expect(json_response['body']).to eq('hi!')
expect(json_response['author']['username']).to eq(user.username)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "returns a 400 bad request error if body not given" do
2017-08-17 22:00:37 +05:30
post api("/projects/#{project.id}/issues/#{issue.iid}/notes", user)
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(400)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "returns a 401 unauthorized error if user not authenticated" do
2017-08-17 22:00:37 +05:30
post api("/projects/#{project.id}/issues/#{issue.iid}/notes"), body: 'hi!'
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(401)
2014-09-02 18:07:02 +05:30
end
2016-06-02 11:05:42 +05:30
context 'when an admin or owner makes the request' do
it 'accepts the creation date to be set' do
creation_time = 2.weeks.ago
2017-08-17 22:00:37 +05:30
post api("/projects/#{project.id}/issues/#{issue.iid}/notes", user),
2016-06-02 11:05:42 +05:30
body: 'hi!', created_at: creation_time
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(201)
2016-06-02 11:05:42 +05:30
expect(json_response['body']).to eq('hi!')
expect(json_response['author']['username']).to eq(user.username)
2016-11-03 12:29:30 +05:30
expect(Time.parse(json_response['created_at'])).to be_like_time(creation_time)
2016-06-02 11:05:42 +05:30
end
end
2016-09-29 09:46:39 +05:30
2017-08-17 22:00:37 +05:30
context 'when the user is posting an award emoji on an issue created by someone else' do
let(:issue2) { create(:issue, project: project) }
it 'creates a new issue note' do
post api("/projects/#{project.id}/issues/#{issue2.iid}/notes", user), body: ':+1:'
2016-09-29 09:46:39 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(201)
2017-08-17 22:00:37 +05:30
expect(json_response['body']).to eq(':+1:')
end
end
context 'when the user is posting an award emoji on his/her own issue' do
it 'creates a new issue note' do
post api("/projects/#{project.id}/issues/#{issue.iid}/notes", user), body: ':+1:'
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(201)
2017-08-17 22:00:37 +05:30
expect(json_response['body']).to eq(':+1:')
2016-09-29 09:46:39 +05:30
end
end
2014-09-02 18:07:02 +05:30
end
context "when noteable is a Snippet" do
2016-09-13 17:45:13 +05:30
it "creates a new snippet note" do
2014-09-02 18:07:02 +05:30
post api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user), body: 'hi!'
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(201)
2015-04-26 12:48:37 +05:30
expect(json_response['body']).to eq('hi!')
expect(json_response['author']['username']).to eq(user.username)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "returns a 400 bad request error if body not given" do
2014-09-02 18:07:02 +05:30
post api("/projects/#{project.id}/snippets/#{snippet.id}/notes", user)
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(400)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "returns a 401 unauthorized error if user not authenticated" do
2014-09-02 18:07:02 +05:30
post api("/projects/#{project.id}/snippets/#{snippet.id}/notes"), body: 'hi!'
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(401)
2014-09-02 18:07:02 +05:30
end
end
2016-06-02 11:05:42 +05:30
2017-08-17 22:00:37 +05:30
context 'when user does not have access to read the noteable' do
it 'responds with 404' do
2017-09-10 17:25:29 +05:30
project = create(:project, :private) { |p| p.add_guest(user) }
2017-08-17 22:00:37 +05:30
issue = create(:issue, :confidential, project: project)
post api("/projects/#{project.id}/issues/#{issue.iid}/notes", user),
body: 'Foo'
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
2017-08-17 22:00:37 +05:30
end
end
2016-06-02 11:05:42 +05:30
context 'when user does not have access to create noteable' do
2017-09-10 17:25:29 +05:30
let(:private_issue) { create(:issue, project: create(:project, :private)) }
2016-06-02 11:05:42 +05:30
##
# We are posting to project user has access to, but we use issue id
# from a different project, see #15577
#
before do
2017-08-17 22:00:37 +05:30
post api("/projects/#{private_issue.project.id}/issues/#{private_issue.iid}/notes", user),
2016-06-02 11:05:42 +05:30
body: 'Hi!'
end
it 'responds with resource not found error' do
expect(response.status).to eq 404
2016-06-02 11:05:42 +05:30
end
it 'does not create new note' do
expect(private_issue.notes.reload).to be_empty
end
end
2018-03-17 18:26:18 +05:30
context 'when the merge request discussion is locked' do
before do
merge_request.update_attribute(:discussion_locked, true)
end
context 'when a user is a team member' do
subject { post api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/notes", user), body: 'Hi!' }
it 'returns 200 status' do
subject
expect(response).to have_gitlab_http_status(201)
end
it 'creates a new note' do
expect { subject }.to change { Note.count }.by(1)
end
end
context 'when a user is not a team member' do
subject { post api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/notes", private_user), body: 'Hi!' }
it 'returns 403 status' do
subject
expect(response).to have_gitlab_http_status(403)
end
it 'does not create a new note' do
expect { subject }.not_to change { Note.count }
end
end
end
2014-09-02 18:07:02 +05:30
end
describe "POST /projects/:id/noteable/:noteable_id/notes to test observer on create" do
2016-09-13 17:45:13 +05:30
it "creates an activity event when an issue note is created" do
2018-03-17 18:26:18 +05:30
expect(Event).to receive(:create!)
2014-09-02 18:07:02 +05:30
2017-08-17 22:00:37 +05:30
post api("/projects/#{project.id}/issues/#{issue.iid}/notes", user), body: 'hi!'
2014-09-02 18:07:02 +05:30
end
end
2015-04-26 12:48:37 +05:30
describe 'PUT /projects/:id/noteable/:noteable_id/notes/:note_id' do
context 'when noteable is an Issue' do
2016-09-13 17:45:13 +05:30
it 'returns modified note' do
2017-08-17 22:00:37 +05:30
put api("/projects/#{project.id}/issues/#{issue.iid}/"\
2015-04-26 12:48:37 +05:30
"notes/#{issue_note.id}", user), body: 'Hello!'
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2015-04-26 12:48:37 +05:30
expect(json_response['body']).to eq('Hello!')
end
2016-09-13 17:45:13 +05:30
it 'returns a 404 error when note id not found' do
2017-08-17 22:00:37 +05:30
put api("/projects/#{project.id}/issues/#{issue.iid}/notes/12345", user),
2015-04-26 12:48:37 +05:30
body: 'Hello!'
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
2015-04-26 12:48:37 +05:30
end
2016-09-13 17:45:13 +05:30
it 'returns a 400 bad request error if body not given' do
2017-08-17 22:00:37 +05:30
put api("/projects/#{project.id}/issues/#{issue.iid}/"\
2015-04-26 12:48:37 +05:30
"notes/#{issue_note.id}", user)
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(400)
2015-04-26 12:48:37 +05:30
end
end
context 'when noteable is a Snippet' do
2016-09-13 17:45:13 +05:30
it 'returns modified note' do
2015-04-26 12:48:37 +05:30
put api("/projects/#{project.id}/snippets/#{snippet.id}/"\
"notes/#{snippet_note.id}", user), body: 'Hello!'
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2015-04-26 12:48:37 +05:30
expect(json_response['body']).to eq('Hello!')
end
2016-09-13 17:45:13 +05:30
it 'returns a 404 error when note id not found' do
2015-04-26 12:48:37 +05:30
put api("/projects/#{project.id}/snippets/#{snippet.id}/"\
2016-06-02 11:05:42 +05:30
"notes/12345", user), body: "Hello!"
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
2015-04-26 12:48:37 +05:30
end
end
context 'when noteable is a Merge Request' do
2016-09-13 17:45:13 +05:30
it 'returns modified note' do
2017-08-17 22:00:37 +05:30
put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/"\
2015-04-26 12:48:37 +05:30
"notes/#{merge_request_note.id}", user), body: 'Hello!'
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2015-04-26 12:48:37 +05:30
expect(json_response['body']).to eq('Hello!')
end
2016-09-13 17:45:13 +05:30
it 'returns a 404 error when note id not found' do
2017-08-17 22:00:37 +05:30
put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/"\
2016-06-02 11:05:42 +05:30
"notes/12345", user), body: "Hello!"
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
2016-06-02 11:05:42 +05:30
end
end
end
describe 'DELETE /projects/:id/noteable/:noteable_id/notes/:note_id' do
context 'when noteable is an Issue' do
it 'deletes a note' do
2017-08-17 22:00:37 +05:30
delete api("/projects/#{project.id}/issues/#{issue.iid}/"\
2016-06-02 11:05:42 +05:30
"notes/#{issue_note.id}", user)
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(204)
2016-06-02 11:05:42 +05:30
# Check if note is really deleted
2017-08-17 22:00:37 +05:30
delete api("/projects/#{project.id}/issues/#{issue.iid}/"\
2016-06-02 11:05:42 +05:30
"notes/#{issue_note.id}", user)
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
2016-06-02 11:05:42 +05:30
end
it 'returns a 404 error when note id not found' do
2017-08-17 22:00:37 +05:30
delete api("/projects/#{project.id}/issues/#{issue.iid}/notes/12345", user)
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
end
it_behaves_like '412 response' do
let(:request) { api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{issue_note.id}", user) }
2016-06-02 11:05:42 +05:30
end
end
context 'when noteable is a Snippet' do
it 'deletes a note' do
delete api("/projects/#{project.id}/snippets/#{snippet.id}/"\
"notes/#{snippet_note.id}", user)
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(204)
2016-06-02 11:05:42 +05:30
# Check if note is really deleted
delete api("/projects/#{project.id}/snippets/#{snippet.id}/"\
"notes/#{snippet_note.id}", user)
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
2016-06-02 11:05:42 +05:30
end
it 'returns a 404 error when note id not found' do
delete api("/projects/#{project.id}/snippets/#{snippet.id}/"\
"notes/12345", user)
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
end
it_behaves_like '412 response' do
let(:request) { api("/projects/#{project.id}/snippets/#{snippet.id}/notes/#{snippet_note.id}", user) }
2016-06-02 11:05:42 +05:30
end
end
context 'when noteable is a Merge Request' do
it 'deletes a note' do
delete api("/projects/#{project.id}/merge_requests/"\
2017-08-17 22:00:37 +05:30
"#{merge_request.iid}/notes/#{merge_request_note.id}", user)
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(204)
2016-06-02 11:05:42 +05:30
# Check if note is really deleted
delete api("/projects/#{project.id}/merge_requests/"\
2017-08-17 22:00:37 +05:30
"#{merge_request.iid}/notes/#{merge_request_note.id}", user)
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
2016-06-02 11:05:42 +05:30
end
it 'returns a 404 error when note id not found' do
delete api("/projects/#{project.id}/merge_requests/"\
2017-08-17 22:00:37 +05:30
"#{merge_request.iid}/notes/12345", user)
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
end
it_behaves_like '412 response' do
let(:request) { api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/notes/#{merge_request_note.id}", user) }
2015-04-26 12:48:37 +05:30
end
end
end
2014-09-02 18:07:02 +05:30
end