diff options
author | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 22:34:23 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 22:34:23 +0300 |
commit | 6438df3a1e0fb944485cebf07976160184697d72 (patch) | |
tree | 00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /spec/graphql/resolvers | |
parent | 42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff) |
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'spec/graphql/resolvers')
9 files changed, 98 insertions, 26 deletions
diff --git a/spec/graphql/resolvers/ci/config_resolver_spec.rb b/spec/graphql/resolvers/ci/config_resolver_spec.rb index 6911acdb4ec..ca7ae73fef8 100644 --- a/spec/graphql/resolvers/ci/config_resolver_spec.rb +++ b/spec/graphql/resolvers/ci/config_resolver_spec.rb @@ -7,16 +7,26 @@ RSpec.describe Resolvers::Ci::ConfigResolver do describe '#resolve' do before do - yaml_processor_double = instance_double(::Gitlab::Ci::YamlProcessor) - allow(yaml_processor_double).to receive(:execute).and_return(fake_result) + ci_lint_double = instance_double(::Gitlab::Ci::Lint) + allow(ci_lint_double).to receive(:validate).and_return(fake_result) - allow(::Gitlab::Ci::YamlProcessor).to receive(:new).and_return(yaml_processor_double) + allow(::Gitlab::Ci::Lint).to receive(:new).and_return(ci_lint_double) + end + + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :repository, creator: user, namespace: user.namespace) } + + subject(:response) do + resolve(described_class, + args: { project_path: project.full_path, content: content }, + ctx: { current_user: user }) 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), + ::Gitlab::Ci::Lint::Result.new( + merged_yaml: content, + jobs: [], errors: [], warnings: [] ) @@ -27,8 +37,6 @@ RSpec.describe Resolvers::Ci::ConfigResolver do 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 @@ -38,16 +46,15 @@ RSpec.describe Resolvers::Ci::ConfigResolver do let(:content) { 'invalid' } let(:fake_result) do - Gitlab::Ci::YamlProcessor::Result.new( - ci_config: nil, + Gitlab::Ci::Lint::Result.new( + jobs: [], + merged_yaml: content, 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 diff --git a/spec/graphql/resolvers/ci/jobs_resolver_spec.rb b/spec/graphql/resolvers/ci/jobs_resolver_spec.rb index 46ee74a5f7e..c44f6b623d7 100644 --- a/spec/graphql/resolvers/ci/jobs_resolver_spec.rb +++ b/spec/graphql/resolvers/ci/jobs_resolver_spec.rb @@ -5,7 +5,8 @@ require 'spec_helper' RSpec.describe Resolvers::Ci::JobsResolver do include GraphqlHelpers - let_it_be(:pipeline) { create(:ci_pipeline) } + let_it_be(:project) { create(:project, :repository, :public) } + let_it_be(:pipeline) { create(:ci_pipeline, project: project) } before_all do create(:ci_build, name: 'Normal job', pipeline: pipeline) diff --git a/spec/graphql/resolvers/issues_resolver_spec.rb b/spec/graphql/resolvers/issues_resolver_spec.rb index f6f746a8572..269ee9eabf9 100644 --- a/spec/graphql/resolvers/issues_resolver_spec.rb +++ b/spec/graphql/resolvers/issues_resolver_spec.rb @@ -264,13 +264,13 @@ RSpec.describe Resolvers::IssuesResolver do end it 'finds a specific issue with iid', :request_store do - result = batch_sync(max_queries: 2) { resolve_issues(iid: issue1.iid) } + result = batch_sync(max_queries: 4) { resolve_issues(iid: issue1.iid) } expect(result).to contain_exactly(issue1) end it 'batches queries that only include IIDs', :request_store do - result = batch_sync(max_queries: 2) do + result = batch_sync(max_queries: 4) do [issue1, issue2] .map { |issue| resolve_issues(iid: issue.iid.to_s) } .flat_map(&:to_a) @@ -280,7 +280,7 @@ RSpec.describe Resolvers::IssuesResolver do end it 'finds a specific issue with iids', :request_store do - result = batch_sync(max_queries: 2) do + result = batch_sync(max_queries: 4) do resolve_issues(iids: [issue1.iid]) end diff --git a/spec/graphql/resolvers/merge_requests_resolver_spec.rb b/spec/graphql/resolvers/merge_requests_resolver_spec.rb index 63fbd04848d..50b9243efa5 100644 --- a/spec/graphql/resolvers/merge_requests_resolver_spec.rb +++ b/spec/graphql/resolvers/merge_requests_resolver_spec.rb @@ -231,6 +231,16 @@ RSpec.describe Resolvers::MergeRequestsResolver do it 'sorts merge requests descending' do expect(resolve_mr(project, sort: :merged_at_desc)).to eq [merge_request_3, merge_request_1, merge_request_with_milestone, merge_request_6, merge_request_5, merge_request_4, merge_request_2] end + + context 'when label filter is given and the optimized_issuable_label_filter feature flag is off' do + before do + stub_feature_flags(optimized_issuable_label_filter: false) + end + + it 'does not raise PG::GroupingError' do + expect { resolve_mr(project, sort: :merged_at_desc, labels: %w[a b]) }.not_to raise_error + end + end end end end diff --git a/spec/graphql/resolvers/package_details_resolver_spec.rb b/spec/graphql/resolvers/package_details_resolver_spec.rb new file mode 100644 index 00000000000..825b2aed40a --- /dev/null +++ b/spec/graphql/resolvers/package_details_resolver_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Resolvers::PackageDetailsResolver do + include GraphqlHelpers + + let_it_be_with_reload(:project) { create(:project) } + let_it_be(:user) { project.owner } + let_it_be(:package) { create(:composer_package, project: project) } + + describe '#resolve' do + let(:args) do + { id: package.to_global_id.to_s } + end + + subject { resolve(described_class, ctx: { current_user: user }, args: args).sync } + + it { is_expected.to eq(package) } + end +end diff --git a/spec/graphql/resolvers/projects_resolver_spec.rb b/spec/graphql/resolvers/projects_resolver_spec.rb index 3de54c7e410..34ddc9cd8cb 100644 --- a/spec/graphql/resolvers/projects_resolver_spec.rb +++ b/spec/graphql/resolvers/projects_resolver_spec.rb @@ -129,7 +129,7 @@ RSpec.describe Resolvers::ProjectsResolver do let(:filters) { { search: 'projA', sort: 'similarity' } } it 'returns projects in order of similarity to search' do - stub_feature_flags(project_finder_similarity_sort: true) + stub_feature_flags(project_finder_similarity_sort: current_user) is_expected.to eq([named_project3, named_project1, named_project2]) end diff --git a/spec/graphql/resolvers/release_milestones_resolver_spec.rb b/spec/graphql/resolvers/release_milestones_resolver_spec.rb new file mode 100644 index 00000000000..5f66cba859d --- /dev/null +++ b/spec/graphql/resolvers/release_milestones_resolver_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Resolvers::ReleaseMilestonesResolver do + include GraphqlHelpers + + let_it_be(:release) { create(:release, :with_milestones, milestones_count: 2) } + + let(:resolved) do + resolve(described_class, obj: release) + end + + describe '#resolve' do + it "returns an OffsetActiveRecordRelationConnection" do + expect(resolved).to be_a(::Gitlab::Graphql::Pagination::OffsetActiveRecordRelationConnection) + end + + it "includes the release's milestones in the returned OffsetActiveRecordRelationConnection" do + expect(resolved.items).to eq(release.milestones.order_by_dates_and_title) + end + end +end diff --git a/spec/graphql/resolvers/user_notes_count_resolver_spec.rb b/spec/graphql/resolvers/user_notes_count_resolver_spec.rb index 3cb0810c698..6cf23a2f57f 100644 --- a/spec/graphql/resolvers/user_notes_count_resolver_spec.rb +++ b/spec/graphql/resolvers/user_notes_count_resolver_spec.rb @@ -44,7 +44,7 @@ RSpec.describe Resolvers::UserNotesCountResolver do context 'when a user does not have permission to view notes' do subject { batch_sync { resolve_user_notes_count(private_issue) } } - it 'returns no notes' do + it 'raises an error' do expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) end end @@ -80,7 +80,7 @@ RSpec.describe Resolvers::UserNotesCountResolver do context 'when a user does not have permission to view notes' do subject { batch_sync { resolve_user_notes_count(private_merge_request) } } - it 'returns no notes' do + it 'raises an error' do expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) end end diff --git a/spec/graphql/resolvers/users_resolver_spec.rb b/spec/graphql/resolvers/users_resolver_spec.rb index 1aa24055a89..031d7c99eef 100644 --- a/spec/graphql/resolvers/users_resolver_spec.rb +++ b/spec/graphql/resolvers/users_resolver_spec.rb @@ -27,7 +27,7 @@ RSpec.describe Resolvers::UsersResolver do context 'when both ids and usernames are passed ' do it 'raises an error' do - expect { resolve_users(ids: [user1.to_global_id.to_s], usernames: [user1.username]) } + expect { resolve_users( args: { ids: [user1.to_global_id.to_s], usernames: [user1.username] } ) } .to raise_error(Gitlab::Graphql::Errors::ArgumentError) end end @@ -35,7 +35,7 @@ RSpec.describe Resolvers::UsersResolver do context 'when a set of IDs is passed' do it 'returns those users' do expect( - resolve_users(ids: [user1.to_global_id.to_s, user2.to_global_id.to_s]) + resolve_users( args: { ids: [user1.to_global_id.to_s, user2.to_global_id.to_s] } ) ).to contain_exactly(user1, user2) end end @@ -43,21 +43,31 @@ RSpec.describe Resolvers::UsersResolver do context 'when a set of usernames is passed' do it 'returns those users' do expect( - resolve_users(usernames: [user1.username, user2.username]) + resolve_users( args: { usernames: [user1.username, user2.username] } ) ).to contain_exactly(user1, user2) end end + context 'when admins is true', :enable_admin_mode do + let(:admin_user) { create(:user, :admin) } + + it 'returns only admins' do + expect( + resolve_users( args: { admins: true }, ctx: { current_user: admin_user } ) + ).to contain_exactly(admin_user) + end + end + context 'when a search term is passed' do it 'returns all users who match', :aggregate_failures do - expect(resolve_users(search: "some")).to contain_exactly(user1, user2) - expect(resolve_users(search: "123784")).to contain_exactly(user2) - expect(resolve_users(search: "someperson")).to contain_exactly(user1) + expect(resolve_users( args: { search: "some" } )).to contain_exactly(user1, user2) + expect(resolve_users( args: { search: "123784" } )).to contain_exactly(user2) + expect(resolve_users( args: { search: "someperson" } )).to contain_exactly(user1) end end end - def resolve_users(args = {}) - resolve(described_class, args: args) + def resolve_users(args: {}, ctx: {}) + resolve(described_class, args: args, ctx: ctx) end end |