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

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

100 lines
3 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe API::Submodules, feature_category: :source_code_management do
2018-12-13 13:39:08 +05:30
let(:user) { create(:user) }
2023-01-13 00:05:48 +05:30
let!(:project) { create(:project, :repository, namespace: user.namespace) }
2018-12-13 13:39:08 +05:30
let(:guest) { create(:user) { |u| project.add_guest(u) } }
let(:submodule) { 'six' }
let(:commit_sha) { 'e25eda1fece24ac7a03624ed1320f82396f35bd8' }
let(:branch) { 'master' }
let(:commit_message) { 'whatever' }
let(:params) do
{
submodule: submodule,
commit_sha: commit_sha,
branch: branch,
commit_message: commit_message
}
end
before do
project.add_developer(user)
end
def route(submodule = nil)
"/projects/#{project.id}/repository/submodules/#{submodule}"
end
describe "PUT /projects/:id/repository/submodule/:submodule" do
context 'when unauthenticated' do
it 'returns 401' do
2019-02-15 15:39:39 +05:30
put api(route(submodule)), params: params
2018-12-13 13:39:08 +05:30
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:unauthorized)
2018-12-13 13:39:08 +05:30
end
end
context 'when authenticated', 'as a guest' do
it 'returns 403' do
2019-02-15 15:39:39 +05:30
put api(route(submodule), guest), params: params
2018-12-13 13:39:08 +05:30
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:forbidden)
2018-12-13 13:39:08 +05:30
end
end
context 'when authenticated', 'as a developer' do
it 'returns 400 if params is missing' do
put api(route(submodule), user)
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:bad_request)
2018-12-13 13:39:08 +05:30
end
it 'returns 400 if branch is missing' do
2019-02-15 15:39:39 +05:30
put api(route(submodule), user), params: params.except(:branch)
2018-12-13 13:39:08 +05:30
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:bad_request)
2018-12-13 13:39:08 +05:30
end
it 'returns 400 if commit_sha is missing' do
2019-02-15 15:39:39 +05:30
put api(route(submodule), user), params: params.except(:commit_sha)
2018-12-13 13:39:08 +05:30
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:bad_request)
2018-12-13 13:39:08 +05:30
end
2019-03-02 22:35:43 +05:30
it 'returns the commit' do
2018-12-13 13:39:08 +05:30
head_commit = project.repository.commit.id
2019-02-15 15:39:39 +05:30
put api(route(submodule), user), params: params
2018-12-13 13:39:08 +05:30
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:ok)
2018-12-13 13:39:08 +05:30
expect(json_response['message']).to eq commit_message
expect(json_response['author_name']).to eq user.name
expect(json_response['committer_name']).to eq user.name
expect(json_response['parent_ids'].first).to eq head_commit
end
context 'when the submodule name is urlencoded' do
let(:submodule) { 'test_inside_folder/another_folder/six' }
let(:branch) { 'submodule_inside_folder' }
let(:encoded_submodule) { CGI.escape(submodule) }
2019-03-02 22:35:43 +05:30
it 'returns the commit' do
2018-12-13 13:39:08 +05:30
expect(Submodules::UpdateService)
.to receive(:new)
.with(any_args, hash_including(submodule: submodule))
.and_call_original
2019-02-15 15:39:39 +05:30
put api(route(encoded_submodule), user), params: params
2018-12-13 13:39:08 +05:30
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:ok)
2018-12-13 13:39:08 +05:30
expect(json_response['id']).to eq project.repository.commit(branch).id
expect(project.repository.blob_at(branch, submodule).id).to eq commit_sha
end
end
end
end
end