diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /spec/graphql/resolvers | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'spec/graphql/resolvers')
10 files changed, 173 insertions, 22 deletions
diff --git a/spec/graphql/resolvers/alert_management/http_integrations_resolver_spec.rb b/spec/graphql/resolvers/alert_management/http_integrations_resolver_spec.rb index a4d1101bc4f..0f40565c5d3 100644 --- a/spec/graphql/resolvers/alert_management/http_integrations_resolver_spec.rb +++ b/spec/graphql/resolvers/alert_management/http_integrations_resolver_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Resolvers::AlertManagement::HttpIntegrationsResolver do let_it_be(:developer) { create(:user) } let_it_be(:maintainer) { create(:user) } let_it_be(:project) { create(:project) } - let_it_be(:prometheus_integration) { create(:prometheus_service, project: project) } + let_it_be(:prometheus_integration) { create(:prometheus_integration, project: project) } let_it_be(:active_http_integration) { create(:alert_management_http_integration, project: project) } let_it_be(:inactive_http_integration) { create(:alert_management_http_integration, :inactive, project: project) } let_it_be(:other_proj_integration) { create(:alert_management_http_integration) } diff --git a/spec/graphql/resolvers/alert_management/integrations_resolver_spec.rb b/spec/graphql/resolvers/alert_management/integrations_resolver_spec.rb index fb0fb6729d4..11114d41522 100644 --- a/spec/graphql/resolvers/alert_management/integrations_resolver_spec.rb +++ b/spec/graphql/resolvers/alert_management/integrations_resolver_spec.rb @@ -8,11 +8,11 @@ RSpec.describe Resolvers::AlertManagement::IntegrationsResolver do let_it_be(:current_user) { create(:user) } let_it_be(:project) { create(:project) } let_it_be(:project2) { create(:project) } - let_it_be(:prometheus_integration) { create(:prometheus_service, project: project) } + let_it_be(:prometheus_integration) { create(:prometheus_integration, project: project) } let_it_be(:active_http_integration) { create(:alert_management_http_integration, project: project) } let_it_be(:inactive_http_integration) { create(:alert_management_http_integration, :inactive, project: project) } let_it_be(:other_proj_integration) { create(:alert_management_http_integration, project: project2) } - let_it_be(:other_proj_prometheus_integration) { create(:prometheus_service, project: project2) } + let_it_be(:other_proj_prometheus_integration) { create(:prometheus_integration, project: project2) } let(:params) { {} } diff --git a/spec/graphql/resolvers/ci/config_resolver_spec.rb b/spec/graphql/resolvers/ci/config_resolver_spec.rb index 73e9fab9f99..97eee749290 100644 --- a/spec/graphql/resolvers/ci/config_resolver_spec.rb +++ b/spec/graphql/resolvers/ci/config_resolver_spec.rb @@ -15,14 +15,15 @@ RSpec.describe Resolvers::Ci::ConfigResolver do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, :repository, creator: user, namespace: user.namespace) } + let_it_be(:sha) { nil } subject(:response) do resolve(described_class, - args: { project_path: project.full_path, content: content }, + args: { project_path: project.full_path, content: content, sha: sha }, ctx: { current_user: user }) end - context 'with a valid .gitlab-ci.yml' do + shared_examples 'a valid config file' do let(:fake_result) do ::Gitlab::Ci::Lint::Result.new( merged_yaml: content, @@ -37,9 +38,22 @@ RSpec.describe Resolvers::Ci::ConfigResolver do end it 'lints the ci config file and returns the merged yaml file' do - expect(response[:merged_yaml]).to eq(content) expect(response[:status]).to eq(:valid) + expect(response[:merged_yaml]).to eq(content) expect(response[:errors]).to be_empty + expect(::Gitlab::Ci::Lint).to have_received(:new).with(current_user: user, project: project, sha: sha) + end + end + + context 'with a valid .gitlab-ci.yml' do + context 'with a sha' do + let(:sha) { '1231231' } + + it_behaves_like 'a valid config file' + end + + context 'without a sha' do + it_behaves_like 'a valid config file' end end diff --git a/spec/graphql/resolvers/ci/job_token_scope_resolver_spec.rb b/spec/graphql/resolvers/ci/job_token_scope_resolver_spec.rb new file mode 100644 index 00000000000..8522542498d --- /dev/null +++ b/spec/graphql/resolvers/ci/job_token_scope_resolver_spec.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Resolvers::Ci::JobTokenScopeResolver do + include GraphqlHelpers + + let_it_be(:current_user) { create(:user) } + let_it_be(:project) { create(:project, ci_job_token_scope_enabled: true).tap(&:save!) } + + specify do + expect(described_class).to have_nullable_graphql_type(::Types::Ci::JobTokenScopeType) + end + + subject(:resolve_scope) { resolve(described_class, ctx: { current_user: current_user }, obj: project) } + + describe '#resolve' do + context 'with access to scope' do + before do + project.add_user(current_user, :maintainer) + end + + it 'returns nil when scope is not enabled' do + allow(project).to receive(:ci_job_token_scope_enabled?).and_return(false) + + expect(resolve_scope).to eq(nil) + end + + it 'returns the same project in the allow list of projects for the Ci Job Token' do + expect(resolve_scope.all_projects).to contain_exactly(project) + end + + context 'when another projects gets added to the allow list' do + let!(:link) { create(:ci_job_token_project_scope_link, source_project: project) } + + it 'returns both projects' do + expect(resolve_scope.all_projects).to contain_exactly(project, link.target_project) + end + end + + context 'when job token scope is disabled' do + before do + project.update!(ci_job_token_scope_enabled: false) + end + + it 'returns nil' do + expect(resolve_scope).to be_nil + end + end + end + + context 'without access to scope' do + before do + project.add_user(current_user, :developer) + end + + it 'raises error' do + expect do + resolve_scope + end.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + end + end + end +end diff --git a/spec/graphql/resolvers/group_milestones_resolver_spec.rb b/spec/graphql/resolvers/group_milestones_resolver_spec.rb index 78d89054efd..acfc8313407 100644 --- a/spec/graphql/resolvers/group_milestones_resolver_spec.rb +++ b/spec/graphql/resolvers/group_milestones_resolver_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' RSpec.describe Resolvers::GroupMilestonesResolver do + using RSpec::Parameterized::TableSyntax include GraphqlHelpers describe '#resolve' do @@ -79,6 +80,24 @@ RSpec.describe Resolvers::GroupMilestonesResolver do end end + context 'by sort' do + it 'calls MilestonesFinder with correct parameters' do + expect(MilestonesFinder).to receive(:new) + .with(args(group_ids: group.id, state: 'all', sort: :due_date_desc)) + .and_call_original + + resolve_group_milestones(sort: :due_date_desc) + end + + %i[expired_last_due_date_asc expired_last_due_date_desc].each do |sort_by| + it "uses offset-pagination when sorting by #{sort_by}" do + resolved = resolve_group_milestones(sort: sort_by) + + expect(resolved).to be_a(::Gitlab::Graphql::Pagination::OffsetActiveRecordRelationConnection) + end + end + end + context 'by timeframe' do context 'when start_date and end_date are present' do context 'when start date is after end_date' do diff --git a/spec/graphql/resolvers/issues_resolver_spec.rb b/spec/graphql/resolvers/issues_resolver_spec.rb index 7c2ceb50066..9b329e961cc 100644 --- a/spec/graphql/resolvers/issues_resolver_spec.rb +++ b/spec/graphql/resolvers/issues_resolver_spec.rb @@ -290,6 +290,42 @@ RSpec.describe Resolvers::IssuesResolver do expect(resolve_issues(sort: :severity_desc).to_a).to eq([issue_high_severity, issue_low_severity, issue_no_severity]) end end + + context 'when sorting by popularity' do + let_it_be(:project) { create(:project, :public) } + let_it_be(:issue1) { create(:issue, project: project) } # has one upvote + let_it_be(:issue2) { create(:issue, project: project) } # has two upvote + let_it_be(:issue3) { create(:issue, project: project) } + let_it_be(:issue4) { create(:issue, project: project) } # has one upvote + + before do + create(:award_emoji, :upvote, awardable: issue1) + create(:award_emoji, :upvote, awardable: issue2) + create(:award_emoji, :upvote, awardable: issue2) + create(:award_emoji, :upvote, awardable: issue4) + end + + it 'sorts issues ascending (ties broken by id in desc order)' do + expect(resolve_issues(sort: :popularity_asc).to_a).to eq([issue3, issue4, issue1, issue2]) + end + + it 'sorts issues descending (ties broken by id in desc order)' do + expect(resolve_issues(sort: :popularity_desc).to_a).to eq([issue2, issue4, issue1, issue3]) + end + end + + context 'when sorting with non-stable cursors' do + %i[priority_asc priority_desc + popularity_asc popularity_desc + label_priority_asc label_priority_desc + milestone_due_asc milestone_due_desc].each do |sort_by| + it "uses offset-pagination when sorting by #{sort_by}" do + resolved = resolve_issues(sort: sort_by) + + expect(resolved).to be_a(::Gitlab::Graphql::Pagination::OffsetActiveRecordRelationConnection) + end + end + end end it 'returns issues user can see' do diff --git a/spec/graphql/resolvers/project_milestones_resolver_spec.rb b/spec/graphql/resolvers/project_milestones_resolver_spec.rb index b641a54393e..e168291c804 100644 --- a/spec/graphql/resolvers/project_milestones_resolver_spec.rb +++ b/spec/graphql/resolvers/project_milestones_resolver_spec.rb @@ -71,6 +71,24 @@ RSpec.describe Resolvers::ProjectMilestonesResolver do end end + context 'by sort' do + it 'calls MilestonesFinder with correct parameters' do + expect(MilestonesFinder).to receive(:new) + .with(args(project_ids: project.id, state: 'all', sort: :due_date_desc)) + .and_call_original + + resolve_project_milestones(sort: :due_date_desc) + end + + %i[expired_last_due_date_asc expired_last_due_date_desc].each do |sort_by| + it "uses offset-pagination when sorting by #{sort_by}" do + resolved = resolve_project_milestones(sort: sort_by) + + expect(resolved).to be_a(::Gitlab::Graphql::Pagination::OffsetActiveRecordRelationConnection) + end + end + end + context 'by timeframe' do context 'when start_date and end_date are present' do it 'calls MilestonesFinder with correct parameters' do diff --git a/spec/graphql/resolvers/projects/jira_projects_resolver_spec.rb b/spec/graphql/resolvers/projects/jira_projects_resolver_spec.rb index c375345250d..8c36153d485 100644 --- a/spec/graphql/resolvers/projects/jira_projects_resolver_spec.rb +++ b/spec/graphql/resolvers/projects/jira_projects_resolver_spec.rb @@ -22,7 +22,7 @@ RSpec.describe Resolvers::Projects::JiraProjectsResolver do end context 'when project has no Jira service' do - let_it_be(:jira_service) { nil } + let_it_be(:jira_integration) { nil } context 'when user is a maintainer' do before do @@ -34,7 +34,7 @@ RSpec.describe Resolvers::Projects::JiraProjectsResolver do end context 'when project has Jira service' do - let(:jira_service) { create(:jira_service, project: project) } + let(:jira_integration) { create(:jira_integration, project: project) } context 'when user is a developer' do before do @@ -98,6 +98,6 @@ RSpec.describe Resolvers::Projects::JiraProjectsResolver do end def resolve_jira_projects(args = {}, context = { current_user: user }) - resolve(described_class, obj: jira_service, args: args, ctx: context) + resolve(described_class, obj: jira_integration, args: args, ctx: context) end end diff --git a/spec/graphql/resolvers/projects/services_resolver_spec.rb b/spec/graphql/resolvers/projects/services_resolver_spec.rb index a1b631113b2..6da99c8448e 100644 --- a/spec/graphql/resolvers/projects/services_resolver_spec.rb +++ b/spec/graphql/resolvers/projects/services_resolver_spec.rb @@ -40,7 +40,7 @@ RSpec.describe Resolvers::Projects::ServicesResolver do context 'when project has services' do let_it_be(:project) { create(:project, :private) } - let_it_be(:jira_service) { create(:jira_service, project: project) } + let_it_be(:jira_integration) { create(:jira_integration, project: project) } context 'when user cannot access services' do context 'when anonymous user' do diff --git a/spec/graphql/resolvers/projects_resolver_spec.rb b/spec/graphql/resolvers/projects_resolver_spec.rb index 2f2aacb9ad5..2685115d1a2 100644 --- a/spec/graphql/resolvers/projects_resolver_spec.rb +++ b/spec/graphql/resolvers/projects_resolver_spec.rb @@ -27,10 +27,6 @@ RSpec.describe Resolvers::ProjectsResolver do private_group.add_developer(user) end - before do - stub_feature_flags(project_finder_similarity_sort: false) - end - context 'when user is not logged in' do let(:current_user) { nil } @@ -83,6 +79,7 @@ RSpec.describe Resolvers::ProjectsResolver do context 'when user is logged in' do let(:current_user) { user } + let(:visible_projecs) { [project, other_project, group_project, private_project, private_group_project] } context 'when no filters are applied' do it 'returns all visible projects for the user' do @@ -129,21 +126,24 @@ RSpec.describe Resolvers::ProjectsResolver do end end - context 'when sort is similarity' do + context 'when sorting' do let_it_be(:named_project1) { create(:project, :public, name: 'projAB', path: 'projAB') } let_it_be(:named_project2) { create(:project, :public, name: 'projABC', path: 'projABC') } let_it_be(:named_project3) { create(:project, :public, name: 'projA', path: 'projA') } + let_it_be(:named_projects) { [named_project1, named_project2, named_project3] } - let(:filters) { { search: 'projA', sort: 'similarity' } } - - it 'returns projects in order of similarity to search' do - stub_feature_flags(project_finder_similarity_sort: current_user) + context 'when sorting by similarity' do + let(:filters) { { search: 'projA', sort: 'similarity' } } - is_expected.to eq([named_project3, named_project1, named_project2]) + it 'returns projects in order of similarity to search' do + is_expected.to eq([named_project3, named_project1, named_project2]) + end end - it 'returns projects in any order if flag is off' do - is_expected.to match_array([named_project3, named_project1, named_project2]) + context 'when no sort is provided' do + it 'returns projects in descending order by id' do + is_expected.to match_array((visible_projecs + named_projects).sort_by { |p| p[:id]}.reverse ) + end end end |