2013-05-23 05:23:47 -04:00
|
|
|
require 'spec_helper'
|
2013-12-20 14:12:44 -05:00
|
|
|
require 'mime/types'
|
2013-05-23 05:23:47 -04:00
|
|
|
|
2014-04-11 15:45:56 -04:00
|
|
|
describe API::API, api: true do
|
2013-05-23 05:23:47 -04:00
|
|
|
include ApiHelpers
|
2014-08-01 08:41:02 -04:00
|
|
|
include RepoHelpers
|
2016-02-11 12:10:14 -05:00
|
|
|
include WorkhorseHelpers
|
2014-08-01 08:41:02 -04:00
|
|
|
|
2013-05-23 05:23:47 -04:00
|
|
|
let(:user) { create(:user) }
|
2013-05-23 05:26:06 -04:00
|
|
|
let(:user2) { create(:user) }
|
2014-01-22 14:03:52 -05:00
|
|
|
let!(:project) { create(:project, creator_id: user.id) }
|
2016-03-06 16:53:22 -05:00
|
|
|
let!(:master) { create(:project_member, :master, user: user, project: project) }
|
|
|
|
let!(:guest) { create(:project_member, :guest, user: user2, project: project) }
|
2013-05-23 05:23:47 -04:00
|
|
|
|
2013-06-06 11:01:03 -04:00
|
|
|
describe "GET /projects/:id/repository/tree" do
|
|
|
|
context "authorized user" do
|
|
|
|
before { project.team << [user2, :reporter] }
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "returns project commits" do
|
2013-06-06 11:01:03 -04:00
|
|
|
get api("/projects/#{project.id}/repository/tree", user)
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2013-06-06 11:01:03 -04:00
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.first['name']).to eq('encoding')
|
|
|
|
expect(json_response.first['type']).to eq('tree')
|
|
|
|
expect(json_response.first['mode']).to eq('040000')
|
2013-06-06 11:01:03 -04:00
|
|
|
end
|
2015-01-18 16:17:10 -05:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns a 404 for unknown ref' do
|
2015-01-18 16:17:10 -05:00
|
|
|
get api("/projects/#{project.id}/repository/tree?ref_name=foo", user)
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2015-01-18 16:17:10 -05:00
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response).to be_an Object
|
2015-01-18 16:17:10 -05:00
|
|
|
json_response['message'] == '404 Tree Not Found'
|
|
|
|
end
|
2013-06-06 11:01:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "unauthorized user" do
|
2016-08-01 11:00:44 -04:00
|
|
|
it "does not return project commits" do
|
2013-06-06 11:01:03 -04:00
|
|
|
get api("/projects/#{project.id}/repository/tree")
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(401)
|
2013-06-06 11:01:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-27 21:22:42 -04:00
|
|
|
describe "GET /projects/:id/repository/blobs/:sha" do
|
2016-08-01 11:00:44 -04:00
|
|
|
it "gets the raw file contents" do
|
2013-08-27 21:22:42 -04:00
|
|
|
get api("/projects/#{project.id}/repository/blobs/master?filepath=README.md", user)
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2013-05-23 05:23:47 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "returns 404 for invalid branch_name" do
|
2013-08-27 21:22:42 -04:00
|
|
|
get api("/projects/#{project.id}/repository/blobs/invalid_branch_name?filepath=README.md", user)
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2013-05-23 05:23:47 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "returns 404 for invalid file" do
|
2013-08-27 21:22:42 -04:00
|
|
|
get api("/projects/#{project.id}/repository/blobs/master?filepath=README.invalid", user)
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2013-05-23 05:23:47 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "returns a 400 error if filepath is missing" do
|
2013-08-27 21:22:42 -04:00
|
|
|
get api("/projects/#{project.id}/repository/blobs/master", user)
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(400)
|
2013-05-23 05:23:47 -04:00
|
|
|
end
|
|
|
|
end
|
2013-08-27 21:22:42 -04:00
|
|
|
|
|
|
|
describe "GET /projects/:id/repository/commits/:sha/blob" do
|
2016-08-01 11:00:44 -04:00
|
|
|
it "gets the raw file contents" do
|
2013-08-27 21:22:42 -04:00
|
|
|
get api("/projects/#{project.id}/repository/commits/master/blob?filepath=README.md", user)
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2013-08-27 21:22:42 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-12-23 04:37:38 -05:00
|
|
|
describe "GET /projects/:id/repository/raw_blobs/:sha" do
|
2016-08-01 11:00:44 -04:00
|
|
|
it "gets the raw file contents" do
|
2014-08-01 08:41:02 -04:00
|
|
|
get api("/projects/#{project.id}/repository/raw_blobs/#{sample_blob.oid}", user)
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2013-12-23 04:37:38 -05:00
|
|
|
end
|
2015-01-18 16:17:10 -05:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns a 404 for unknown blob' do
|
2015-01-18 16:17:10 -05:00
|
|
|
get api("/projects/#{project.id}/repository/raw_blobs/123456", user)
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2015-01-18 16:17:10 -05:00
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response).to be_an Object
|
2015-01-18 16:17:10 -05:00
|
|
|
json_response['message'] == '404 Blob Not Found'
|
|
|
|
end
|
2013-12-23 04:37:38 -05:00
|
|
|
end
|
|
|
|
|
2013-12-20 14:12:44 -05:00
|
|
|
describe "GET /projects/:id/repository/archive(.:format)?:sha" do
|
2016-08-01 11:00:44 -04:00
|
|
|
it "gets the archive" do
|
2013-09-26 16:42:49 -04:00
|
|
|
get api("/projects/#{project.id}/repository/archive", user)
|
2013-12-20 14:12:44 -05:00
|
|
|
repo_name = project.repository.name.gsub("\.git", "")
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2016-02-11 12:10:14 -05:00
|
|
|
type, params = workhorse_send_data
|
|
|
|
expect(type).to eq('git-archive')
|
|
|
|
expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.tar.gz/)
|
2013-12-20 14:12:44 -05:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "gets the archive.zip" do
|
2013-12-20 14:12:44 -05:00
|
|
|
get api("/projects/#{project.id}/repository/archive.zip", user)
|
|
|
|
repo_name = project.repository.name.gsub("\.git", "")
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2016-02-11 12:10:14 -05:00
|
|
|
type, params = workhorse_send_data
|
|
|
|
expect(type).to eq('git-archive')
|
|
|
|
expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.zip/)
|
2013-12-20 14:12:44 -05:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "gets the archive.tar.bz2" do
|
2013-12-20 14:12:44 -05:00
|
|
|
get api("/projects/#{project.id}/repository/archive.tar.bz2", user)
|
|
|
|
repo_name = project.repository.name.gsub("\.git", "")
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2016-02-11 12:10:14 -05:00
|
|
|
type, params = workhorse_send_data
|
|
|
|
expect(type).to eq('git-archive')
|
|
|
|
expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.tar.bz2/)
|
2013-09-26 16:42:49 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "returns 404 for invalid sha" do
|
2013-09-26 16:42:49 -04:00
|
|
|
get api("/projects/#{project.id}/repository/archive/?sha=xxx", user)
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2013-09-26 16:42:49 -04:00
|
|
|
end
|
|
|
|
end
|
2014-05-26 11:05:55 -04:00
|
|
|
|
2014-07-02 05:40:20 -04:00
|
|
|
describe 'GET /projects/:id/repository/compare' do
|
2016-08-01 11:00:44 -04:00
|
|
|
it "compares branches" do
|
2014-08-01 08:41:02 -04:00
|
|
|
get api("/projects/#{project.id}/repository/compare", user), from: 'master', to: 'feature'
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response['commits']).to be_present
|
|
|
|
expect(json_response['diffs']).to be_present
|
2014-05-26 11:05:55 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "compares tags" do
|
2014-08-01 08:41:02 -04:00
|
|
|
get api("/projects/#{project.id}/repository/compare", user), from: 'v1.0.0', to: 'v1.1.0'
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response['commits']).to be_present
|
|
|
|
expect(json_response['diffs']).to be_present
|
2014-05-27 04:27:42 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "compares commits" do
|
2014-08-01 08:41:02 -04:00
|
|
|
get api("/projects/#{project.id}/repository/compare", user), from: sample_commit.id, to: sample_commit.parent_id
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response['commits']).to be_empty
|
|
|
|
expect(json_response['diffs']).to be_empty
|
|
|
|
expect(json_response['compare_same_ref']).to be_falsey
|
2014-05-26 11:05:55 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "compares commits in reverse order" do
|
2014-08-01 08:41:02 -04:00
|
|
|
get api("/projects/#{project.id}/repository/compare", user), from: sample_commit.parent_id, to: sample_commit.id
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response['commits']).to be_present
|
|
|
|
expect(json_response['diffs']).to be_present
|
2014-05-27 04:27:42 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "compares same refs" do
|
2014-05-27 04:27:42 -04:00
|
|
|
get api("/projects/#{project.id}/repository/compare", user), from: 'master', to: 'master'
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response['commits']).to be_empty
|
|
|
|
expect(json_response['diffs']).to be_empty
|
|
|
|
expect(json_response['compare_same_ref']).to be_truthy
|
2014-05-26 11:05:55 -04:00
|
|
|
end
|
|
|
|
end
|
2014-07-02 05:40:20 -04:00
|
|
|
|
|
|
|
describe 'GET /projects/:id/repository/contributors' do
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns valid data' do
|
2014-07-02 05:40:20 -04:00
|
|
|
get api("/projects/#{project.id}/repository/contributors", user)
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response).to be_an Array
|
2014-07-02 07:43:23 -04:00
|
|
|
contributor = json_response.first
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(contributor['email']).to eq('dmitriy.zaporozhets@gmail.com')
|
|
|
|
expect(contributor['name']).to eq('Dmitriy Zaporozhets')
|
|
|
|
expect(contributor['commits']).to eq(13)
|
|
|
|
expect(contributor['additions']).to eq(0)
|
|
|
|
expect(contributor['deletions']).to eq(0)
|
2014-07-02 05:40:20 -04:00
|
|
|
end
|
|
|
|
end
|
2013-05-23 05:23:47 -04:00
|
|
|
end
|