summaryrefslogtreecommitdiff
path: root/spec/requests
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-31 15:07:53 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-31 15:07:53 +0000
commitd7a028e20d29b8c6d0e780ac168544dfbb712d3c (patch)
treef9fc9ea12e166aec6c4ffe476ba7a3566396b696 /spec/requests
parent0d0cddc9ce20c5a7d8a2723d0aa620ca184a711a (diff)
downloadgitlab-ce-d7a028e20d29b8c6d0e780ac168544dfbb712d3c.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r--spec/requests/api/graphql/mutations/jira_import/start_spec.rb130
-rw-r--r--spec/requests/api/project_clusters_spec.rb80
2 files changed, 156 insertions, 54 deletions
diff --git a/spec/requests/api/graphql/mutations/jira_import/start_spec.rb b/spec/requests/api/graphql/mutations/jira_import/start_spec.rb
new file mode 100644
index 00000000000..3eb2ca6909b
--- /dev/null
+++ b/spec/requests/api/graphql/mutations/jira_import/start_spec.rb
@@ -0,0 +1,130 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe 'Starting a Jira Import' do
+ include GraphqlHelpers
+
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project, reload: true) { create(:project) }
+ let(:jira_project_key) { 'AA' }
+ let(:project_path) { project.full_path }
+
+ let(:mutation) do
+ variables = {
+ jira_project_key: jira_project_key,
+ project_path: project_path
+ }
+
+ graphql_mutation(:jira_import_start, variables)
+ end
+
+ def mutation_response
+ graphql_mutation_response(:jira_import_start)
+ end
+
+ def jira_import
+ mutation_response['jiraImport']
+ end
+
+ context 'when the user does not have permission' do
+ before do
+ stub_feature_flags(jira_issue_import: true)
+ end
+
+ shared_examples 'Jira import does not start' do
+ it 'does not start the Jira import' do
+ post_graphql_mutation(mutation, current_user: current_user)
+
+ expect(project.reload.import_state).to be nil
+ expect(project.reload.import_data).to be nil
+ end
+ end
+
+ context 'with anonymous user' do
+ let(:current_user) { nil }
+
+ it_behaves_like 'Jira import does not start'
+ it_behaves_like 'a mutation that returns top-level errors',
+ errors: [Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR]
+ end
+
+ context 'with user without permissions' do
+ let(:current_user) { user }
+ let(:project_path) { project.full_path }
+
+ before do
+ project.add_developer(current_user)
+ end
+
+ it_behaves_like 'Jira import does not start'
+ it_behaves_like 'a mutation that returns top-level errors',
+ errors: [Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR]
+ end
+ end
+
+ context 'when the user has permission' do
+ let(:current_user) { user }
+
+ before do
+ project.add_maintainer(current_user)
+ end
+
+ context 'with project' do
+ context 'when the project path is invalid' do
+ let(:project_path) { 'foobar' }
+
+ it 'returns an an error' do
+ post_graphql_mutation(mutation, current_user: current_user)
+ errors = json_response['errors']
+
+ expect(errors.first['message']).to eq(Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR)
+ end
+ end
+
+ context 'when feature jira_issue_import feature flag is disabled' do
+ before do
+ stub_feature_flags(jira_issue_import: false)
+ end
+
+ it_behaves_like 'a mutation that returns errors in the response', errors: ['Jira import feature is disabled.']
+ end
+
+ context 'when feature jira_issue_import feature flag is enabled' do
+ before do
+ stub_feature_flags(jira_issue_import: true)
+ end
+
+ context 'when project has no Jira service' do
+ it_behaves_like 'a mutation that returns errors in the response', errors: ['Jira integration not configured.']
+ end
+
+ context 'when when project has Jira service' do
+ let!(:service) { create(:jira_service, project: project) }
+
+ before do
+ project.reload
+ end
+
+ context 'when jira_project_key not provided' do
+ let(:jira_project_key) { '' }
+
+ it_behaves_like 'a mutation that returns errors in the response', errors: ['Unable to find Jira project to import data from.']
+ end
+
+ context 'when jira import successfully scheduled' do
+ it 'schedules a Jira import' do
+ post_graphql_mutation(mutation, current_user: current_user)
+
+ expect(jira_import['jiraProjectKey']).to eq 'AA'
+ expect(jira_import['scheduledBy']['username']).to eq current_user.username
+ expect(project.import_state).not_to be nil
+ expect(project.import_state.status).to eq 'scheduled'
+ expect(project.import_data.becomes(JiraImportData).projects.last.scheduled_by['user_id']).to eq current_user.id
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/requests/api/project_clusters_spec.rb b/spec/requests/api/project_clusters_spec.rb
index 7cef40ff3b5..648577dce8d 100644
--- a/spec/requests/api/project_clusters_spec.rb
+++ b/spec/requests/api/project_clusters_spec.rb
@@ -5,9 +5,9 @@ require 'spec_helper'
describe API::ProjectClusters do
include KubernetesHelpers
- let(:current_user) { create(:user) }
- let(:developer_user) { create(:user) }
- let(:project) { create(:project) }
+ let_it_be(:current_user) { create(:user) }
+ let_it_be(:developer_user) { create(:user) }
+ let_it_be(:project) { create(:project) }
before do
project.add_maintainer(current_user)
@@ -15,10 +15,10 @@ describe API::ProjectClusters do
end
describe 'GET /projects/:id/clusters' do
- let!(:extra_cluster) { create(:cluster, :provided_by_gcp, :project) }
+ let_it_be(:extra_cluster) { create(:cluster, :provided_by_gcp, :project) }
- let!(:clusters) do
- create_list(:cluster, 5, :provided_by_gcp, :project, :production_environment,
+ let_it_be(:clusters) do
+ create_list(:cluster, 2, :provided_by_gcp, :project, :production_environment,
projects: [project])
end
@@ -35,17 +35,15 @@ describe API::ProjectClusters do
get api("/projects/#{project.id}/clusters", current_user)
end
- it 'responds with 200' do
- expect(response).to have_gitlab_http_status(:ok)
- end
-
it 'includes pagination headers' do
+ expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers
end
it 'onlies include authorized clusters' do
cluster_ids = json_response.map { |cluster| cluster['id'] }
+ expect(response).to have_gitlab_http_status(:ok)
expect(cluster_ids).to match_array(clusters.pluck(:id))
expect(cluster_ids).not_to include(extra_cluster.id)
end
@@ -139,7 +137,7 @@ describe API::ProjectClusters do
end
context 'with non-existing cluster' do
- let(:cluster_id) { 123 }
+ let(:cluster_id) { 0 }
it 'returns 404' do
expect(response).to have_gitlab_http_status(:not_found)
@@ -185,14 +183,11 @@ describe API::ProjectClusters do
end
context 'with valid params' do
- it 'responds with 201' do
- expect(response).to have_gitlab_http_status(:created)
- end
-
it 'creates a new Cluster::Cluster' do
cluster_result = Clusters::Cluster.find(json_response["id"])
platform_kubernetes = cluster_result.platform
+ expect(response).to have_gitlab_http_status(:created)
expect(cluster_result).to be_user
expect(cluster_result).to be_kubernetes
expect(cluster_result.project).to eq(project)
@@ -235,15 +230,9 @@ describe API::ProjectClusters do
context 'with invalid params' do
let(:namespace) { 'invalid_namespace' }
- it 'responds with 400' do
- expect(response).to have_gitlab_http_status(:bad_request)
- end
-
it 'does not create a new Clusters::Cluster' do
+ expect(response).to have_gitlab_http_status(:bad_request)
expect(project.reload.clusters).to be_empty
- end
-
- it 'returns validation errors' do
expect(json_response['message']['platform_kubernetes.namespace'].first).to be_present
end
end
@@ -259,8 +248,8 @@ describe API::ProjectClusters do
it 'responds with 400' do
expect(response).to have_gitlab_http_status(:bad_request)
-
- expect(json_response['message']['base'].first).to eq(_('Instance does not support multiple Kubernetes clusters'))
+ expect(json_response['message']['base'].first)
+ .to eq(_('Instance does not support multiple Kubernetes clusters'))
end
end
@@ -271,7 +260,6 @@ describe API::ProjectClusters do
it 'responds with 403' do
expect(response).to have_gitlab_http_status(:forbidden)
-
expect(json_response['message']).to eq('403 Forbidden')
end
end
@@ -281,7 +269,7 @@ describe API::ProjectClusters do
let(:api_url) { 'https://kubernetes.example.com' }
let(:namespace) { 'new-namespace' }
let(:platform_kubernetes_attributes) { { namespace: namespace } }
- let(:management_project) { create(:project, namespace: project.namespace) }
+ let_it_be(:management_project) { create(:project, namespace: project.namespace) }
let(:management_project_id) { management_project.id }
let(:update_params) do
@@ -321,11 +309,8 @@ describe API::ProjectClusters do
end
context 'with valid params' do
- it 'responds with 200' do
- expect(response).to have_gitlab_http_status(:ok)
- end
-
it 'updates cluster attributes' do
+ expect(response).to have_gitlab_http_status(:ok)
expect(cluster.domain).to eq('new-domain.com')
expect(cluster.platform_kubernetes.namespace).to eq('new-namespace')
expect(cluster.management_project).to eq(management_project)
@@ -335,29 +320,24 @@ describe API::ProjectClusters do
context 'with invalid params' do
let(:namespace) { 'invalid_namespace' }
- it 'responds with 400' do
- expect(response).to have_gitlab_http_status(:bad_request)
- end
-
it 'does not update cluster attributes' do
+ expect(response).to have_gitlab_http_status(:bad_request)
expect(cluster.domain).not_to eq('new_domain.com')
expect(cluster.platform_kubernetes.namespace).not_to eq('invalid_namespace')
expect(cluster.management_project).not_to eq(management_project)
end
it 'returns validation errors' do
- expect(json_response['message']['platform_kubernetes.namespace'].first).to match('can contain only lowercase letters')
+ expect(json_response['message']['platform_kubernetes.namespace'].first)
+ .to match('can contain only lowercase letters')
end
end
context 'current user does not have access to management_project_id' do
- let(:management_project_id) { create(:project).id }
-
- it 'responds with 400' do
- expect(response).to have_gitlab_http_status(:bad_request)
- end
+ let_it_be(:management_project_id) { create(:project).id }
it 'returns validation errors' do
+ expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']['management_project_id'].first).to match('don\'t have permission')
end
end
@@ -371,12 +351,10 @@ describe API::ProjectClusters do
}
end
- it 'responds with 400' do
- expect(response).to have_gitlab_http_status(:bad_request)
- end
-
it 'returns validation error' do
- expect(json_response['message']['platform_kubernetes.base'].first).to eq(_('Cannot modify managed Kubernetes cluster'))
+ expect(response).to have_gitlab_http_status(:bad_request)
+ expect(json_response['message']['platform_kubernetes.base'].first)
+ .to eq(_('Cannot modify managed Kubernetes cluster'))
end
end
@@ -412,13 +390,10 @@ describe API::ProjectClusters do
}
end
- it 'responds with 200' do
- expect(response).to have_gitlab_http_status(:ok)
- end
-
it 'updates platform kubernetes attributes' do
platform_kubernetes = cluster.platform_kubernetes
+ expect(response).to have_gitlab_http_status(:ok)
expect(cluster.name).to eq('new-name')
expect(platform_kubernetes.namespace).to eq('new-namespace')
expect(platform_kubernetes.api_url).to eq('https://new-api-url.com')
@@ -439,7 +414,7 @@ describe API::ProjectClusters do
describe 'DELETE /projects/:id/clusters/:cluster_id' do
let(:cluster_params) { { cluster_id: cluster.id } }
- let(:cluster) do
+ let_it_be(:cluster) do
create(:cluster, :project, :provided_by_gcp,
projects: [project])
end
@@ -457,11 +432,8 @@ describe API::ProjectClusters do
delete api("/projects/#{project.id}/clusters/#{cluster.id}", current_user), params: cluster_params
end
- it 'responds with 204' do
- expect(response).to have_gitlab_http_status(:no_content)
- end
-
it 'deletes the cluster' do
+ expect(response).to have_gitlab_http_status(:no_content)
expect(Clusters::Cluster.exists?(id: cluster.id)).to be_falsy
end