diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-24 06:09:04 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-24 06:09:04 +0300 |
commit | 93b0b77287acb1cf1a6a408b3a4e9587bedc9364 (patch) | |
tree | 8bf7121ae9329c82dbc85745fe4c8d831ef3cea0 /spec/graphql | |
parent | 27f3465d8a52afce630417b6e4b58992b6e403fe (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/graphql')
-rw-r--r-- | spec/graphql/features/authorization_spec.rb | 32 | ||||
-rw-r--r-- | spec/graphql/mutations/design_management/upload_spec.rb | 4 | ||||
-rw-r--r-- | spec/graphql/resolvers/merge_requests_resolver_spec.rb | 43 | ||||
-rw-r--r-- | spec/graphql/types/alert_management/prometheus_integration_type_spec.rb | 4 | ||||
-rw-r--r-- | spec/graphql/types/base_object_spec.rb | 14 | ||||
-rw-r--r-- | spec/graphql/types/project_type_spec.rb | 20 |
6 files changed, 71 insertions, 46 deletions
diff --git a/spec/graphql/features/authorization_spec.rb b/spec/graphql/features/authorization_spec.rb index 7ab5adadd1f..d2a6b91d1c2 100644 --- a/spec/graphql/features/authorization_spec.rb +++ b/spec/graphql/features/authorization_spec.rb @@ -84,9 +84,9 @@ RSpec.describe 'DeclarativePolicy authorization in GraphQL ' do permissions = permission_collection query_factory do |qt| qt.field :item, type, - null: true, - resolver: new_resolver(test_object), - authorize: permissions + null: true, + resolver: new_resolver(test_object), + authorize: permissions end end @@ -123,8 +123,9 @@ RSpec.describe 'DeclarativePolicy authorization in GraphQL ' do let(:type) do permissions = permission_collection type_factory do |type| - type.field :name, GraphQL::STRING_TYPE, null: true, - authorize: permissions + type.field :name, GraphQL::STRING_TYPE, + null: true, + authorize: permissions end end @@ -201,9 +202,10 @@ RSpec.describe 'DeclarativePolicy authorization in GraphQL ' do let(:query_type) do query_factory do |query| - query.field :item, type, null: true, - resolver: resolver, - authorize: permission_2 + query.field :item, type, + null: true, + resolver: resolver, + authorize: permission_2 end end @@ -288,8 +290,12 @@ RSpec.describe 'DeclarativePolicy authorization in GraphQL ' do let(:query_string) { '{ item(first: 1) { edges { node { name } } } }' } it 'only checks permissions for the first object' do - expect(Ability).to receive(:allowed?).with(user, permission_single, test_object) { true } - expect(Ability).not_to receive(:allowed?).with(user, permission_single, second_test_object) + expect(Ability) + .to receive(:allowed?) + .with(user, permission_single, test_object) + .and_return(true) + expect(Ability) + .not_to receive(:allowed?).with(user, permission_single, second_test_object) expect(subject.size).to eq(1) end @@ -330,10 +336,12 @@ RSpec.describe 'DeclarativePolicy authorization in GraphQL ' do end let(:project_type) do |type| + issues = Issue.where(project: [visible_project, other_project]).order(id: :asc) type_factory do |type| type.graphql_name 'FakeProjectType' - type.field :test_issues, issue_type.connection_type, null: false, - resolver: new_resolver(Issue.where(project: [visible_project, other_project]).order(id: :asc)) + type.field :test_issues, issue_type.connection_type, + null: false, + resolver: new_resolver(issues) end end diff --git a/spec/graphql/mutations/design_management/upload_spec.rb b/spec/graphql/mutations/design_management/upload_spec.rb index e92000194b1..ada88b7652c 100644 --- a/spec/graphql/mutations/design_management/upload_spec.rb +++ b/spec/graphql/mutations/design_management/upload_spec.rb @@ -56,10 +56,10 @@ RSpec.describe Mutations::DesignManagement::Upload do .map { |f| RenameableUpload.unique_file(f) } end - def creates_designs + def creates_designs(&block) prior_count = DesignManagement::Design.count - expect { yield }.not_to raise_error + expect(&block).not_to raise_error expect(DesignManagement::Design.count).to eq(prior_count + files.size) end diff --git a/spec/graphql/resolvers/merge_requests_resolver_spec.rb b/spec/graphql/resolvers/merge_requests_resolver_spec.rb index 5e2a075c5b3..09f5181107d 100644 --- a/spec/graphql/resolvers/merge_requests_resolver_spec.rb +++ b/spec/graphql/resolvers/merge_requests_resolver_spec.rb @@ -7,6 +7,7 @@ RSpec.describe Resolvers::MergeRequestsResolver do include SortingHelper let_it_be(:project) { create(:project, :repository) } + let_it_be(:other_project) { create(:project, :repository) } let_it_be(:milestone) { create(:milestone, project: project) } let_it_be(:current_user) { create(:user) } let_it_be(:other_user) { create(:user) } @@ -16,10 +17,17 @@ RSpec.describe Resolvers::MergeRequestsResolver do let_it_be(:merge_request_3) { create(:merge_request, :unique_branches, **common_attrs) } let_it_be(:merge_request_4) { create(:merge_request, :unique_branches, :locked, **common_attrs) } let_it_be(:merge_request_5) { create(:merge_request, :simple, :locked, **common_attrs) } - let_it_be(:merge_request_6) { create(:labeled_merge_request, :unique_branches, labels: create_list(:label, 2, project: project), **common_attrs) } - let_it_be(:merge_request_with_milestone) { create(:merge_request, :unique_branches, **common_attrs, milestone: milestone) } - let_it_be(:other_project) { create(:project, :repository) } - let_it_be(:other_merge_request) { create(:merge_request, source_project: other_project, target_project: other_project) } + let_it_be(:merge_request_6) do + create(:labeled_merge_request, :unique_branches, **common_attrs, labels: create_list(:label, 2, project: project)) + end + + let_it_be(:merge_request_with_milestone) do + create(:merge_request, :unique_branches, **common_attrs, milestone: milestone) + end + + let_it_be(:other_merge_request) do + create(:merge_request, source_project: other_project, target_project: other_project) + end let(:iid_1) { merge_request_1.iid } let(:iid_2) { merge_request_2.iid } @@ -43,11 +51,14 @@ RSpec.describe Resolvers::MergeRequestsResolver do # SELECT "project_features".* FROM "project_features" WHERE "project_features"."project_id" = 2 let(:queries_per_project) { 4 } - context 'no arguments' do + context 'without arguments' do it 'returns all merge requests' do result = resolve_mr(project) - expect(result).to contain_exactly(merge_request_1, merge_request_2, merge_request_3, merge_request_4, merge_request_5, merge_request_6, merge_request_with_milestone) + expect(result).to contain_exactly( + merge_request_1, merge_request_2, merge_request_3, merge_request_4, merge_request_5, + merge_request_6, merge_request_with_milestone + ) end it 'returns only merge requests that the current user can see' do @@ -57,7 +68,7 @@ RSpec.describe Resolvers::MergeRequestsResolver do end end - context 'by iid alone' do + context 'with iid alone' do it 'batch-resolves by target project full path and individual IID', :request_store do # 1 query for project_authorizations, and 1 for merge_requests result = batch_sync(max_queries: queries_per_project) do @@ -83,7 +94,7 @@ RSpec.describe Resolvers::MergeRequestsResolver do expect(result).to contain_exactly(merge_request_1, merge_request_2, merge_request_3) end - it 'can batch-resolve merge requests from different projects', :request_store, :use_clean_rails_memory_store_caching do + it 'can batch-resolve merge requests from different projects', :request_store do # 2 queries for project_authorizations, and 2 for merge_requests results = batch_sync(max_queries: queries_per_project * 2) do a = resolve_mr(project, iids: [iid_1]) @@ -121,7 +132,7 @@ RSpec.describe Resolvers::MergeRequestsResolver do end end - context 'by source branches' do + context 'with source branches argument' do it 'takes one argument' do result = resolve_mr(project, source_branches: [merge_request_3.source_branch]) @@ -131,13 +142,13 @@ RSpec.describe Resolvers::MergeRequestsResolver do it 'takes more than one argument' do mrs = [merge_request_3, merge_request_4] branches = mrs.map(&:source_branch) - result = resolve_mr(project, source_branches: branches ) + result = resolve_mr(project, source_branches: branches) expect(result).to match_array(mrs) end end - context 'by target branches' do + context 'with target branches argument' do it 'takes one argument' do result = resolve_mr(project, target_branches: [merge_request_3.target_branch]) @@ -153,7 +164,7 @@ RSpec.describe Resolvers::MergeRequestsResolver do end end - context 'by state' do + context 'with state argument' do it 'takes one argument' do result = resolve_mr(project, state: 'locked') @@ -161,7 +172,7 @@ RSpec.describe Resolvers::MergeRequestsResolver do end end - context 'by label' do + context 'with label argument' do let_it_be(:label) { merge_request_6.labels.first } let_it_be(:with_label) { create(:labeled_merge_request, :closed, labels: [label], **common_attrs) } @@ -178,7 +189,7 @@ RSpec.describe Resolvers::MergeRequestsResolver do end end - context 'by merged_after and merged_before' do + context 'with merged_after and merged_before arguments' do before do merge_request_1.metrics.update!(merged_at: 10.days.ago) end @@ -196,7 +207,7 @@ RSpec.describe Resolvers::MergeRequestsResolver do end end - context 'by milestone' do + context 'with milestone argument' do it 'filters merge requests by milestone title' do result = resolve_mr(project, milestone_title: milestone.title) @@ -212,7 +223,7 @@ RSpec.describe Resolvers::MergeRequestsResolver do describe 'combinations' do it 'requires all filters' do - create(:merge_request, :closed, source_project: project, target_project: project, source_branch: merge_request_4.source_branch) + create(:merge_request, :closed, **common_attrs, source_branch: merge_request_4.source_branch) result = resolve_mr(project, source_branches: [merge_request_4.source_branch], state: 'locked') diff --git a/spec/graphql/types/alert_management/prometheus_integration_type_spec.rb b/spec/graphql/types/alert_management/prometheus_integration_type_spec.rb index 7e4110af9a4..d057afb331c 100644 --- a/spec/graphql/types/alert_management/prometheus_integration_type_spec.rb +++ b/spec/graphql/types/alert_management/prometheus_integration_type_spec.rb @@ -48,14 +48,14 @@ RSpec.describe GitlabSchema.types['AlertManagementPrometheusIntegration'] do end end - context 'group integration' do + describe 'a group integration' do let_it_be(:group) { create(:group) } let_it_be(:integration) { create(:prometheus_service, project: nil, group: group) } # Since it is impossible to authorize the parent here, given that the # project is nil, all fields should be redacted: - described_class.fields.keys.each do |field_name| + described_class.fields.each_key do |field_name| context "field: #{field_name}" do it 'is redacted' do expect do diff --git a/spec/graphql/types/base_object_spec.rb b/spec/graphql/types/base_object_spec.rb index d144c1f6456..d8f2ef58ea5 100644 --- a/spec/graphql/types/base_object_spec.rb +++ b/spec/graphql/types/base_object_spec.rb @@ -196,20 +196,20 @@ RSpec.describe Types::BaseObject do end # For example a batchloaded association - context 'a lazy list' do + describe 'a lazy list' do it_behaves_like 'array member redaction', %w[lazyListOfYs] end # For example using a batchloader to map over a set of IDs - context 'a list of lazy items' do + describe 'a list of lazy items' do it_behaves_like 'array member redaction', %w[listOfLazyYs] end - context 'an array connection of items' do + describe 'an array connection of items' do it_behaves_like 'array member redaction', %w[arrayYsConn nodes] end - context 'an array connection of items, selecting edges' do + describe 'an array connection of items, selecting edges' do it_behaves_like 'array member redaction', %w[arrayYsConn edges node] end @@ -222,7 +222,7 @@ RSpec.describe Types::BaseObject do } } - doc = ->(after) do + doc = lambda do |after| GraphQL.parse(<<~GQL) query { x { @@ -238,9 +238,7 @@ RSpec.describe Types::BaseObject do } GQL end - returned_items = ->(ids) do - ids.to_a.map { |id| eq({ 'id' => id }) } - end + returned_items = ->(ids) { ids.to_a.map { |id| eq({ 'id' => id }) } } query = GraphQL::Query.new(test_schema, document: doc[nil], context: data) result = query.result.to_h diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb index 9579ef8b99b..8499df6234d 100644 --- a/spec/graphql/types/project_type_spec.rb +++ b/spec/graphql/types/project_type_spec.rb @@ -106,7 +106,8 @@ RSpec.describe GitlabSchema.types['Project'] do expect(secure_analyzers_prefix['type']).to eq('string') expect(secure_analyzers_prefix['field']).to eq('SECURE_ANALYZERS_PREFIX') expect(secure_analyzers_prefix['label']).to eq('Image prefix') - expect(secure_analyzers_prefix['defaultValue']).to eq('registry.gitlab.com/gitlab-org/security-products/analyzers') + expect(secure_analyzers_prefix['defaultValue']) + .to eq('registry.gitlab.com/gitlab-org/security-products/analyzers') expect(secure_analyzers_prefix['value']).to eq('registry.gitlab.com/gitlab-org/security-products/analyzers') expect(secure_analyzers_prefix['size']).to eq('LARGE') expect(secure_analyzers_prefix['options']).to be_nil @@ -184,9 +185,11 @@ RSpec.describe GitlabSchema.types['Project'] do context 'when repository is accessible only by team members' do it "returns no configuration" do - project.project_feature.update!(merge_requests_access_level: ProjectFeature::DISABLED, - builds_access_level: ProjectFeature::DISABLED, - repository_access_level: ProjectFeature::PRIVATE) + project.project_feature.update!( + merge_requests_access_level: ProjectFeature::DISABLED, + builds_access_level: ProjectFeature::DISABLED, + repository_access_level: ProjectFeature::PRIVATE + ) secure_analyzers_prefix = subject.dig('data', 'project', 'sastCiConfiguration') expect(secure_analyzers_prefix).to be_nil @@ -342,8 +345,13 @@ RSpec.describe GitlabSchema.types['Project'] do let_it_be(:project) { create(:project, :public) } context 'when project has Jira imports' do - let_it_be(:jira_import1) { create(:jira_import_state, :finished, project: project, jira_project_key: 'AA', created_at: 2.days.ago) } - let_it_be(:jira_import2) { create(:jira_import_state, :finished, project: project, jira_project_key: 'BB', created_at: 5.days.ago) } + let_it_be(:jira_import1) do + create(:jira_import_state, :finished, project: project, jira_project_key: 'AA', created_at: 2.days.ago) + end + + let_it_be(:jira_import2) do + create(:jira_import_state, :finished, project: project, jira_project_key: 'BB', created_at: 5.days.ago) + end it 'retrieves the imports' do expect(subject).to contain_exactly(jira_import1, jira_import2) |