1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
# frozen_string_literal: true
RSpec.shared_examples 'diff draft notes API' do |id_name|
describe "post /projects/:id/merge_requests/:merge_request_id/draft_notes" do
it "creates a new diff draft note" do
line_range = {
"start" => {
"line_code" => Gitlab::Git.diff_line_code(draft_note.position.file_path, 1, 1),
"type" => draft_note.position.type
},
"end" => {
"line_code" => Gitlab::Git.diff_line_code(draft_note.position.file_path, 2, 2),
"type" => draft_note.position.type
}
}
position = draft_note.position.to_h.merge({ line_range: line_range }).except(:ignore_whitespace_change)
post api("/projects/#{project.id}/merge_requests/#{merge_request[id_name]}/draft_notes", user),
params: { note: 'hi!', position: position }
expect(response).to have_gitlab_http_status(:created)
expect(json_response['note']).to eq('hi!')
expect(json_response['position']).to eq(position.stringify_keys)
end
context "when position is invalid" do
it "returns a 400 bad request error when position is not plausible" do
position = draft_note.position.to_h.merge(new_line: '100000')
post api("/projects/#{project.id}/merge_requests/#{merge_request[id_name]}/draft_notes", user),
params: { body: 'hi!', position: position }
expect(response).to have_gitlab_http_status(:bad_request)
end
it "returns a 400 bad request error when the position is not valid for this discussion" do
position = draft_note.position.to_h.merge(new_line: '588440f66559714280628a4f9799f0c4eb880a4a')
post api("/projects/#{project.id}/merge_requests/#{merge_request[id_name]}/draft_notes", user),
params: { body: 'hi!', position: position }
expect(response).to have_gitlab_http_status(:bad_request)
end
end
end
describe "put /projects/:id/merge_requests/:merge_request_id/draft_notes/:draft_note_id" do
it "modifies a draft note" do
line_range = {
"start" => {
"line_code" => Gitlab::Git.diff_line_code(draft_note.position.file_path, 3, 3),
"type" => draft_note.position.type
},
"end" => {
"line_code" => Gitlab::Git.diff_line_code(draft_note.position.file_path, 4, 4),
"type" => draft_note.position.type
}
}
position = draft_note.position.to_h.merge({ line_range: line_range }).except(:ignore_whitespace_change)
put api("/projects/#{project.id}/merge_requests/#{merge_request[id_name]}/draft_notes/#{draft_note.id}", user),
params: { note: 'hola!', position: position }
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['note']).to eq('hola!')
expect(json_response['position']).to eq(position.stringify_keys)
end
it "returns bad request for an empty note" do
line_range = {
"start" => {
"line_code" => Gitlab::Git.diff_line_code(draft_note.position.file_path, 3, 3),
"type" => draft_note.position.type
},
"end" => {
"line_code" => Gitlab::Git.diff_line_code(draft_note.position.file_path, 4, 4),
"type" => draft_note.position.type
}
}
position = draft_note.position.to_h.merge({ line_range: line_range }).except(:ignore_whitespace_change)
put api("/projects/#{project.id}/merge_requests/#{merge_request[id_name]}/draft_notes/#{draft_note.id}", user),
params: { note: '', position: position }
expect(response).to have_gitlab_http_status(:bad_request)
end
end
end
|