summaryrefslogtreecommitdiff
path: root/spec/controllers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-09 12:09:24 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-09 12:09:24 +0000
commita9ced7da447785c57477b3d8dbccc73a78cface1 (patch)
tree5179d27ab9d801748ee4ed1c64c985974e799812 /spec/controllers
parentad0265eead72a624ce7a020847db4f0f0c877e57 (diff)
downloadgitlab-ce-a9ced7da447785c57477b3d8dbccc73a78cface1.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/controllers')
-rw-r--r--spec/controllers/groups_controller_spec.rb130
-rw-r--r--spec/controllers/projects/import/jira_controller_spec.rb48
2 files changed, 143 insertions, 35 deletions
diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb
index 7bd0f6bd6b8..93478bbff1d 100644
--- a/spec/controllers/groups_controller_spec.rb
+++ b/spec/controllers/groups_controller_spec.rb
@@ -764,6 +764,136 @@ describe GroupsController do
end
end
+ describe 'POST #export' do
+ context 'when the group export feature flag is not enabled' do
+ before do
+ sign_in(admin)
+ stub_feature_flags(group_import_export: false)
+ end
+
+ it 'returns a not found error' do
+ post :export, params: { id: group.to_param }
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+ end
+
+ context 'when the user does not have permission to export the group' do
+ before do
+ sign_in(guest)
+ end
+
+ it 'returns an error' do
+ post :export, params: { id: group.to_param }
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+ end
+
+ context 'when supplied valid params' do
+ before do
+ sign_in(admin)
+ end
+
+ it 'triggers the export job' do
+ expect(GroupExportWorker).to receive(:perform_async).with(admin.id, group.id, {})
+
+ post :export, params: { id: group.to_param }
+ end
+
+ it 'redirects to the edit page' do
+ post :export, params: { id: group.to_param }
+
+ expect(response).to have_gitlab_http_status(:found)
+ end
+ end
+
+ context 'when the endpoint receives requests above the rate limit' do
+ before do
+ sign_in(admin)
+ allow(Gitlab::ApplicationRateLimiter).to receive(:throttled?).and_return(true)
+ end
+
+ it 'throttles the endpoint' do
+ post :export, params: { id: group.to_param }
+
+ expect(flash[:alert]).to eq('This endpoint has been requested too many times. Try again later.')
+ expect(response).to have_gitlab_http_status(:found)
+ end
+ end
+ end
+
+ describe 'GET #download_export' do
+ context 'when there is a file available to download' do
+ let(:export_file) { fixture_file_upload('spec/fixtures/group_export.tar.gz') }
+
+ before do
+ sign_in(admin)
+ create(:import_export_upload, group: group, export_file: export_file)
+ end
+
+ it 'sends the file' do
+ get :download_export, params: { id: group.to_param }
+
+ expect(response.body).to eq export_file.tempfile.read
+ end
+ end
+
+ context 'when there is no file available to download' do
+ before do
+ sign_in(admin)
+ end
+
+ it 'returns not found' do
+ get :download_export, params: { id: group.to_param }
+
+ expect(flash[:alert])
+ .to eq 'Group export link has expired. Please generate a new export from your group settings.'
+
+ expect(response).to redirect_to(edit_group_path(group))
+ end
+ end
+
+ context 'when the group export feature flag is not enabled' do
+ before do
+ sign_in(admin)
+ stub_feature_flags(group_import_export: false)
+ end
+
+ it 'returns a not found error' do
+ post :export, params: { id: group.to_param }
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+ end
+
+ context 'when the user does not have the required permissions' do
+ before do
+ sign_in(guest)
+ end
+
+ it 'returns not_found' do
+ get :download_export, params: { id: group.to_param }
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+ end
+
+ context 'when the endpoint receives requests above the rate limit' do
+ before do
+ sign_in(admin)
+ allow(Gitlab::ApplicationRateLimiter).to receive(:throttled?).and_return(true)
+ end
+
+ it 'throttles the endpoint' do
+ get :download_export, params: { id: group.to_param }
+
+ expect(flash[:alert]).to eq('This endpoint has been requested too many times. Try again later.')
+ expect(response).to have_gitlab_http_status(:found)
+ end
+ end
+ end
+
context 'token authentication' do
it_behaves_like 'authenticates sessionless user', :show, :atom, public: true do
before do
diff --git a/spec/controllers/projects/import/jira_controller_spec.rb b/spec/controllers/projects/import/jira_controller_spec.rb
index 57e0aa098c0..8e0d506e5e4 100644
--- a/spec/controllers/projects/import/jira_controller_spec.rb
+++ b/spec/controllers/projects/import/jira_controller_spec.rb
@@ -105,16 +105,16 @@ describe Projects::Import::JiraController do
context 'when everything is ok' do
it 'creates import state' do
- expect(project.import_state).to be_nil
+ expect(project.latest_jira_import).to be_nil
post :import, params: { namespace_id: project.namespace, project_id: project, jira_project_key: 'Test' }
project.reload
- jira_project = project.import_data.data.dig('jira', 'projects').first
+ jira_import = project.latest_jira_import
expect(project.import_type).to eq 'jira'
- expect(project.import_state.status).to eq 'scheduled'
- expect(jira_project['key']).to eq 'Test'
+ expect(jira_import.status).to eq 'scheduled'
+ expect(jira_import.jira_project_key).to eq 'Test'
expect(response).to redirect_to(project_import_jira_path(project))
end
end
@@ -122,29 +122,19 @@ describe Projects::Import::JiraController do
end
context 'when import state is scheduled' do
- let_it_be(:import_state) { create(:import_state, project: project, status: :scheduled) }
+ let_it_be(:jira_import_state) { create(:jira_import_state, :scheduled, project: project) }
context 'get show' do
it 'renders import status' do
get :show, params: { namespace_id: project.namespace.to_param, project_id: project }
- expect(project.import_state.status).to eq 'scheduled'
+ jira_import = project.latest_jira_import
+ expect(jira_import.status).to eq 'scheduled'
expect(flash.now[:notice]).to eq 'Import scheduled'
end
end
context 'post import' do
- before do
- project.reload
- project.create_import_data(
- data: {
- 'jira': {
- 'projects': [{ 'key': 'Test', scheduled_at: 5.days.ago, scheduled_by: { user_id: user.id, name: user.name } }]
- }
- }
- )
- end
-
it 'uses the existing import data' do
post :import, params: { namespace_id: project.namespace, project_id: project, jira_project_key: 'New Project' }
@@ -155,39 +145,27 @@ describe Projects::Import::JiraController do
end
context 'when jira import ran before' do
- let_it_be(:import_state) { create(:import_state, project: project, status: :finished) }
+ let_it_be(:jira_import_state) { create(:jira_import_state, :finished, project: project, jira_project_key: 'Test') }
context 'get show' do
it 'renders import status' do
allow(JIRA::Resource::Project).to receive(:all).and_return([])
get :show, params: { namespace_id: project.namespace.to_param, project_id: project }
- expect(project.import_state.status).to eq 'finished'
+ expect(project.latest_jira_import.status).to eq 'finished'
expect(flash.now[:notice]).to eq 'Import finished'
end
end
context 'post import' do
- before do
- project.reload
- project.create_import_data(
- data: {
- 'jira': {
- 'projects': [{ 'key': 'Test', scheduled_at: 5.days.ago, scheduled_by: { user_id: user.id, name: user.name } }]
- }
- }
- )
- end
-
it 'uses the existing import data' do
post :import, params: { namespace_id: project.namespace, project_id: project, jira_project_key: 'New Project' }
project.reload
- expect(project.import_state.status).to eq 'scheduled'
- jira_imported_projects = project.import_data.data.dig('jira', 'projects')
- expect(jira_imported_projects.size).to eq 2
- expect(jira_imported_projects.first['key']).to eq 'Test'
- expect(jira_imported_projects.last['key']).to eq 'New Project'
+ expect(project.latest_jira_import.status).to eq 'scheduled'
+ expect(project.jira_imports.size).to eq 2
+ expect(project.jira_imports.first.jira_project_key).to eq 'Test'
+ expect(project.jira_imports.last.jira_project_key).to eq 'New Project'
expect(response).to redirect_to(project_import_jira_path(project))
end
end