diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
commit | 4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch) | |
tree | 5423a1c7516cffe36384133ade12572cf709398d /spec/graphql/resolvers | |
parent | e570267f2f6b326480d284e0164a6464ba4081bc (diff) |
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'spec/graphql/resolvers')
19 files changed, 259 insertions, 21 deletions
diff --git a/spec/graphql/resolvers/admin/analytics/usage_trends/measurements_resolver_spec.rb b/spec/graphql/resolvers/admin/analytics/usage_trends/measurements_resolver_spec.rb index 269a1fb1758..b63eca4359d 100644 --- a/spec/graphql/resolvers/admin/analytics/usage_trends/measurements_resolver_spec.rb +++ b/spec/graphql/resolvers/admin/analytics/usage_trends/measurements_resolver_spec.rb @@ -6,6 +6,7 @@ RSpec.describe Resolvers::Admin::Analytics::UsageTrends::MeasurementsResolver do include GraphqlHelpers let_it_be(:admin_user) { create(:user, :admin) } + let(:current_user) { admin_user } describe '#resolve' do diff --git a/spec/graphql/resolvers/alert_management/alert_status_counts_resolver_spec.rb b/spec/graphql/resolvers/alert_management/alert_status_counts_resolver_spec.rb index b72e692f2e8..3bc6043a849 100644 --- a/spec/graphql/resolvers/alert_management/alert_status_counts_resolver_spec.rb +++ b/spec/graphql/resolvers/alert_management/alert_status_counts_resolver_spec.rb @@ -8,6 +8,7 @@ RSpec.describe Resolvers::AlertManagement::AlertStatusCountsResolver do describe '#resolve' do let_it_be(:current_user) { create(:user) } let_it_be(:project) { create(:project) } + let(:args) { {} } subject { resolve_alert_status_counts(args) } diff --git a/spec/graphql/resolvers/boards_resolver_spec.rb b/spec/graphql/resolvers/boards_resolver_spec.rb index cb3bcb002ec..221e905f441 100644 --- a/spec/graphql/resolvers/boards_resolver_spec.rb +++ b/spec/graphql/resolvers/boards_resolver_spec.rb @@ -54,7 +54,7 @@ RSpec.describe Resolvers::BoardsResolver do end it 'returns nil if board not found' do - outside_parent = create(board_parent.class.underscore.to_sym) + outside_parent = create(board_parent.class.underscore.to_sym) # rubocop:disable Rails/SaveBang outside_board = create(:board, name: 'outside board', resource_parent: outside_parent) expect(resolve_boards(args: { id: global_id_of(outside_board) })).to eq Board.none diff --git a/spec/graphql/resolvers/branch_commit_resolver_spec.rb b/spec/graphql/resolvers/branch_commit_resolver_spec.rb index 346c9e01088..3d5702539fa 100644 --- a/spec/graphql/resolvers/branch_commit_resolver_spec.rb +++ b/spec/graphql/resolvers/branch_commit_resolver_spec.rb @@ -8,6 +8,7 @@ RSpec.describe Resolvers::BranchCommitResolver do subject(:commit) { resolve(described_class, obj: branch) } let_it_be(:repository) { create(:project, :repository).repository } + let(:branch) { repository.find_branch('master') } describe '#resolve' do diff --git a/spec/graphql/resolvers/ci/runners_resolver_spec.rb b/spec/graphql/resolvers/ci/runners_resolver_spec.rb new file mode 100644 index 00000000000..006d6785506 --- /dev/null +++ b/spec/graphql/resolvers/ci/runners_resolver_spec.rb @@ -0,0 +1,136 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Resolvers::Ci::RunnersResolver do + include GraphqlHelpers + + let_it_be(:user) { create_default(:user, :admin) } + let_it_be(:group) { create(:group, :public) } + let_it_be(:project) { create(:project, :repository, :public) } + + let_it_be(:inactive_project_runner) do + create(:ci_runner, :project, projects: [project], active: false, contacted_at: 1.minute.ago, tag_list: %w(project_runner)) + end + + let_it_be(:offline_project_runner) do + create(:ci_runner, :project, projects: [project], contacted_at: 1.day.ago, tag_list: %w(project_runner active_runner)) + end + + let_it_be(:group_runner) { create(:ci_runner, :group, groups: [group], contacted_at: 1.second.ago) } + let_it_be(:instance_runner) { create(:ci_runner, :instance, contacted_at: 2.minutes.ago, tag_list: %w(instance_runner active_runner)) } + + describe '#resolve' do + subject { resolve(described_class, ctx: { current_user: user }, args: args).items.to_a } + + let(:args) do + {} + end + + context 'without sort' do + it 'returns all the runners' do + is_expected.to contain_exactly(inactive_project_runner, offline_project_runner, group_runner, instance_runner) + end + end + + context 'with a sort argument' do + context "set to :contacted_asc" do + let(:args) do + { sort: :contacted_asc } + end + + it { is_expected.to eq([offline_project_runner, instance_runner, inactive_project_runner, group_runner]) } + end + + context "set to :created_date" do + let(:args) do + { sort: :created_date } + end + + it { is_expected.to eq([instance_runner, group_runner, offline_project_runner, inactive_project_runner]) } + end + end + + context 'when type is filtered' do + let(:args) do + { type: runner_type.to_s } + end + + context 'to instance runners' do + let(:runner_type) { :instance_type } + + it 'returns the instance runner' do + is_expected.to contain_exactly(instance_runner) + end + end + + context 'to group runners' do + let(:runner_type) { :group_type } + + it 'returns the group runner' do + is_expected.to contain_exactly(group_runner) + end + end + + context 'to project runners' do + let(:runner_type) { :project_type } + + it 'returns the project runner' do + is_expected.to contain_exactly(inactive_project_runner, offline_project_runner) + end + end + end + + context 'when status is filtered' do + let(:args) do + { status: runner_status.to_s } + end + + context 'to active runners' do + let(:runner_status) { :active } + + it 'returns the instance and group runners' do + is_expected.to contain_exactly(offline_project_runner, group_runner, instance_runner) + end + end + + context 'to offline runners' do + let(:runner_status) { :offline } + + it 'returns the offline project runner' do + is_expected.to contain_exactly(offline_project_runner) + end + end + end + + context 'when tag list is filtered' do + let(:args) do + { tag_list: tag_list } + end + + context 'with "project_runner" tag' do + let(:tag_list) { ['project_runner'] } + + it 'returns the project_runner runners' do + is_expected.to contain_exactly(offline_project_runner, inactive_project_runner) + end + end + + context 'with "project_runner" and "active_runner" tags as comma-separated string' do + let(:tag_list) { ['project_runner,active_runner'] } + + it 'returns the offline_project_runner runner' do + is_expected.to contain_exactly(offline_project_runner) + end + end + + context 'with "active_runner" and "instance_runner" tags as array' do + let(:tag_list) { %w[instance_runner active_runner] } + + it 'returns the offline_project_runner runner' do + is_expected.to contain_exactly(instance_runner) + end + end + end + end +end diff --git a/spec/graphql/resolvers/ci/template_resolver_spec.rb b/spec/graphql/resolvers/ci/template_resolver_spec.rb new file mode 100644 index 00000000000..bec25640c7f --- /dev/null +++ b/spec/graphql/resolvers/ci/template_resolver_spec.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Resolvers::Ci::TemplateResolver do + include GraphqlHelpers + + describe '#resolve' do + let(:user) { create(:user) } + let(:project) { create(:project) } + + subject(:resolve_subject) { resolve(described_class, obj: project, ctx: { current_user: user }, args: { name: template_name }) } + + context 'when template exists' do + let(:template_name) { 'Android' } + + it 'returns the found template' do + found_template = resolve_subject + + expect(found_template).to be_an_instance_of(Gitlab::Template::GitlabCiYmlTemplate) + expect(found_template.name).to eq('Android') + end + end + + context 'when template does not exist' do + let(:template_name) { 'invalidname' } + + it 'returns nil' do + expect(resolve_subject).to eq(nil) + end + end + end +end diff --git a/spec/graphql/resolvers/design_management/designs_resolver_spec.rb b/spec/graphql/resolvers/design_management/designs_resolver_spec.rb index 28e963c88a9..b091e58b06f 100644 --- a/spec/graphql/resolvers/design_management/designs_resolver_spec.rb +++ b/spec/graphql/resolvers/design_management/designs_resolver_spec.rb @@ -20,6 +20,7 @@ RSpec.describe Resolvers::DesignManagement::DesignsResolver do let_it_be(:first_version) { create(:design_version) } let_it_be(:first_design) { create(:design, issue: issue, versions: [first_version]) } let_it_be(:current_user) { create(:user) } + let(:gql_context) { { current_user: current_user } } let(:args) { {} } diff --git a/spec/graphql/resolvers/design_management/version/designs_at_version_resolver_spec.rb b/spec/graphql/resolvers/design_management/version/designs_at_version_resolver_spec.rb index c038216ce0b..4e8f5e5fc1d 100644 --- a/spec/graphql/resolvers/design_management/version/designs_at_version_resolver_spec.rb +++ b/spec/graphql/resolvers/design_management/version/designs_at_version_resolver_spec.rb @@ -8,6 +8,7 @@ RSpec.describe Resolvers::DesignManagement::Version::DesignsAtVersionResolver do include_context 'four designs in three versions' let_it_be(:current_user) { authorized_user } + let(:gql_context) { { current_user: current_user } } let(:version) { third_version } diff --git a/spec/graphql/resolvers/design_management/versions_resolver_spec.rb b/spec/graphql/resolvers/design_management/versions_resolver_spec.rb index 23d4d86c79a..2c9c3a47650 100644 --- a/spec/graphql/resolvers/design_management/versions_resolver_spec.rb +++ b/spec/graphql/resolvers/design_management/versions_resolver_spec.rb @@ -41,6 +41,20 @@ RSpec.describe Resolvers::DesignManagement::VersionsResolver do it 'returns the ordered versions' do expect(result.to_a).to eq(all_versions) end + + context 'loading associations' do + it 'prevents N+1 queries when loading author' do + control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) do + resolve_versions(object).items.map(&:author) + end.count + + create_list(:design_version, 3, issue: issue) + + expect do + resolve_versions(object).items.map(&:author) + end.not_to exceed_all_query_limit(control_count) + end + end end context 'when constrained' do diff --git a/spec/graphql/resolvers/group_milestones_resolver_spec.rb b/spec/graphql/resolvers/group_milestones_resolver_spec.rb index dd3f1676538..78d89054efd 100644 --- a/spec/graphql/resolvers/group_milestones_resolver_spec.rb +++ b/spec/graphql/resolvers/group_milestones_resolver_spec.rb @@ -119,6 +119,7 @@ RSpec.describe Resolvers::GroupMilestonesResolver do context 'when including descendant milestones in a public group' do let_it_be(:group) { create(:group, :public) } + let(:args) { { include_descendants: true } } it 'finds milestones only in accessible projects and groups' do diff --git a/spec/graphql/resolvers/group_packages_resolver_spec.rb b/spec/graphql/resolvers/group_packages_resolver_spec.rb index 59438b8d5ad..48f4c8ec4ca 100644 --- a/spec/graphql/resolvers/group_packages_resolver_spec.rb +++ b/spec/graphql/resolvers/group_packages_resolver_spec.rb @@ -8,11 +8,14 @@ RSpec.describe Resolvers::GroupPackagesResolver do let_it_be(:user) { create(:user) } let_it_be(:group) { create(:group, :public) } let_it_be(:project) { create(:project, :public, group: group) } - let_it_be(:package) { create(:package, project: project) } + + let(:args) do + { sort: :created_desc } + end describe '#resolve' do - subject(:packages) { resolve(described_class, ctx: { current_user: user }, obj: group) } + subject { resolve(described_class, ctx: { current_user: user }, obj: group, args: args).to_a } - it { is_expected.to contain_exactly(package) } + it_behaves_like 'group and projects packages resolver' end end diff --git a/spec/graphql/resolvers/merge_request_pipelines_resolver_spec.rb b/spec/graphql/resolvers/merge_request_pipelines_resolver_spec.rb index 84ef906b72f..3aadbc76be8 100644 --- a/spec/graphql/resolvers/merge_request_pipelines_resolver_spec.rb +++ b/spec/graphql/resolvers/merge_request_pipelines_resolver_spec.rb @@ -17,6 +17,7 @@ RSpec.describe Resolvers::MergeRequestPipelinesResolver do let_it_be(:other_project_pipeline) { create(:ci_pipeline, project: merge_request.source_project, ref: 'other-ref') } let_it_be(:other_pipeline) { create(:ci_pipeline) } + let(:current_user) { create(:user) } before do diff --git a/spec/graphql/resolvers/metadata_resolver_spec.rb b/spec/graphql/resolvers/metadata_resolver_spec.rb index f8c01f9d531..56875e185e7 100644 --- a/spec/graphql/resolvers/metadata_resolver_spec.rb +++ b/spec/graphql/resolvers/metadata_resolver_spec.rb @@ -7,7 +7,10 @@ RSpec.describe Resolvers::MetadataResolver do describe '#resolve' do it 'returns version and revision' do - expect(resolve(described_class)).to have_attributes(version: Gitlab::VERSION, revision: Gitlab.revision) + expect(resolve(described_class)).to have_attributes( + version: Gitlab::VERSION, + revision: Gitlab.revision, + kas: kind_of(InstanceMetadata::Kas)) end end end diff --git a/spec/graphql/resolvers/metrics/dashboards/annotation_resolver_spec.rb b/spec/graphql/resolvers/metrics/dashboards/annotation_resolver_spec.rb index f90869c52bc..a83cef40bdf 100644 --- a/spec/graphql/resolvers/metrics/dashboards/annotation_resolver_spec.rb +++ b/spec/graphql/resolvers/metrics/dashboards/annotation_resolver_spec.rb @@ -12,6 +12,7 @@ RSpec.describe Resolvers::Metrics::Dashboards::AnnotationResolver do let_it_be(:current_user) { create(:user) } let_it_be(:environment) { create(:environment) } let_it_be(:path) { 'config/prometheus/common_metrics.yml' } + let(:dashboard) { PerformanceMonitoring::PrometheusDashboard.new(path: path, environment: environment) } let(:args) do { diff --git a/spec/graphql/resolvers/packages_base_resolver_spec.rb b/spec/graphql/resolvers/packages_base_resolver_spec.rb new file mode 100644 index 00000000000..8f9865c3785 --- /dev/null +++ b/spec/graphql/resolvers/packages_base_resolver_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Resolvers::PackagesBaseResolver do + include GraphqlHelpers + + describe '#resolve' do + subject { resolve(described_class) } + + it 'throws an error' do + expect { subject }.to raise_error(NotImplementedError) + end + end +end diff --git a/spec/graphql/resolvers/project_packages_resolver_spec.rb b/spec/graphql/resolvers/project_packages_resolver_spec.rb index c8105ed2a38..66a94bd42dd 100644 --- a/spec/graphql/resolvers/project_packages_resolver_spec.rb +++ b/spec/graphql/resolvers/project_packages_resolver_spec.rb @@ -6,12 +6,15 @@ RSpec.describe Resolvers::ProjectPackagesResolver do include GraphqlHelpers let_it_be(:user) { create(:user) } - let_it_be(:project) { create(:project, :public) } - let_it_be(:package) { create(:package, project: project) } + let_it_be_with_reload(:project) { create(:project, :public) } + + let(:args) do + { sort: :created_desc } + end describe '#resolve' do - subject(:packages) { resolve(described_class, ctx: { current_user: user }, obj: project) } + subject { resolve(described_class, ctx: { current_user: user }, obj: project, args: args).to_a } - it { is_expected.to contain_exactly(package) } + it_behaves_like 'group and projects packages resolver' end end diff --git a/spec/graphql/resolvers/project_pipeline_resolver_spec.rb b/spec/graphql/resolvers/project_pipeline_resolver_spec.rb index 3d33e0b500d..6a8aa39f3b2 100644 --- a/spec/graphql/resolvers/project_pipeline_resolver_spec.rb +++ b/spec/graphql/resolvers/project_pipeline_resolver_spec.rb @@ -9,6 +9,7 @@ RSpec.describe Resolvers::ProjectPipelineResolver do let_it_be(:pipeline) { create(:ci_pipeline, project: project, iid: '1234', sha: 'sha') } let_it_be(:other_project_pipeline) { create(:ci_pipeline, project: project, iid: '1235', sha: 'sha2') } let_it_be(:other_pipeline) { create(:ci_pipeline) } + let(:current_user) { create(:user) } specify do diff --git a/spec/graphql/resolvers/project_pipelines_resolver_spec.rb b/spec/graphql/resolvers/project_pipelines_resolver_spec.rb index b2e8fed2441..c7c00f54c0c 100644 --- a/spec/graphql/resolvers/project_pipelines_resolver_spec.rb +++ b/spec/graphql/resolvers/project_pipelines_resolver_spec.rb @@ -8,6 +8,7 @@ RSpec.describe Resolvers::ProjectPipelinesResolver do let_it_be(:project) { create(:project) } let_it_be(:pipeline) { create(:ci_pipeline, project: project) } let_it_be(:other_pipeline) { create(:ci_pipeline) } + let(:current_user) { create(:user) } before do diff --git a/spec/graphql/resolvers/repository_branch_names_resolver_spec.rb b/spec/graphql/resolvers/repository_branch_names_resolver_spec.rb index 398dd7a2e2e..004e0411e51 100644 --- a/spec/graphql/resolvers/repository_branch_names_resolver_spec.rb +++ b/spec/graphql/resolvers/repository_branch_names_resolver_spec.rb @@ -8,29 +8,50 @@ RSpec.describe Resolvers::RepositoryBranchNamesResolver do let(:project) { create(:project, :repository) } describe '#resolve' do - subject(:resolve_branch_names) do - resolve( - described_class, - obj: project.repository, - args: { search_pattern: pattern }, - ctx: { current_user: project.creator } - ) - end - context 'with empty search pattern' do let(:pattern) { '' } it 'returns nil' do - expect(resolve_branch_names).to eq(nil) + expect(resolve_branch_names(pattern, 0, 100)).to eq(nil) end end context 'with a valid search pattern' do - let(:pattern) { 'mas*' } + let(:pattern) { 'snippet/*' } it 'returns matching branches' do - expect(resolve_branch_names).to match_array(['master']) + expect(resolve_branch_names(pattern, 0, 100)).to contain_exactly( + 'snippet/edit-file', + 'snippet/multiple-files', + 'snippet/no-files', + 'snippet/rename-and-edit-file', + 'snippet/single-file' + ) + end + + it 'properly offsets and limits branch name results' do + starting_names = resolve_branch_names(pattern, 0, 3) + offset_names = resolve_branch_names(pattern, 3, 2) + + expect(starting_names.count).to eq(3) + expect(offset_names.count).to eq(2) + + expect(offset_names).not_to include(*starting_names) + + all_names = resolve_branch_names(pattern, 0, 100) + expect(all_names).to contain_exactly(*starting_names, *offset_names) end end end + + private + + def resolve_branch_names(pattern, offset, limit) + resolve( + described_class, + obj: project.repository, + args: { search_pattern: pattern, offset: offset, limit: limit }, + ctx: { current_user: project.creator } + ) + end end |