2016-08-03 04:32:29 -04:00
|
|
|
require "spec_helper"
|
|
|
|
|
2017-04-21 16:32:02 -04:00
|
|
|
describe API::MergeRequestDiffs, 'MergeRequestDiffs' do
|
2016-08-03 04:32:29 -04:00
|
|
|
let!(:user) { create(:user) }
|
|
|
|
let!(:merge_request) { create(:merge_request, importing: true) }
|
|
|
|
let!(:project) { merge_request.target_project }
|
|
|
|
|
|
|
|
before do
|
|
|
|
merge_request.merge_request_diffs.create(head_commit_sha: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9')
|
|
|
|
merge_request.merge_request_diffs.create(head_commit_sha: '5937ac0a7beb003549fc5fd26fc247adbce4a52e')
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_master(user)
|
2016-08-03 04:32:29 -04:00
|
|
|
end
|
|
|
|
|
2017-02-28 00:26:09 -05:00
|
|
|
describe 'GET /projects/:id/merge_requests/:merge_request_iid/versions' do
|
2016-10-19 08:25:37 -04:00
|
|
|
it 'returns 200 for a valid merge request' do
|
2017-02-28 00:26:09 -05:00
|
|
|
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/versions", user)
|
2017-08-15 06:27:37 -04:00
|
|
|
merge_request_diff = merge_request.merge_request_diffs.last
|
2016-10-19 08:25:37 -04:00
|
|
|
|
|
|
|
expect(response.status).to eq 200
|
2017-01-24 15:49:10 -05:00
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
expect(json_response).to be_an Array
|
2016-10-19 08:25:37 -04:00
|
|
|
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)
|
2016-08-03 04:32:29 -04:00
|
|
|
end
|
|
|
|
|
2017-02-28 00:26:09 -05:00
|
|
|
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)
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2017-02-28 00:26:09 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a 404 when merge_request_iid not found' do
|
2016-08-03 04:32:29 -04:00
|
|
|
get api("/projects/#{project.id}/merge_requests/999/versions", user)
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-08-03 04:32:29 -04:00
|
|
|
end
|
|
|
|
end
|
2016-08-12 07:44:49 -04:00
|
|
|
|
2017-02-28 00:26:09 -05:00
|
|
|
describe 'GET /projects/:id/merge_requests/:merge_request_iid/versions/:version_id' do
|
|
|
|
let(:merge_request_diff) { merge_request.merge_request_diffs.first }
|
|
|
|
|
2016-10-19 08:25:37 -04:00
|
|
|
it 'returns a 200 for a valid merge request' do
|
2017-02-28 00:26:09 -05:00
|
|
|
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/versions/#{merge_request_diff.id}", user)
|
2016-10-19 08:25:37 -04:00
|
|
|
|
|
|
|
expect(response.status).to eq 200
|
|
|
|
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)
|
2016-08-12 07:44:49 -04:00
|
|
|
end
|
|
|
|
|
2017-02-28 00:26:09 -05:00
|
|
|
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)
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2017-02-28 00:26:09 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a 404 when merge_request version_id is not found' do
|
|
|
|
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/versions/999", user)
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2017-02-28 00:26:09 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a 404 when merge_request_iid is not found' do
|
|
|
|
get api("/projects/#{project.id}/merge_requests/12345/versions/#{merge_request_diff.id}", user)
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-08-12 07:44:49 -04:00
|
|
|
end
|
|
|
|
end
|
2016-08-03 04:32:29 -04:00
|
|
|
end
|