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

83 lines
2.7 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
require 'spec_helper'
describe API::Suggestions do
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
let(:merge_request) do
create(:merge_request, source_project: project,
target_project: project)
end
let(:position) do
Gitlab::Diff::Position.new(old_path: "files/ruby/popen.rb",
new_path: "files/ruby/popen.rb",
old_line: nil,
new_line: 9,
diff_refs: merge_request.diff_refs)
end
let(:diff_note) do
create(:diff_note_on_merge_request, noteable: merge_request,
position: position,
project: project)
end
describe "PUT /suggestions/:id/apply" do
let(:url) { "/suggestions/#{suggestion.id}/apply" }
context 'when successfully applies patch' do
let(:suggestion) do
create(:suggestion, note: diff_note,
from_content: " raise RuntimeError, \"System commands must be given as an array of strings\"\n",
to_content: " raise RuntimeError, 'Explosion'\n # explosion?")
end
it 'returns 200 with json content' do
project.add_maintainer(user)
put api(url, user), params: { id: suggestion.id }
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:ok)
2019-02-15 15:39:39 +05:30
expect(json_response)
2019-05-18 00:54:41 +05:30
.to include('id', 'from_line', 'to_line', 'appliable', 'applied',
2019-02-15 15:39:39 +05:30
'from_content', 'to_content')
end
end
context 'when not able to apply patch' do
let(:suggestion) do
create(:suggestion, :unappliable, note: diff_note)
end
it 'returns 400 with json content' do
project.add_maintainer(user)
put api(url, user), params: { id: suggestion.id }
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:bad_request)
2019-02-15 15:39:39 +05:30
expect(json_response).to eq({ 'message' => 'Suggestion is not appliable' })
end
end
context 'when unauthorized' do
let(:suggestion) do
create(:suggestion, note: diff_note,
from_content: " raise RuntimeError, \"System commands must be given as an array of strings\"\n",
to_content: " raise RuntimeError, 'Explosion'\n # explosion?")
end
it 'returns 403 with json content' do
project.add_reporter(user)
put api(url, user), params: { id: suggestion.id }
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:forbidden)
2019-02-15 15:39:39 +05:30
expect(json_response).to eq({ 'message' => '403 Forbidden' })
end
end
end
end