2019-10-28 20:06:10 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-02-28 02:48:23 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe API::Discussions do
|
2018-02-28 02:48:23 -05:00
|
|
|
let(:user) { create(:user) }
|
2018-05-01 08:39:44 -04:00
|
|
|
let!(:project) { create(:project, :public, :repository, namespace: user.namespace) }
|
2019-01-16 07:09:29 -05:00
|
|
|
let(:private_user) { create(:user) }
|
2018-02-28 02:48:23 -05:00
|
|
|
|
|
|
|
before do
|
2018-05-01 08:39:44 -04:00
|
|
|
project.add_developer(user)
|
2018-02-28 02:48:23 -05:00
|
|
|
end
|
|
|
|
|
2019-08-22 03:19:44 -04:00
|
|
|
context 'when discussions have cross-reference system notes' do
|
2019-08-15 00:50:52 -04:00
|
|
|
let(:url) { "/projects/#{project.id}/merge_requests/#{merge_request.iid}/discussions" }
|
2019-08-22 03:19:44 -04:00
|
|
|
let(:notes_in_response) { json_response.first['notes'] }
|
2019-08-15 00:50:52 -04:00
|
|
|
|
2019-08-22 03:19:44 -04:00
|
|
|
it_behaves_like 'with cross-reference system notes'
|
2019-08-15 00:50:52 -04:00
|
|
|
end
|
|
|
|
|
2018-05-01 08:39:44 -04:00
|
|
|
context 'when noteable is an Issue' do
|
2018-02-28 02:48:23 -05:00
|
|
|
let!(:issue) { create(:issue, project: project, author: user) }
|
|
|
|
let!(:issue_note) { create(:discussion_note_on_issue, noteable: issue, project: project, author: user) }
|
|
|
|
|
2019-05-20 10:11:44 -04:00
|
|
|
it_behaves_like 'discussions API', 'projects', 'issues', 'iid', can_reply_to_individual_notes: true do
|
2018-02-28 02:48:23 -05:00
|
|
|
let(:parent) { project }
|
|
|
|
let(:noteable) { issue }
|
|
|
|
let(:note) { issue_note }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-01 08:39:44 -04:00
|
|
|
context 'when noteable is a Snippet' do
|
2018-02-28 02:48:23 -05:00
|
|
|
let!(:snippet) { create(:project_snippet, project: project, author: user) }
|
2020-04-03 14:10:03 -04:00
|
|
|
let!(:snippet_note) { create(:discussion_note_on_project_snippet, noteable: snippet, project: project, author: user) }
|
2018-02-28 02:48:23 -05:00
|
|
|
|
2018-05-01 08:39:44 -04:00
|
|
|
it_behaves_like 'discussions API', 'projects', 'snippets', 'id' do
|
2018-02-28 02:48:23 -05:00
|
|
|
let(:parent) { project }
|
|
|
|
let(:noteable) { snippet }
|
|
|
|
let(:note) { snippet_note }
|
|
|
|
end
|
|
|
|
end
|
2018-05-01 08:39:44 -04:00
|
|
|
|
|
|
|
context 'when noteable is a Merge Request' do
|
|
|
|
let!(:noteable) { create(:merge_request_with_diffs, source_project: project, target_project: project, author: user) }
|
|
|
|
let!(:note) { create(:discussion_note_on_merge_request, noteable: noteable, project: project, author: user) }
|
|
|
|
let!(:diff_note) { create(:diff_note_on_merge_request, noteable: noteable, project: project, author: user) }
|
|
|
|
let(:parent) { project }
|
|
|
|
|
2019-05-20 10:11:44 -04:00
|
|
|
it_behaves_like 'discussions API', 'projects', 'merge_requests', 'iid', can_reply_to_individual_notes: true
|
2018-05-01 08:39:44 -04:00
|
|
|
it_behaves_like 'diff discussions API', 'projects', 'merge_requests', 'iid'
|
|
|
|
it_behaves_like 'resolvable discussions API', 'projects', 'merge_requests', 'iid'
|
2019-12-23 07:08:18 -05:00
|
|
|
|
|
|
|
context "when position is for a previous commit on the merge request" do
|
|
|
|
it "returns a 400 bad request error because the line_code is old" do
|
|
|
|
# SHA taken from an earlier commit listed in spec/factories/merge_requests.rb
|
|
|
|
position = diff_note.position.to_h.merge(new_line: 'c1acaa58bbcbc3eafe538cb8274ba387047b69f8')
|
|
|
|
|
|
|
|
post api("/projects/#{project.id}/merge_requests/#{noteable['iid']}/discussions", user),
|
|
|
|
params: { body: 'hi!', position: position }
|
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2019-12-23 07:08:18 -05:00
|
|
|
end
|
|
|
|
end
|
2020-12-15 19:09:58 -05:00
|
|
|
|
|
|
|
context "when a commit parameter is given" do
|
|
|
|
it "creates the discussion on that commit within the merge request" do
|
|
|
|
# SHAs of "feature" and its parent in spec/support/gitlab-git-test.git
|
|
|
|
mr_commit = '0b4bc9a49b562e85de7cc9e834518ea6828729b9'
|
|
|
|
parent_commit = 'ae73cb07c9eeaf35924a10f713b364d32b2dd34f'
|
|
|
|
file = "files/ruby/feature.rb"
|
|
|
|
position = build(
|
|
|
|
:text_diff_position,
|
|
|
|
:added,
|
|
|
|
file: file,
|
|
|
|
new_line: 1,
|
|
|
|
base_sha: parent_commit,
|
|
|
|
head_sha: mr_commit,
|
|
|
|
start_sha: parent_commit
|
|
|
|
)
|
|
|
|
|
|
|
|
post api("/projects/#{project.id}/merge_requests/#{noteable['iid']}/discussions", user),
|
|
|
|
params: { body: 'MR discussion on commit', position: position.to_h, commit_id: mr_commit }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:created)
|
|
|
|
expect(json_response['notes'].first['commit_id']).to eq(mr_commit)
|
|
|
|
end
|
|
|
|
end
|
2018-05-01 08:39:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when noteable is a Commit' do
|
|
|
|
let!(:noteable) { create(:commit, project: project, author: user) }
|
|
|
|
let!(:note) { create(:discussion_note_on_commit, commit_id: noteable.id, project: project, author: user) }
|
|
|
|
let!(:diff_note) { create(:diff_note_on_commit, commit_id: noteable.id, project: project, author: user) }
|
|
|
|
let(:parent) { project }
|
|
|
|
|
|
|
|
it_behaves_like 'discussions API', 'projects', 'repository/commits', 'id'
|
|
|
|
it_behaves_like 'diff discussions API', 'projects', 'repository/commits', 'id'
|
|
|
|
end
|
2018-02-28 02:48:23 -05:00
|
|
|
end
|