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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

88 lines
3.9 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2016-09-29 09:46:39 +05:30
require "spec_helper"
2023-03-04 22:38:38 +05:30
RSpec.describe API::MergeRequestDiffs, 'MergeRequestDiffs', feature_category: :source_code_management do
2016-09-29 09:46:39 +05:30
let!(:user) { create(:user) }
let!(:merge_request) { create(:merge_request, importing: true) }
let!(:project) { merge_request.target_project }
before do
2020-11-24 15:15:51 +05:30
merge_request.merge_request_diffs.create!(head_commit_sha: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9')
merge_request.merge_request_diffs.create!(head_commit_sha: '5937ac0a7beb003549fc5fd26fc247adbce4a52e')
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2016-09-29 09:46:39 +05:30
end
2017-08-17 22:00:37 +05:30
describe 'GET /projects/:id/merge_requests/:merge_request_iid/versions' do
it 'returns 200 for a valid merge request' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/versions", user)
2018-03-17 18:26:18 +05:30
merge_request_diff = merge_request.merge_request_diffs.last
2017-08-17 22:00:37 +05:30
2020-04-22 19:07:51 +05:30
expect(response).to have_gitlab_http_status(:ok)
2017-08-17 22:00:37 +05:30
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.size).to eq(merge_request.merge_request_diffs.size)
expect(json_response.first['id']).to eq(merge_request_diff.id)
expect(json_response.first['head_commit_sha']).to eq(merge_request_diff.head_commit_sha)
end
2016-09-29 09:46:39 +05:30
2017-08-17 22:00:37 +05:30
it 'returns a 404 when merge_request id is used instead of the iid' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/versions", user)
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2016-09-29 09:46:39 +05:30
end
2017-08-17 22:00:37 +05:30
it 'returns a 404 when merge_request_iid not found' do
2019-07-07 11:18:12 +05:30
get api("/projects/#{project.id}/merge_requests/0/versions", user)
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2016-09-29 09:46:39 +05:30
end
2021-02-11 23:33:58 +05:30
context 'when merge request author has only guest access' do
it_behaves_like 'rejects user from accessing merge request info' do
let(:url) { "/projects/#{project.id}/merge_requests/#{merge_request.iid}/versions" }
end
end
2016-09-29 09:46:39 +05:30
end
2017-08-17 22:00:37 +05:30
describe 'GET /projects/:id/merge_requests/:merge_request_iid/versions/:version_id' do
let(:merge_request_diff) { merge_request.merge_request_diffs.first }
it 'returns a 200 for a valid merge request' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/versions/#{merge_request_diff.id}", user)
2016-09-29 09:46:39 +05:30
2020-04-22 19:07:51 +05:30
expect(response).to have_gitlab_http_status(:ok)
2017-08-17 22:00:37 +05:30
expect(json_response['id']).to eq(merge_request_diff.id)
expect(json_response['head_commit_sha']).to eq(merge_request_diff.head_commit_sha)
expect(json_response['diffs'].size).to eq(merge_request_diff.diffs.size)
end
it 'returns a 404 when merge_request id is used instead of the iid' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/versions/#{merge_request_diff.id}", user)
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2017-08-17 22:00:37 +05:30
end
it 'returns a 404 when merge_request version_id is not found' do
2019-07-07 11:18:12 +05:30
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/versions/0", user)
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2016-09-29 09:46:39 +05:30
end
2017-08-17 22:00:37 +05:30
it 'returns a 404 when merge_request_iid is not found' do
2020-04-22 19:07:51 +05:30
get api("/projects/#{project.id}/merge_requests/#{non_existing_record_iid}/versions/#{merge_request_diff.id}", user)
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2016-09-29 09:46:39 +05:30
end
2021-02-11 23:33:58 +05:30
context 'when merge request author has only guest access' do
it_behaves_like 'rejects user from accessing merge request info' do
let(:url) { "/projects/#{project.id}/merge_requests/#{merge_request.iid}/versions/#{merge_request_diff.id}" }
end
end
2021-04-29 21:17:54 +05:30
context 'caching merge request diffs', :use_clean_rails_redis_caching do
it 'is performed' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/versions/#{merge_request_diff.id}", user)
expect(Rails.cache.fetch(merge_request_diff.cache_key)).to be_present
end
end
2016-09-29 09:46:39 +05:30
end
end