diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-04 18:09:55 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-04 18:09:55 +0000 |
commit | ae42530b1be0d25186881ae45c39bdf1122a84b9 (patch) | |
tree | 0592eb5b3b23d1dcd3b00bdb3b00f3b28412a291 /spec/graphql | |
parent | e0655935eb32ba057b6ced978940076681d71177 (diff) | |
download | gitlab-ce-ae42530b1be0d25186881ae45c39bdf1122a84b9.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/graphql')
-rw-r--r-- | spec/graphql/features/authorization_spec.rb | 22 | ||||
-rw-r--r-- | spec/graphql/features/feature_flag_spec.rb | 2 | ||||
-rw-r--r-- | spec/graphql/mutations/environments/canary_ingress/update_spec.rb | 66 | ||||
-rw-r--r-- | spec/graphql/resolvers/ci/config_resolver_spec.rb | 56 | ||||
-rw-r--r-- | spec/graphql/types/ci/config/config_type_spec.rb | 18 | ||||
-rw-r--r-- | spec/graphql/types/ci/config/group_type_spec.rb | 17 | ||||
-rw-r--r-- | spec/graphql/types/ci/config/job_type_spec.rb | 18 | ||||
-rw-r--r-- | spec/graphql/types/ci/config/need_type_spec.rb | 15 | ||||
-rw-r--r-- | spec/graphql/types/ci/config/stage_type_spec.rb | 16 | ||||
-rw-r--r-- | spec/graphql/types/permission_types/base_permission_type_spec.rb | 6 |
10 files changed, 222 insertions, 14 deletions
diff --git a/spec/graphql/features/authorization_spec.rb b/spec/graphql/features/authorization_spec.rb index e40c44925e2..ec67ed16fe9 100644 --- a/spec/graphql/features/authorization_spec.rb +++ b/spec/graphql/features/authorization_spec.rb @@ -55,7 +55,7 @@ RSpec.describe 'Gitlab::Graphql::Authorization' do describe 'with a single permission' do let(:query_type) do query_factory do |query| - query.field :item, type, null: true, resolve: ->(obj, args, ctx) { test_object }, authorize: permission_single + query.field :item, type, null: true, resolver: simple_resolver(test_object), authorize: permission_single end end @@ -66,7 +66,7 @@ RSpec.describe 'Gitlab::Graphql::Authorization' do let(:query_type) do permissions = permission_collection query_factory do |qt| - qt.field :item, type, null: true, resolve: ->(obj, args, ctx) { test_object } do + qt.field :item, type, null: true, resolver: simple_resolver(test_object) do authorize permissions end end @@ -79,7 +79,7 @@ RSpec.describe 'Gitlab::Graphql::Authorization' do describe 'Field authorizations when field is a built in type' do let(:query_type) do query_factory do |query| - query.field :item, type, null: true, resolve: ->(obj, args, ctx) { test_object } + query.field :item, type, null: true, resolver: simple_resolver(test_object) end end @@ -132,7 +132,7 @@ RSpec.describe 'Gitlab::Graphql::Authorization' do describe 'Type authorizations' do let(:query_type) do query_factory do |query| - query.field :item, type, null: true, resolve: ->(obj, args, ctx) { test_object } + query.field :item, type, null: true, resolver: simple_resolver(test_object) end end @@ -169,7 +169,7 @@ RSpec.describe 'Gitlab::Graphql::Authorization' do let(:query_type) do query_factory do |query| - query.field :item, type, null: true, resolve: ->(obj, args, ctx) { test_object }, authorize: permission_2 + query.field :item, type, null: true, resolver: simple_resolver(test_object), authorize: permission_2 end end @@ -188,7 +188,7 @@ RSpec.describe 'Gitlab::Graphql::Authorization' do let(:query_type) do query_factory do |query| - query.field :item, type.connection_type, null: true, resolve: ->(obj, args, ctx) { [test_object, second_test_object] } + query.field :item, type.connection_type, null: true, resolver: simple_resolver([test_object, second_test_object]) end end @@ -208,9 +208,7 @@ RSpec.describe 'Gitlab::Graphql::Authorization' do describe 'limiting connections with multiple objects' do let(:query_type) do query_factory do |query| - query.field :item, type.connection_type, null: true, resolve: ->(obj, args, ctx) do - [test_object, second_test_object] - end + query.field :item, type.connection_type, null: true, resolver: simple_resolver([test_object, second_test_object]) end end @@ -234,7 +232,7 @@ RSpec.describe 'Gitlab::Graphql::Authorization' do let(:query_type) do query_factory do |query| - query.field :item, [type], null: true, resolve: ->(obj, args, ctx) { [test_object] } + query.field :item, [type], null: true, resolver: simple_resolver([test_object]) end end @@ -262,13 +260,13 @@ RSpec.describe 'Gitlab::Graphql::Authorization' do type_factory do |type| type.graphql_name 'FakeProjectType' type.field :test_issues, issue_type.connection_type, null: false, - resolve: -> (_, _, _) { Issue.where(project: [visible_project, other_project]).order(id: :asc) } + resolver: simple_resolver(Issue.where(project: [visible_project, other_project]).order(id: :asc)) end end let(:query_type) do query_factory do |query| - query.field :test_project, project_type, null: false, resolve: -> (_, _, _) { visible_project } + query.field :test_project, project_type, null: false, resolver: simple_resolver(visible_project) end end diff --git a/spec/graphql/features/feature_flag_spec.rb b/spec/graphql/features/feature_flag_spec.rb index 9ebc6e595a6..77810f78257 100644 --- a/spec/graphql/features/feature_flag_spec.rb +++ b/spec/graphql/features/feature_flag_spec.rb @@ -23,7 +23,7 @@ RSpec.describe 'Graphql Field feature flags' do let(:query_type) do query_factory do |query| - query.field :item, type, null: true, feature_flag: feature_flag, resolve: ->(obj, args, ctx) { test_object } + query.field :item, type, null: true, feature_flag: feature_flag, resolver: simple_resolver(test_object) end end diff --git a/spec/graphql/mutations/environments/canary_ingress/update_spec.rb b/spec/graphql/mutations/environments/canary_ingress/update_spec.rb new file mode 100644 index 00000000000..c022828cf09 --- /dev/null +++ b/spec/graphql/mutations/environments/canary_ingress/update_spec.rb @@ -0,0 +1,66 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Mutations::Environments::CanaryIngress::Update do + let_it_be(:project) { create(:project) } + let_it_be(:environment) { create(:environment, project: project) } + let_it_be(:maintainer) { create(:user) } + let_it_be(:reporter) { create(:user) } + let(:user) { maintainer } + + subject(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) } + + before_all do + project.add_maintainer(maintainer) + project.add_reporter(reporter) + end + + describe '#resolve' do + subject { mutation.resolve(id: environment_id, weight: weight) } + + let(:environment_id) { environment.to_global_id.to_s } + let(:weight) { 50 } + let(:update_service) { double('update_service') } + + before do + allow(Environments::CanaryIngress::UpdateService).to receive(:new) { update_service } + end + + context 'when service execution succeeded' do + before do + allow(update_service).to receive(:execute_async) { { status: :success } } + end + + it 'returns no errors' do + expect(subject[:errors]).to be_empty + end + end + + context 'when service encounters a problem' do + before do + allow(update_service).to receive(:execute_async) { { status: :error, message: 'something went wrong' } } + end + + it 'returns an error' do + expect(subject[:errors]).to eq(['something went wrong']) + end + end + + context 'when environment is not found' do + let(:environment_id) { non_existing_record_id.to_s } + + it 'raises an error' do + expect { subject }.to raise_error(GraphQL::CoercionError) + end + end + + context 'when user is reporter who does not have permission to access the environment' do + let(:user) { reporter } + + it 'raises an error' do + expect { subject }.to raise_error("The resource that you are attempting to access does not exist or you don't have permission to perform this action") + end + end + end +end diff --git a/spec/graphql/resolvers/ci/config_resolver_spec.rb b/spec/graphql/resolvers/ci/config_resolver_spec.rb new file mode 100644 index 00000000000..6911acdb4ec --- /dev/null +++ b/spec/graphql/resolvers/ci/config_resolver_spec.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Resolvers::Ci::ConfigResolver do + include GraphqlHelpers + + describe '#resolve' do + before do + yaml_processor_double = instance_double(::Gitlab::Ci::YamlProcessor) + allow(yaml_processor_double).to receive(:execute).and_return(fake_result) + + allow(::Gitlab::Ci::YamlProcessor).to receive(:new).and_return(yaml_processor_double) + end + + context 'with a valid .gitlab-ci.yml' do + let(:fake_result) do + ::Gitlab::Ci::YamlProcessor::Result.new( + ci_config: ::Gitlab::Ci::Config.new(content), + errors: [], + warnings: [] + ) + end + + let_it_be(:content) do + File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci_includes.yml')) + end + + it 'lints the ci config file' do + response = resolve(described_class, args: { content: content }, ctx: {}) + + expect(response[:status]).to eq(:valid) + expect(response[:errors]).to be_empty + end + end + + context 'with an invalid .gitlab-ci.yml' do + let(:content) { 'invalid' } + + let(:fake_result) do + Gitlab::Ci::YamlProcessor::Result.new( + ci_config: nil, + errors: ['Invalid configuration format'], + warnings: [] + ) + end + + it 'responds with errors about invalid syntax' do + response = resolve(described_class, args: { content: content }, ctx: {}) + + expect(response[:status]).to eq(:invalid) + expect(response[:errors]).to eq(['Invalid configuration format']) + end + end + end +end diff --git a/spec/graphql/types/ci/config/config_type_spec.rb b/spec/graphql/types/ci/config/config_type_spec.rb new file mode 100644 index 00000000000..edd190a4365 --- /dev/null +++ b/spec/graphql/types/ci/config/config_type_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::Ci::Config::ConfigType do + specify { expect(described_class.graphql_name).to eq('CiConfig') } + + it 'exposes the expected fields' do + expected_fields = %i[ + errors + mergedYaml + stages + status + ] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/ci/config/group_type_spec.rb b/spec/graphql/types/ci/config/group_type_spec.rb new file mode 100644 index 00000000000..7d808e85371 --- /dev/null +++ b/spec/graphql/types/ci/config/group_type_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::Ci::Config::GroupType do + specify { expect(described_class.graphql_name).to eq('CiConfigGroup') } + + it 'exposes the expected fields' do + expected_fields = %i[ + name + jobs + size + ] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/ci/config/job_type_spec.rb b/spec/graphql/types/ci/config/job_type_spec.rb new file mode 100644 index 00000000000..600d665a84b --- /dev/null +++ b/spec/graphql/types/ci/config/job_type_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::Ci::Config::JobType do + specify { expect(described_class.graphql_name).to eq('CiConfigJob') } + + it 'exposes the expected fields' do + expected_fields = %i[ + name + group_name + stage + needs + ] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/ci/config/need_type_spec.rb b/spec/graphql/types/ci/config/need_type_spec.rb new file mode 100644 index 00000000000..3387049a81d --- /dev/null +++ b/spec/graphql/types/ci/config/need_type_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::Ci::Config::NeedType do + specify { expect(described_class.graphql_name).to eq('CiConfigNeed') } + + it 'exposes the expected fields' do + expected_fields = %i[ + name + ] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/ci/config/stage_type_spec.rb b/spec/graphql/types/ci/config/stage_type_spec.rb new file mode 100644 index 00000000000..aba97f8c7ed --- /dev/null +++ b/spec/graphql/types/ci/config/stage_type_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::Ci::Config::StageType do + specify { expect(described_class.graphql_name).to eq('CiConfigStage') } + + it 'exposes the expected fields' do + expected_fields = %i[ + name + groups + ] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/permission_types/base_permission_type_spec.rb b/spec/graphql/types/permission_types/base_permission_type_spec.rb index 2ce02f1520c..68632a509ee 100644 --- a/spec/graphql/types/permission_types/base_permission_type_spec.rb +++ b/spec/graphql/types/permission_types/base_permission_type_spec.rb @@ -11,9 +11,13 @@ RSpec.describe Types::PermissionTypes::BasePermissionType do Class.new(described_class) do graphql_name 'TestClass' - permission_field :do_stuff, resolve: -> (_, _, _) { true } + permission_field :do_stuff ability_field(:read_issue) abilities :admin_issue + + define_method :do_stuff do + true + end end end |