Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-06-20 13:43:29 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-06-20 13:43:29 +0300
commit3b1af5cc7ed2666ff18b718ce5d30fa5a2756674 (patch)
tree3bc4a40e0ee51ec27eabf917c537033c0c5b14d4 /spec/requests/api/graphql/mutations/environments
parent9bba14be3f2c211bf79e15769cd9b77bc73a13bc (diff)
Add latest changes from gitlab-org/gitlab@16-1-stable-eev16.1.0-rc42
Diffstat (limited to 'spec/requests/api/graphql/mutations/environments')
-rw-r--r--spec/requests/api/graphql/mutations/environments/create_spec.rb60
-rw-r--r--spec/requests/api/graphql/mutations/environments/delete_spec.rb33
-rw-r--r--spec/requests/api/graphql/mutations/environments/update_spec.rb70
3 files changed, 163 insertions, 0 deletions
diff --git a/spec/requests/api/graphql/mutations/environments/create_spec.rb b/spec/requests/api/graphql/mutations/environments/create_spec.rb
new file mode 100644
index 00000000000..8a67f86dc4b
--- /dev/null
+++ b/spec/requests/api/graphql/mutations/environments/create_spec.rb
@@ -0,0 +1,60 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe 'Create Environment', feature_category: :environment_management do
+ include GraphqlHelpers
+
+ let_it_be(:project) { create(:project, :repository) }
+ let_it_be(:developer) { create(:user).tap { |u| project.add_maintainer(u) } }
+ let_it_be(:reporter) { create(:user).tap { |u| project.add_reporter(u) } }
+
+ let(:current_user) { developer }
+
+ let(:mutation) do
+ graphql_mutation(:environment_create, input)
+ end
+
+ context 'when creating an environment' do
+ let(:input) do
+ {
+ project_path: project.full_path,
+ name: 'production',
+ external_url: 'https://gitlab.com/'
+ }
+ end
+
+ it 'creates successfully' do
+ post_graphql_mutation(mutation, current_user: current_user)
+
+ expect(graphql_mutation_response(:environment_create)['environment']['name']).to eq('production')
+ expect(graphql_mutation_response(:environment_create)['environment']['externalUrl']).to eq('https://gitlab.com/')
+ expect(graphql_mutation_response(:environment_create)['errors']).to be_empty
+ end
+
+ context 'when current user is reporter' do
+ let(:current_user) { reporter }
+
+ it 'returns error' do
+ post_graphql_mutation(mutation, current_user: current_user)
+
+ expect(graphql_errors.to_s)
+ .to include("The resource that you are attempting to access does not exist or you don't have permission")
+ end
+ end
+ end
+
+ context 'when name is missing' do
+ let(:input) do
+ {
+ project_path: project.full_path
+ }
+ end
+
+ it 'returns error' do
+ post_graphql_mutation(mutation, current_user: current_user)
+
+ expect(graphql_errors.to_s).to include("Expected value to not be null")
+ end
+ end
+end
diff --git a/spec/requests/api/graphql/mutations/environments/delete_spec.rb b/spec/requests/api/graphql/mutations/environments/delete_spec.rb
new file mode 100644
index 00000000000..1e28d0ebc0b
--- /dev/null
+++ b/spec/requests/api/graphql/mutations/environments/delete_spec.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe 'Delete Environment', feature_category: :deployment_management do
+ include GraphqlHelpers
+
+ let_it_be(:project) { create(:project, :repository) }
+ let_it_be(:environment) { create(:environment, project: project, state: :stopped) }
+ let_it_be(:maintainer) { create(:user).tap { |u| project.add_maintainer(u) } }
+ let_it_be(:developer) { create(:user).tap { |u| project.add_maintainer(u) } }
+
+ let(:environment_id) { environment.to_global_id.to_s }
+ let(:current_user) { developer }
+
+ let(:mutation) do
+ graphql_mutation(:environment_delete, input)
+ end
+
+ context 'when delete is successful' do
+ let(:input) do
+ { id: environment_id }
+ end
+
+ it 'deletes the environment' do
+ expect do
+ post_graphql_mutation(mutation, current_user: current_user)
+ end.to change { project.reload.environments.include?(environment) }.from(true).to(false)
+
+ expect(graphql_mutation_response(:environment_delete)['errors']).to be_empty
+ end
+ end
+end
diff --git a/spec/requests/api/graphql/mutations/environments/update_spec.rb b/spec/requests/api/graphql/mutations/environments/update_spec.rb
new file mode 100644
index 00000000000..9c68b3a024c
--- /dev/null
+++ b/spec/requests/api/graphql/mutations/environments/update_spec.rb
@@ -0,0 +1,70 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe 'Update Environment', feature_category: :deployment_management do
+ include GraphqlHelpers
+
+ let_it_be(:project) { create(:project, :repository) }
+ let_it_be(:environment) { create(:environment, project: project) }
+ let_it_be(:maintainer) { create(:user).tap { |u| project.add_maintainer(u) } }
+ let_it_be(:developer) { create(:user).tap { |u| project.add_maintainer(u) } }
+
+ let(:environment_id) { environment.to_global_id.to_s }
+ let(:current_user) { developer }
+
+ let(:mutation) do
+ graphql_mutation(:environment_update, input)
+ end
+
+ context 'when updating external URL' do
+ let(:input) do
+ {
+ id: environment_id,
+ external_url: 'https://gitlab.com/'
+ }
+ end
+
+ it 'updates successfully' do
+ expect do
+ post_graphql_mutation(mutation, current_user: current_user)
+ end.to change { environment.reload.external_url }.to('https://gitlab.com/')
+
+ expect(graphql_mutation_response(:environment_update)['errors']).to be_empty
+ end
+
+ context 'when url is invalid' do
+ let(:input) do
+ {
+ id: environment_id,
+ external_url: 'http://${URL}'
+ }
+ end
+
+ it 'returns error' do
+ expect do
+ post_graphql_mutation(mutation, current_user: current_user)
+ end.not_to change { environment.reload.external_url }
+
+ expect(graphql_mutation_response(:environment_update)['errors'].first).to include('URI is invalid')
+ end
+ end
+ end
+
+ context 'when updating tier' do
+ let(:input) do
+ {
+ id: environment_id,
+ tier: 'STAGING'
+ }
+ end
+
+ it 'updates successfully' do
+ expect do
+ post_graphql_mutation(mutation, current_user: current_user)
+ end.to change { environment.reload.tier }.to('staging')
+
+ expect(graphql_mutation_response(:environment_update)['errors']).to be_empty
+ end
+ end
+end