diff options
Diffstat (limited to 'spec/graphql')
42 files changed, 495 insertions, 211 deletions
diff --git a/spec/graphql/mutations/customer_relations/contacts/create_spec.rb b/spec/graphql/mutations/customer_relations/contacts/create_spec.rb index 21a1aa2741a..0f05504d4f2 100644 --- a/spec/graphql/mutations/customer_relations/contacts/create_spec.rb +++ b/spec/graphql/mutations/customer_relations/contacts/create_spec.rb @@ -29,7 +29,7 @@ RSpec.describe Mutations::CustomerRelations::Contacts::Create do it 'raises an error' do expect { resolve_mutation }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) - .with_message("The resource that you are attempting to access does not exist or you don't have permission to perform this action") + .with_message(Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR) end end @@ -45,7 +45,7 @@ RSpec.describe Mutations::CustomerRelations::Contacts::Create do it 'raises an error' do expect { resolve_mutation }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) - .with_message('Feature disabled') + .with_message("The resource that you are attempting to access does not exist or you don't have permission to perform this action") end end @@ -97,5 +97,5 @@ RSpec.describe Mutations::CustomerRelations::Contacts::Create do end end - specify { expect(described_class).to require_graphql_authorizations(:admin_contact) } + specify { expect(described_class).to require_graphql_authorizations(:admin_crm_contact) } end diff --git a/spec/graphql/mutations/customer_relations/contacts/update_spec.rb b/spec/graphql/mutations/customer_relations/contacts/update_spec.rb index 93bc6f53cf9..4f59de194fd 100644 --- a/spec/graphql/mutations/customer_relations/contacts/update_spec.rb +++ b/spec/graphql/mutations/customer_relations/contacts/update_spec.rb @@ -10,7 +10,7 @@ RSpec.describe Mutations::CustomerRelations::Contacts::Update do let(:last_name) { 'Smith' } let(:email) { 'ls@gitlab.com' } let(:description) { 'VIP' } - let(:does_not_exist_or_no_permission) { "The resource that you are attempting to access does not exist or you don't have permission to perform this action" } + let(:does_not_exist_or_no_permission) { Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR } let(:contact) { create(:contact, group: group) } let(:attributes) do { @@ -65,11 +65,11 @@ RSpec.describe Mutations::CustomerRelations::Contacts::Update do it 'raises an error' do expect { resolve_mutation }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) - .with_message('Feature disabled') + .with_message("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 - specify { expect(described_class).to require_graphql_authorizations(:admin_contact) } + specify { expect(described_class).to require_graphql_authorizations(:admin_crm_contact) } end diff --git a/spec/graphql/mutations/customer_relations/organizations/create_spec.rb b/spec/graphql/mutations/customer_relations/organizations/create_spec.rb index 738a8d724ab..9be0f5d4289 100644 --- a/spec/graphql/mutations/customer_relations/organizations/create_spec.rb +++ b/spec/graphql/mutations/customer_relations/organizations/create_spec.rb @@ -30,7 +30,7 @@ RSpec.describe Mutations::CustomerRelations::Organizations::Create do it 'raises an error' do expect { resolve_mutation }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) - .with_message("The resource that you are attempting to access does not exist or you don't have permission to perform this action") + .with_message(Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR) end end @@ -46,7 +46,7 @@ RSpec.describe Mutations::CustomerRelations::Organizations::Create do it 'raises an error' do expect { resolve_mutation }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) - .with_message('Feature disabled') + .with_message("The resource that you are attempting to access does not exist or you don't have permission to perform this action") end end @@ -69,5 +69,5 @@ RSpec.describe Mutations::CustomerRelations::Organizations::Create do end end - specify { expect(described_class).to require_graphql_authorizations(:admin_organization) } + specify { expect(described_class).to require_graphql_authorizations(:admin_crm_organization) } end diff --git a/spec/graphql/mutations/customer_relations/organizations/update_spec.rb b/spec/graphql/mutations/customer_relations/organizations/update_spec.rb index 0bc6f184fe3..e3aa8eafe0c 100644 --- a/spec/graphql/mutations/customer_relations/organizations/update_spec.rb +++ b/spec/graphql/mutations/customer_relations/organizations/update_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Mutations::CustomerRelations::Organizations::Update do let(:name) { 'GitLab' } let(:default_rate) { 1000.to_f } let(:description) { 'VIP' } - let(:does_not_exist_or_no_permission) { "The resource that you are attempting to access does not exist or you don't have permission to perform this action" } + let(:does_not_exist_or_no_permission) { Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR } let(:organization) { create(:organization, group: group) } let(:attributes) do { @@ -63,11 +63,11 @@ RSpec.describe Mutations::CustomerRelations::Organizations::Update do it 'raises an error' do expect { resolve_mutation }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) - .with_message('Feature disabled') + .with_message("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 - specify { expect(described_class).to require_graphql_authorizations(:admin_organization) } + specify { expect(described_class).to require_graphql_authorizations(:admin_crm_organization) } end diff --git a/spec/graphql/mutations/discussions/toggle_resolve_spec.rb b/spec/graphql/mutations/discussions/toggle_resolve_spec.rb index 8c11279a80a..2041b86d6e7 100644 --- a/spec/graphql/mutations/discussions/toggle_resolve_spec.rb +++ b/spec/graphql/mutations/discussions/toggle_resolve_spec.rb @@ -27,7 +27,7 @@ RSpec.describe Mutations::Discussions::ToggleResolve do it 'raises an error if the resource is not accessible to the user' do expect { subject }.to raise_error( Gitlab::Graphql::Errors::ResourceNotAvailable, - "The resource that you are attempting to access does not exist or you don't have permission to perform this action" + Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR ) end end @@ -41,7 +41,7 @@ RSpec.describe Mutations::Discussions::ToggleResolve do it 'raises an error' do expect { subject }.to raise_error( Gitlab::Graphql::Errors::ResourceNotAvailable, - "The resource that you are attempting to access does not exist or you don't have permission to perform this action" + Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR ) end end diff --git a/spec/graphql/mutations/environments/canary_ingress/update_spec.rb b/spec/graphql/mutations/environments/canary_ingress/update_spec.rb index 2715a908f85..48e55828a6b 100644 --- a/spec/graphql/mutations/environments/canary_ingress/update_spec.rb +++ b/spec/graphql/mutations/environments/canary_ingress/update_spec.rb @@ -60,7 +60,7 @@ RSpec.describe Mutations::Environments::CanaryIngress::Update 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") + expect { subject }.to raise_error(Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR) end end end diff --git a/spec/graphql/mutations/merge_requests/set_wip_spec.rb b/spec/graphql/mutations/merge_requests/set_wip_spec.rb deleted file mode 100644 index fae9c4f7fe0..00000000000 --- a/spec/graphql/mutations/merge_requests/set_wip_spec.rb +++ /dev/null @@ -1,55 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Mutations::MergeRequests::SetWip do - let(:merge_request) { create(:merge_request) } - let(:user) { create(:user) } - - subject(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) } - - specify { expect(described_class).to require_graphql_authorizations(:update_merge_request) } - - describe '#resolve' do - let(:wip) { true } - let(:mutated_merge_request) { subject[:merge_request] } - - subject { mutation.resolve(project_path: merge_request.project.full_path, iid: merge_request.iid, wip: wip) } - - it_behaves_like 'permission level for merge request mutation is correctly verified' - - context 'when the user can update the merge request' do - before do - merge_request.project.add_developer(user) - end - - it 'returns the merge request as a wip' do - expect(mutated_merge_request).to eq(merge_request) - expect(mutated_merge_request).to be_work_in_progress - expect(subject[:errors]).to be_empty - end - - it 'returns errors merge request could not be updated' do - # Make the merge request invalid - merge_request.allow_broken = true - merge_request.update!(source_project: nil) - - expect(subject[:errors]).not_to be_empty - end - - context 'when passing wip as false' do - let(:wip) { false } - - it 'removes `wip` from the title' do - merge_request.update!(title: "WIP: working on it") - - expect(mutated_merge_request).not_to be_work_in_progress - end - - it 'does not do anything if the title did not start with wip' do - expect(mutated_merge_request).not_to be_work_in_progress - end - end - end - end -end diff --git a/spec/graphql/mutations/notes/reposition_image_diff_note_spec.rb b/spec/graphql/mutations/notes/reposition_image_diff_note_spec.rb index e78f755d5c7..39794a070c6 100644 --- a/spec/graphql/mutations/notes/reposition_image_diff_note_spec.rb +++ b/spec/graphql/mutations/notes/reposition_image_diff_note_spec.rb @@ -29,7 +29,7 @@ RSpec.describe Mutations::Notes::RepositionImageDiffNote do it 'raises an error if the resource is not accessible to the user' do expect { subject }.to raise_error( Gitlab::Graphql::Errors::ResourceNotAvailable, - "The resource that you are attempting to access does not exist or you don't have permission to perform this action" + Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR ) end end diff --git a/spec/graphql/mutations/releases/delete_spec.rb b/spec/graphql/mutations/releases/delete_spec.rb index d97f839ce87..9934aea0031 100644 --- a/spec/graphql/mutations/releases/delete_spec.rb +++ b/spec/graphql/mutations/releases/delete_spec.rb @@ -28,7 +28,7 @@ RSpec.describe Mutations::Releases::Delete do shared_examples 'unauthorized or not found error' do it 'raises a Gitlab::Graphql::Errors::ResourceNotAvailable error' do - expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable, "The resource that you are attempting to access does not exist or you don't have permission to perform this action") + expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable, Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR) end end diff --git a/spec/graphql/mutations/releases/update_spec.rb b/spec/graphql/mutations/releases/update_spec.rb index 5ee63ac4dc2..9fae703b85a 100644 --- a/spec/graphql/mutations/releases/update_spec.rb +++ b/spec/graphql/mutations/releases/update_spec.rb @@ -232,7 +232,7 @@ RSpec.describe Mutations::Releases::Update do let(:mutation_arguments) { super().merge(project_path: 'not/a/real/path') } it 'raises an error' do - expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable, "The resource that you are attempting to access does not exist or you don't have permission to perform this action") + expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable, Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR) end end end @@ -242,7 +242,7 @@ RSpec.describe Mutations::Releases::Update do let(:current_user) { reporter } it 'raises an error' do - expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable, "The resource that you are attempting to access does not exist or you don't have permission to perform this action") + expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable, Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR) end end end diff --git a/spec/graphql/mutations/security/ci_configuration/configure_sast_iac_spec.rb b/spec/graphql/mutations/security/ci_configuration/configure_sast_iac_spec.rb new file mode 100644 index 00000000000..f16d504a4ae --- /dev/null +++ b/spec/graphql/mutations/security/ci_configuration/configure_sast_iac_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Mutations::Security::CiConfiguration::ConfigureSastIac do + include GraphqlHelpers + + let(:service) { ::Security::CiConfiguration::SastIacCreateService } + + subject { resolve(described_class, args: { project_path: project.full_path }, ctx: { current_user: user }) } + + include_examples 'graphql mutations security ci configuration' +end diff --git a/spec/graphql/resolvers/concerns/resolves_groups_spec.rb b/spec/graphql/resolvers/concerns/resolves_groups_spec.rb new file mode 100644 index 00000000000..bfbbae29e92 --- /dev/null +++ b/spec/graphql/resolvers/concerns/resolves_groups_spec.rb @@ -0,0 +1,71 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ResolvesGroups do + include GraphqlHelpers + include AfterNextHelpers + + let_it_be(:user) { create(:user) } + let_it_be(:groups) { create_pair(:group) } + + let_it_be(:resolver) do + Class.new(Resolvers::BaseResolver) do + include ResolvesGroups + type Types::GroupType, null: true + end + end + + let_it_be(:query_type) do + query_factory do |query| + query.field :groups, + Types::GroupType.connection_type, + null: true, + resolver: resolver + end + end + + let_it_be(:lookahead_fields) do + <<~FIELDS + contacts { nodes { id } } + containerRepositoriesCount + customEmoji { nodes { id } } + fullPath + organizations { nodes { id } } + path + dependencyProxyBlobCount + dependencyProxyBlobs { nodes { fileName } } + dependencyProxyImageCount + dependencyProxyImageTtlPolicy { enabled } + dependencyProxySetting { enabled } + FIELDS + end + + it 'avoids N+1 queries on the fields marked with lookahead' do + group_ids = groups.map(&:id) + + allow_next(resolver).to receive(:resolve_groups).and_return(Group.id_in(group_ids)) + # Prevent authorization queries from affecting the test. + allow(Ability).to receive(:allowed?).and_return(true) + + single_group_query = ActiveRecord::QueryRecorder.new do + data = query_groups(limit: 1) + expect(data.size).to eq(1) + end + + multi_group_query = -> { + data = query_groups(limit: 2) + expect(data.size).to eq(2) + } + + expect { multi_group_query.call }.not_to exceed_query_limit(single_group_query) + end + + def query_groups(limit:) + query_string = "{ groups(first: #{limit}) { nodes { id #{lookahead_fields} } } }" + + data = execute_query(query_type, graphql: query_string) + + graphql_dig_at(data, :data, :groups, :nodes) + end +end diff --git a/spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb b/spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb index 865e892b12d..3fcfa967452 100644 --- a/spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb +++ b/spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb @@ -20,23 +20,37 @@ RSpec.describe ResolvesPipelines do let_it_be(:project) { create(:project, :private) } let_it_be(:pipeline) { create(:ci_pipeline, project: project) } let_it_be(:failed_pipeline) { create(:ci_pipeline, :failed, project: project) } + let_it_be(:success_pipeline) { create(:ci_pipeline, :success, project: project) } let_it_be(:ref_pipeline) { create(:ci_pipeline, project: project, ref: 'awesome-feature') } let_it_be(:sha_pipeline) { create(:ci_pipeline, project: project, sha: 'deadbeef') } + let_it_be(:all_pipelines) do + [ + pipeline, + failed_pipeline, + success_pipeline, + ref_pipeline, + sha_pipeline + ] + end before do project.add_developer(current_user) end - it { is_expected.to have_graphql_arguments(:status, :ref, :sha, :source) } + it { is_expected.to have_graphql_arguments(:status, :scope, :ref, :sha, :source) } it 'finds all pipelines' do - expect(resolve_pipelines).to contain_exactly(pipeline, failed_pipeline, ref_pipeline, sha_pipeline) + expect(resolve_pipelines).to contain_exactly(*all_pipelines) end it 'allows filtering by status' do expect(resolve_pipelines(status: 'failed')).to contain_exactly(failed_pipeline) end + it 'allows filtering by scope' do + expect(resolve_pipelines(scope: 'finished')).to contain_exactly(failed_pipeline, success_pipeline) + end + it 'allows filtering by ref' do expect(resolve_pipelines(ref: 'awesome-feature')).to contain_exactly(ref_pipeline) end @@ -54,7 +68,7 @@ RSpec.describe ResolvesPipelines do end it 'does not filter by source' do - expect(resolve_pipelines(source: 'web')).to contain_exactly(pipeline, failed_pipeline, ref_pipeline, sha_pipeline, source_pipeline) + expect(resolve_pipelines(source: 'web')).to contain_exactly(*all_pipelines, source_pipeline) end end @@ -64,7 +78,7 @@ RSpec.describe ResolvesPipelines do end it 'returns all the pipelines' do - expect(resolve_pipelines).to contain_exactly(pipeline, failed_pipeline, ref_pipeline, sha_pipeline, source_pipeline) + expect(resolve_pipelines).to contain_exactly(*all_pipelines, source_pipeline) end end end diff --git a/spec/graphql/resolvers/group_issues_resolver_spec.rb b/spec/graphql/resolvers/group_issues_resolver_spec.rb index 463cdca699b..e17429560ac 100644 --- a/spec/graphql/resolvers/group_issues_resolver_spec.rb +++ b/spec/graphql/resolvers/group_issues_resolver_spec.rb @@ -29,15 +29,72 @@ RSpec.describe Resolvers::GroupIssuesResolver do describe '#resolve' do it 'finds all group issues' do - result = resolve(described_class, obj: group, ctx: { current_user: current_user }) - - expect(result).to contain_exactly(issue1, issue2, issue3) + expect(resolve_issues).to contain_exactly(issue1, issue2, issue3) end it 'finds all group and subgroup issues' do - result = resolve(described_class, obj: group, args: { include_subgroups: true }, ctx: { current_user: current_user }) + result = resolve_issues(include_subgroups: true) expect(result).to contain_exactly(issue1, issue2, issue3, subissue1, subissue2, subissue3) end + + it 'returns issues without the specified issue_type' do + result = resolve_issues(not: { types: ['issue'] }) + + expect(result).to contain_exactly(issue1) + end + + context 'confidential issues' do + let_it_be(:confidential_issue1) { create(:issue, project: project, confidential: true) } + let_it_be(:confidential_issue2) { create(:issue, project: other_project, confidential: true) } + + context "when user is allowed to view confidential issues" do + it 'returns all viewable issues by default' do + expect(resolve_issues).to contain_exactly(issue1, issue2, issue3, confidential_issue1, confidential_issue2) + end + + context 'filtering for confidential issues' do + it 'returns only the non-confidential issues for the group when filter is set to false' do + expect(resolve_issues({ confidential: false })).to contain_exactly(issue1, issue2, issue3) + end + + it "returns only the confidential issues for the group when filter is set to true" do + expect(resolve_issues({ confidential: true })).to contain_exactly(confidential_issue1, confidential_issue2) + end + end + end + + context "when user is not allowed to see confidential issues" do + before do + group.add_guest(current_user) + end + + it 'returns all viewable issues by default' do + expect(resolve_issues).to contain_exactly(issue1, issue2, issue3) + end + + context 'filtering for confidential issues' do + it 'does not return the confidential issues when filter is set to false' do + expect(resolve_issues({ confidential: false })).to contain_exactly(issue1, issue2, issue3) + end + + it 'does not return the confidential issues when filter is set to true' do + expect(resolve_issues({ confidential: true })).to be_empty + end + end + end + end + + context 'release_tag filter' do + it 'returns an error when trying to filter by negated release_tag' do + expect do + resolve_issues(not: { release_tag: ['v1.0'] }) + end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, 'releaseTag filter is not allowed when parent is a group.') + end + end + end + + def resolve_issues(args = {}, context = { current_user: current_user }) + resolve(described_class, obj: group, args: args, ctx: context) end end diff --git a/spec/graphql/resolvers/issues_resolver_spec.rb b/spec/graphql/resolvers/issues_resolver_spec.rb index 9897e697009..3c892214aaf 100644 --- a/spec/graphql/resolvers/issues_resolver_spec.rb +++ b/spec/graphql/resolvers/issues_resolver_spec.rb @@ -26,14 +26,7 @@ RSpec.describe Resolvers::IssuesResolver do expect(described_class).to have_nullable_graphql_type(Types::IssueType.connection_type) end - shared_context 'filtering for confidential issues' do - let_it_be(:confidential_issue1) { create(:issue, project: project, confidential: true) } - let_it_be(:confidential_issue2) { create(:issue, project: other_project, confidential: true) } - end - context "with a project" do - let(:obj) { project } - before_all do project.add_developer(current_user) project.add_reporter(reporter) @@ -112,6 +105,54 @@ RSpec.describe Resolvers::IssuesResolver do end end + describe 'filter by release' do + let_it_be(:milestone1) { create(:milestone, project: project, start_date: 1.day.from_now, title: 'Version 1') } + let_it_be(:milestone2) { create(:milestone, project: project, start_date: 1.day.from_now, title: 'Version 2') } + let_it_be(:milestone3) { create(:milestone, project: project, start_date: 1.day.from_now, title: 'Version 3') } + let_it_be(:release1) { create(:release, tag: 'v1.0', milestones: [milestone1], project: project) } + let_it_be(:release2) { create(:release, tag: 'v2.0', milestones: [milestone2], project: project) } + let_it_be(:release3) { create(:release, tag: 'v3.0', milestones: [milestone3], project: project) } + let_it_be(:release_issue1) { create(:issue, project: project, milestone: milestone1) } + let_it_be(:release_issue2) { create(:issue, project: project, milestone: milestone2) } + let_it_be(:release_issue3) { create(:issue, project: project, milestone: milestone3) } + + describe 'filter by release_tag' do + it 'returns all issues associated with the specified tags' do + expect(resolve_issues(release_tag: [release1.tag, release3.tag])).to contain_exactly(release_issue1, release_issue3) + end + + context 'when release_tag_wildcard_id is also provided' do + it 'raises a mutually eclusive argument error' do + expect do + resolve_issues(release_tag: [release1.tag], release_tag_wildcard_id: 'ANY') + end.to raise_error(Gitlab::Graphql::Errors::ArgumentError, 'only one of [releaseTag, releaseTagWildcardId] arguments is allowed at the same time.') + end + end + end + + describe 'filter by negated release_tag' do + it 'returns all issues not associated with the specified tags' do + expect(resolve_issues(not: { release_tag: [release1.tag, release3.tag] })).to contain_exactly(release_issue2) + end + end + + describe 'filter by release_tag_wildcard_id' do + subject { resolve_issues(release_tag_wildcard_id: wildcard_id) } + + context 'when filtering by ANY' do + let(:wildcard_id) { 'ANY' } + + it { is_expected.to contain_exactly(release_issue1, release_issue2, release_issue3) } + end + + context 'when filtering by NONE' do + let(:wildcard_id) { 'NONE' } + + it { is_expected.to contain_exactly(issue1, issue2) } + end + end + end + it 'filters by two assignees' do assignee2 = create(:user) issue2.update!(assignees: [assignee, assignee2]) @@ -230,7 +271,8 @@ RSpec.describe Resolvers::IssuesResolver do end context 'confidential issues' do - include_context 'filtering for confidential issues' + let_it_be(:confidential_issue1) { create(:issue, project: project, confidential: true) } + let_it_be(:confidential_issue2) { create(:issue, project: other_project, confidential: true) } context "when user is allowed to view confidential issues" do it 'returns all viewable issues by default' do @@ -561,64 +603,6 @@ RSpec.describe Resolvers::IssuesResolver do end end - context "with a group" do - let(:obj) { group } - - before do - group.add_developer(current_user) - end - - describe '#resolve' do - it 'finds all group issues' do - expect(resolve_issues).to contain_exactly(issue1, issue2, issue3) - end - - it 'returns issues without the specified issue_type' do - expect(resolve_issues({ not: { types: ['issue'] } })).to contain_exactly(issue1) - end - - context "confidential issues" do - include_context 'filtering for confidential issues' - - context "when user is allowed to view confidential issues" do - it 'returns all viewable issues by default' do - expect(resolve_issues).to contain_exactly(issue1, issue2, issue3, confidential_issue1, confidential_issue2) - end - - context 'filtering for confidential issues' do - it 'returns only the non-confidential issues for the group when filter is set to false' do - expect(resolve_issues({ confidential: false })).to contain_exactly(issue1, issue2, issue3) - end - - it "returns only the confidential issues for the group when filter is set to true" do - expect(resolve_issues({ confidential: true })).to contain_exactly(confidential_issue1, confidential_issue2) - end - end - end - - context "when user is not allowed to see confidential issues" do - before do - group.add_guest(current_user) - end - - it 'returns all viewable issues by default' do - expect(resolve_issues).to contain_exactly(issue1, issue2, issue3) - end - - context 'filtering for confidential issues' do - it 'does not return the confidential issues when filter is set to false' do - expect(resolve_issues({ confidential: false })).to contain_exactly(issue1, issue2, issue3) - end - - it 'does not return the confidential issues when filter is set to true' do - expect(resolve_issues({ confidential: true })).to be_empty - end - end - end - end - end - end - context "when passing a non existent, batch loaded project" do let!(:project) do BatchLoader::GraphQL.for("non-existent-path").batch do |_fake_paths, loader, _| @@ -626,8 +610,6 @@ RSpec.describe Resolvers::IssuesResolver do end end - let(:obj) { project } - it "returns nil without breaking" do expect(resolve_issues(iids: ["don't", "break"])).to be_empty end @@ -648,6 +630,6 @@ RSpec.describe Resolvers::IssuesResolver do end def resolve_issues(args = {}, context = { current_user: current_user }) - resolve(described_class, obj: obj, args: args, ctx: context) + resolve(described_class, obj: project, args: args, ctx: context) end end diff --git a/spec/graphql/resolvers/merge_requests_resolver_spec.rb b/spec/graphql/resolvers/merge_requests_resolver_spec.rb index a897acf7eba..a931b0a3f77 100644 --- a/spec/graphql/resolvers/merge_requests_resolver_spec.rb +++ b/spec/graphql/resolvers/merge_requests_resolver_spec.rb @@ -218,6 +218,54 @@ RSpec.describe Resolvers::MergeRequestsResolver do end end + context 'with created_after and created_before arguments' do + before do + merge_request_1.update!(created_at: 4.days.ago) + end + + let(:all_mrs) do + [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 merge requests created within a given period' do + result = resolve_mr(project, created_after: 5.days.ago, created_before: 2.days.ago) + + expect(result).to contain_exactly( + merge_request_1 + ) + end + + it 'returns some values filtered with created_before' do + result = resolve_mr(project, created_before: 1.day.ago) + + expect(result).to contain_exactly(merge_request_1) + end + + it 'returns some values filtered with created_after' do + result = resolve_mr(project, created_after: 3.days.ago) + + expect(result).to match_array(all_mrs - [merge_request_1]) + end + + it 'does not return anything for dates (even in the future) not matching any MRs' do + result = resolve_mr(project, created_after: 5.days.from_now) + + expect(result).to be_empty + end + + it 'does not return anything for dates not matching any MRs' do + result = resolve_mr(project, created_before: 15.days.ago) + + expect(result).to be_empty + end + + it 'does not return any values for an impossible set' do + result = resolve_mr(project, created_after: 5.days.ago, created_before: 6.days.ago) + + expect(result).to be_empty + end + end + context 'with milestone argument' do it 'filters merge requests by milestone title' do result = resolve_mr(project, milestone_title: milestone.title) diff --git a/spec/graphql/resolvers/projects/jira_projects_resolver_spec.rb b/spec/graphql/resolvers/projects/jira_projects_resolver_spec.rb index 75b9be7dfe7..c6d8c518fb7 100644 --- a/spec/graphql/resolvers/projects/jira_projects_resolver_spec.rb +++ b/spec/graphql/resolvers/projects/jira_projects_resolver_spec.rb @@ -90,7 +90,10 @@ RSpec.describe Resolvers::Projects::JiraProjectsResolver do end it 'raises failure error' do - expect { resolve_jira_projects }.to raise_error('An error occurred while requesting data from Jira: Some failure. Check your Jira integration configuration and try again.') + config_docs_link_url = Rails.application.routes.url_helpers.help_page_path('integration/jira/configure') + docs_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: config_docs_link_url } + error_message = 'An error occurred while requesting data from Jira: Some failure. Check your %{docs_link_start}Jira integration configuration</a> and try again.' % { docs_link_start: docs_link_start } + expect { resolve_jira_projects }.to raise_error(error_message) end end end diff --git a/spec/graphql/resolvers/timelog_resolver_spec.rb b/spec/graphql/resolvers/timelog_resolver_spec.rb index f45f528fe7e..9b3f555071e 100644 --- a/spec/graphql/resolvers/timelog_resolver_spec.rb +++ b/spec/graphql/resolvers/timelog_resolver_spec.rb @@ -11,6 +11,8 @@ RSpec.describe Resolvers::TimelogResolver do let_it_be(:issue) { create(:issue, project: project) } let_it_be(:error_class) { Gitlab::Graphql::Errors::ArgumentError } + let(:timelogs) { resolve_timelogs(**args) } + specify do expect(described_class).to have_non_null_graphql_type(::Types::TimelogType.connection_type) end @@ -24,8 +26,6 @@ RSpec.describe Resolvers::TimelogResolver do let(:args) { { start_time: 6.days.ago, end_time: 2.days.ago.noon } } it 'finds all timelogs within given dates' do - timelogs = resolve_timelogs(**args) - expect(timelogs).to contain_exactly(timelog1) end @@ -33,8 +33,6 @@ RSpec.describe Resolvers::TimelogResolver do let(:args) { {} } it 'finds all timelogs' do - timelogs = resolve_timelogs(**args) - expect(timelogs).to contain_exactly(timelog1, timelog2, timelog3) end end @@ -43,8 +41,6 @@ RSpec.describe Resolvers::TimelogResolver do let(:args) { { start_time: 2.days.ago.noon } } it 'finds timelogs after the start_time' do - timelogs = resolve_timelogs(**args) - expect(timelogs).to contain_exactly(timelog2) end end @@ -53,8 +49,6 @@ RSpec.describe Resolvers::TimelogResolver do let(:args) { { end_time: 2.days.ago.noon } } it 'finds timelogs before the end_time' do - timelogs = resolve_timelogs(**args) - expect(timelogs).to contain_exactly(timelog1, timelog3) end end @@ -63,8 +57,6 @@ RSpec.describe Resolvers::TimelogResolver do let(:args) { { start_time: 6.days.ago, end_date: 2.days.ago } } it 'finds timelogs until the end of day of end_date' do - timelogs = resolve_timelogs(**args) - expect(timelogs).to contain_exactly(timelog1, timelog2) end end @@ -73,8 +65,6 @@ RSpec.describe Resolvers::TimelogResolver do let(:args) { { start_date: 6.days.ago, end_time: 2.days.ago.noon } } it 'finds all timelogs within start_date and end_time' do - timelogs = resolve_timelogs(**args) - expect(timelogs).to contain_exactly(timelog1) end end @@ -96,7 +86,7 @@ RSpec.describe Resolvers::TimelogResolver do let(:args) { { start_time: 6.days.ago, start_date: 6.days.ago } } it 'returns correct error' do - expect { resolve_timelogs(**args) } + expect { timelogs } .to raise_error(error_class, /Provide either a start date or time, but not both/) end end @@ -105,7 +95,7 @@ RSpec.describe Resolvers::TimelogResolver do let(:args) { { end_time: 2.days.ago, end_date: 2.days.ago } } it 'returns correct error' do - expect { resolve_timelogs(**args) } + expect { timelogs } .to raise_error(error_class, /Provide either an end date or time, but not both/) end end @@ -114,14 +104,14 @@ RSpec.describe Resolvers::TimelogResolver do let(:args) { { start_time: 2.days.ago, end_time: 6.days.ago } } it 'returns correct error' do - expect { resolve_timelogs(**args) } + expect { timelogs } .to raise_error(error_class, /Start argument must be before End argument/) end end end end - shared_examples "with a group" do + shared_examples 'with a group' do let_it_be(:short_time_ago) { 5.days.ago.beginning_of_day } let_it_be(:medium_time_ago) { 15.days.ago.beginning_of_day } @@ -141,8 +131,6 @@ RSpec.describe Resolvers::TimelogResolver do end it 'finds all timelogs within given dates' do - timelogs = resolve_timelogs(**args) - expect(timelogs).to contain_exactly(timelog1) end @@ -150,8 +138,6 @@ RSpec.describe Resolvers::TimelogResolver do let(:args) { { start_date: short_time_ago } } it 'finds timelogs until the end of day of end_date' do - timelogs = resolve_timelogs(**args) - expect(timelogs).to contain_exactly(timelog1, timelog2) end end @@ -160,8 +146,6 @@ RSpec.describe Resolvers::TimelogResolver do let(:args) { { end_date: medium_time_ago } } it 'finds timelogs until the end of day of end_date' do - timelogs = resolve_timelogs(**args) - expect(timelogs).to contain_exactly(timelog3) end end @@ -170,8 +154,6 @@ RSpec.describe Resolvers::TimelogResolver do let(:args) { { start_time: short_time_ago, end_date: short_time_ago } } it 'finds timelogs until the end of day of end_date' do - timelogs = resolve_timelogs(**args) - expect(timelogs).to contain_exactly(timelog1, timelog2) end end @@ -180,8 +162,6 @@ RSpec.describe Resolvers::TimelogResolver do let(:args) { { start_date: short_time_ago, end_time: short_time_ago.noon } } it 'finds all timelogs within start_date and end_time' do - timelogs = resolve_timelogs(**args) - expect(timelogs).to contain_exactly(timelog1) end end @@ -191,7 +171,7 @@ RSpec.describe Resolvers::TimelogResolver do let(:args) { { start_time: short_time_ago, start_date: short_time_ago } } it 'returns correct error' do - expect { resolve_timelogs(**args) } + expect { timelogs } .to raise_error(error_class, /Provide either a start date or time, but not both/) end end @@ -200,7 +180,7 @@ RSpec.describe Resolvers::TimelogResolver do let(:args) { { end_time: short_time_ago, end_date: short_time_ago } } it 'returns correct error' do - expect { resolve_timelogs(**args) } + expect { timelogs } .to raise_error(error_class, /Provide either an end date or time, but not both/) end end @@ -209,14 +189,14 @@ RSpec.describe Resolvers::TimelogResolver do let(:args) { { start_time: short_time_ago, end_time: medium_time_ago } } it 'returns correct error' do - expect { resolve_timelogs(**args) } + expect { timelogs } .to raise_error(error_class, /Start argument must be before End argument/) end end end end - shared_examples "with a user" do + shared_examples 'with a user' do let_it_be(:short_time_ago) { 5.days.ago.beginning_of_day } let_it_be(:medium_time_ago) { 15.days.ago.beginning_of_day } @@ -228,20 +208,18 @@ RSpec.describe Resolvers::TimelogResolver do let_it_be(:timelog3) { create(:merge_request_timelog, merge_request: merge_request, user: current_user) } it 'blah' do - timelogs = resolve_timelogs(**args) - expect(timelogs).to contain_exactly(timelog1, timelog3) end end - context "on a project" do + context 'on a project' do let(:object) { project } let(:extra_args) { {} } it_behaves_like 'with a project' end - context "with a project filter" do + context 'with a project filter' do let(:object) { nil } let(:extra_args) { { project_id: project.to_global_id } } @@ -285,8 +263,6 @@ RSpec.describe Resolvers::TimelogResolver do let(:extra_args) { {} } it 'pagination returns `default_max_page_size` and sets `has_next_page` true' do - timelogs = resolve_timelogs(**args) - expect(timelogs.items.count).to be(100) expect(timelogs.has_next_page).to be(true) end @@ -298,7 +274,7 @@ RSpec.describe Resolvers::TimelogResolver do let(:extra_args) { {} } it 'returns correct error' do - expect { resolve_timelogs(**args) } + expect { timelogs } .to raise_error(error_class, /Provide at least one argument/) end end diff --git a/spec/graphql/resolvers/topics_resolver_spec.rb b/spec/graphql/resolvers/topics_resolver_spec.rb new file mode 100644 index 00000000000..3ff1dabc927 --- /dev/null +++ b/spec/graphql/resolvers/topics_resolver_spec.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Resolvers::TopicsResolver do + include GraphqlHelpers + + describe '#resolve' do + let!(:topic1) { create(:topic, name: 'GitLab', total_projects_count: 1) } + let!(:topic2) { create(:topic, name: 'git', total_projects_count: 2) } + let!(:topic3) { create(:topic, name: 'topic3', total_projects_count: 3) } + + it 'finds all topics' do + expect(resolve_topics).to eq([topic3, topic2, topic1]) + end + + context 'with search' do + it 'searches environment by name' do + expect(resolve_topics(search: 'git')).to eq([topic2, topic1]) + end + + context 'when the search term does not match any topic' do + it 'is empty' do + expect(resolve_topics(search: 'nonsense')).to be_empty + end + end + end + end + + def resolve_topics(args = {}) + resolve(described_class, args: args) + end +end 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 31cf94aef44..bfb6958e327 100644 --- a/spec/graphql/types/alert_management/prometheus_integration_type_spec.rb +++ b/spec/graphql/types/alert_management/prometheus_integration_type_spec.rb @@ -50,7 +50,7 @@ RSpec.describe GitlabSchema.types['AlertManagementPrometheusIntegration'] do describe 'a group integration' do let_it_be(:group) { create(:group) } - let_it_be(:integration) { create(:prometheus_integration, project: nil, group: group) } + let_it_be(:integration) { create(:prometheus_integration, :group, group: group) } # Since it is impossible to authorize the parent here, given that the # project is nil, all fields should be redacted: diff --git a/spec/graphql/types/ci/job_artifact_type_spec.rb b/spec/graphql/types/ci/job_artifact_type_spec.rb index d4dc5ef214d..58b5f9cfcb7 100644 --- a/spec/graphql/types/ci/job_artifact_type_spec.rb +++ b/spec/graphql/types/ci/job_artifact_type_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['CiJobArtifact'] do it 'has the correct fields' do - expected_fields = [:download_path, :file_type] + expected_fields = [:download_path, :file_type, :name] expect(described_class).to have_graphql_fields(*expected_fields) end diff --git a/spec/graphql/types/ci/pipeline_scope_enum_spec.rb b/spec/graphql/types/ci/pipeline_scope_enum_spec.rb new file mode 100644 index 00000000000..9dc6e5c6fae --- /dev/null +++ b/spec/graphql/types/ci/pipeline_scope_enum_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::Ci::PipelineScopeEnum do + it 'exposes all pipeline scopes' do + expect(described_class.values.keys).to contain_exactly( + *::Ci::PipelinesFinder::ALLOWED_SCOPES.keys.map(&:to_s) + ) + end +end diff --git a/spec/graphql/types/ci/pipeline_status_enum_spec.rb b/spec/graphql/types/ci/pipeline_status_enum_spec.rb new file mode 100644 index 00000000000..2d6683c6384 --- /dev/null +++ b/spec/graphql/types/ci/pipeline_status_enum_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::Ci::PipelineStatusEnum do + it 'exposes all pipeline states' do + expect(described_class.values.keys).to contain_exactly( + *::Ci::Pipeline.all_state_names.map(&:to_s).map(&:upcase) + ) + end +end diff --git a/spec/graphql/types/ci/pipeline_type_spec.rb b/spec/graphql/types/ci/pipeline_type_spec.rb index 8c849114cf6..58724524785 100644 --- a/spec/graphql/types/ci/pipeline_type_spec.rb +++ b/spec/graphql/types/ci/pipeline_type_spec.rb @@ -12,8 +12,8 @@ RSpec.describe Types::Ci::PipelineType do id iid sha before_sha complete status detailed_status config_source duration queued_duration coverage created_at updated_at started_at finished_at committed_at - stages user retryable cancelable jobs source_job job downstream - upstream path project active user_permissions warnings commit_path uses_needs + stages user retryable cancelable jobs source_job job job_artifacts downstream + upstream path project active user_permissions warnings commit commit_path uses_needs test_report_summary test_suite ref ] diff --git a/spec/graphql/types/commit_type_spec.rb b/spec/graphql/types/commit_type_spec.rb index b43693e5804..2f74ce81761 100644 --- a/spec/graphql/types/commit_type_spec.rb +++ b/spec/graphql/types/commit_type_spec.rb @@ -9,7 +9,7 @@ RSpec.describe GitlabSchema.types['Commit'] do it 'contains attributes related to commit' do expect(described_class).to have_graphql_fields( - :id, :sha, :short_id, :title, :description, :description_html, :message, :title_html, :authored_date, + :id, :sha, :short_id, :title, :full_title, :full_title_html, :description, :description_html, :message, :title_html, :authored_date, :author_name, :author_gravatar, :author, :web_url, :web_path, :pipelines, :signature_html ) diff --git a/spec/graphql/types/customer_relations/contact_type_spec.rb b/spec/graphql/types/customer_relations/contact_type_spec.rb index a51ee705fb0..bb447f405b6 100644 --- a/spec/graphql/types/customer_relations/contact_type_spec.rb +++ b/spec/graphql/types/customer_relations/contact_type_spec.rb @@ -7,5 +7,5 @@ RSpec.describe GitlabSchema.types['CustomerRelationsContact'] do it { expect(described_class.graphql_name).to eq('CustomerRelationsContact') } it { expect(described_class).to have_graphql_fields(fields) } - it { expect(described_class).to require_graphql_authorizations(:read_contact) } + it { expect(described_class).to require_graphql_authorizations(:read_crm_contact) } end diff --git a/spec/graphql/types/customer_relations/organization_type_spec.rb b/spec/graphql/types/customer_relations/organization_type_spec.rb index 2562748477c..93844df1239 100644 --- a/spec/graphql/types/customer_relations/organization_type_spec.rb +++ b/spec/graphql/types/customer_relations/organization_type_spec.rb @@ -7,5 +7,5 @@ RSpec.describe GitlabSchema.types['CustomerRelationsOrganization'] do it { expect(described_class.graphql_name).to eq('CustomerRelationsOrganization') } it { expect(described_class).to have_graphql_fields(fields) } - it { expect(described_class).to require_graphql_authorizations(:read_organization) } + it { expect(described_class).to require_graphql_authorizations(:read_crm_organization) } end diff --git a/spec/graphql/types/dependency_proxy/manifest_type_spec.rb b/spec/graphql/types/dependency_proxy/manifest_type_spec.rb index 18cc89adfcb..b251ca63c4f 100644 --- a/spec/graphql/types/dependency_proxy/manifest_type_spec.rb +++ b/spec/graphql/types/dependency_proxy/manifest_type_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['DependencyProxyManifest'] do it 'includes dependency proxy manifest fields' do expected_fields = %w[ - file_name image_name size created_at updated_at digest + id file_name image_name size created_at updated_at digest ] expect(described_class).to include_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/evidence_type_spec.rb b/spec/graphql/types/evidence_type_spec.rb index 92134e74d51..be85724eac5 100644 --- a/spec/graphql/types/evidence_type_spec.rb +++ b/spec/graphql/types/evidence_type_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['ReleaseEvidence'] do - it { expect(described_class).to require_graphql_authorizations(:download_code) } + specify { expect(described_class).to require_graphql_authorizations(:read_release_evidence) } it 'has the expected fields' do expected_fields = %w[ diff --git a/spec/graphql/types/merge_request_review_state_enum_spec.rb b/spec/graphql/types/merge_request_review_state_enum_spec.rb index 486e1c4f502..407a1ae3c1f 100644 --- a/spec/graphql/types/merge_request_review_state_enum_spec.rb +++ b/spec/graphql/types/merge_request_review_state_enum_spec.rb @@ -12,6 +12,10 @@ RSpec.describe GitlabSchema.types['MergeRequestReviewState'] do 'UNREVIEWED' => have_attributes( description: 'The merge request is unreviewed.', value: 'unreviewed' + ), + 'ATTENTION_REQUESTED' => have_attributes( + description: 'The merge request is attention_requested.', + value: 'attention_requested' ) ) end diff --git a/spec/graphql/types/merge_request_type_spec.rb b/spec/graphql/types/merge_request_type_spec.rb index bc3ccb0d9ba..b17b7c32289 100644 --- a/spec/graphql/types/merge_request_type_spec.rb +++ b/spec/graphql/types/merge_request_type_spec.rb @@ -18,7 +18,7 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do notes discussions user_permissions id iid title title_html description description_html state created_at updated_at source_project target_project project project_id source_project_id target_project_id source_branch - target_branch work_in_progress draft merge_when_pipeline_succeeds diff_head_sha + target_branch draft merge_when_pipeline_succeeds diff_head_sha merge_commit_sha user_notes_count user_discussions_count should_remove_source_branch diff_refs diff_stats diff_stats_summary force_remove_source_branch diff --git a/spec/graphql/types/mutation_type_spec.rb b/spec/graphql/types/mutation_type_spec.rb index c1a5c93c85b..95d835c88cf 100644 --- a/spec/graphql/types/mutation_type_spec.rb +++ b/spec/graphql/types/mutation_type_spec.rb @@ -3,14 +3,6 @@ require 'spec_helper' RSpec.describe Types::MutationType do - it 'is expected to have the deprecated MergeRequestSetWip' do - field = get_field('MergeRequestSetWip') - - expect(field).to be_present - expect(field.deprecation_reason).to be_present - expect(field.resolver).to eq(Mutations::MergeRequests::SetWip) - end - it 'is expected to have the MergeRequestSetDraft' do expect(described_class).to have_graphql_mutation(Mutations::MergeRequests::SetDraft) end diff --git a/spec/graphql/types/packages/helm/dependency_type_spec.rb b/spec/graphql/types/packages/helm/dependency_type_spec.rb new file mode 100644 index 00000000000..2047205275f --- /dev/null +++ b/spec/graphql/types/packages/helm/dependency_type_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['PackageHelmDependencyType'] do + it { expect(described_class.graphql_name).to eq('PackageHelmDependencyType') } + + it 'includes helm dependency fields' do + expected_fields = %w[ + name version repository condition tags enabled import_values alias + ] + + expect(described_class).to include_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/packages/helm/file_metadatum_type_spec.rb b/spec/graphql/types/packages/helm/file_metadatum_type_spec.rb new file mode 100644 index 00000000000..b7bcd6213b4 --- /dev/null +++ b/spec/graphql/types/packages/helm/file_metadatum_type_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['HelmFileMetadata'] do + it { expect(described_class.graphql_name).to eq('HelmFileMetadata') } + + it 'includes helm file metadatum fields' do + expected_fields = %w[ + created_at updated_at channel metadata + ] + + expect(described_class).to include_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/packages/helm/maintainer_type_spec.rb b/spec/graphql/types/packages/helm/maintainer_type_spec.rb new file mode 100644 index 00000000000..9ad51427d42 --- /dev/null +++ b/spec/graphql/types/packages/helm/maintainer_type_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['PackageHelmMaintainerType'] do + it { expect(described_class.graphql_name).to eq('PackageHelmMaintainerType') } + + it 'includes helm maintainer fields' do + expected_fields = %w[ + name email url + ] + + expect(described_class).to include_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/packages/helm/metadata_type_spec.rb b/spec/graphql/types/packages/helm/metadata_type_spec.rb new file mode 100644 index 00000000000..04639450d9a --- /dev/null +++ b/spec/graphql/types/packages/helm/metadata_type_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['PackageHelmMetadataType'] do + it { expect(described_class.graphql_name).to eq('PackageHelmMetadataType') } + + it 'includes helm json fields' do + expected_fields = %w[ + name home sources version description keywords maintainers icon apiVersion condition tags appVersion deprecated annotations kubeVersion dependencies type + ] + + expect(described_class).to include_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb index 45a718683be..4f205e861dd 100644 --- a/spec/graphql/types/project_type_spec.rb +++ b/spec/graphql/types/project_type_spec.rb @@ -34,7 +34,7 @@ RSpec.describe GitlabSchema.types['Project'] do container_repositories container_repositories_count pipeline_analytics squash_read_only sast_ci_configuration cluster_agent cluster_agents agent_configurations - ci_template timelogs + ci_template timelogs merge_commit_template ] expect(described_class).to include_graphql_fields(*expected_fields) @@ -296,6 +296,8 @@ RSpec.describe GitlabSchema.types['Project'] do :last, :merged_after, :merged_before, + :created_after, + :created_before, :author_username, :assignee_username, :reviewer_username, diff --git a/spec/graphql/types/projects/topic_type_spec.rb b/spec/graphql/types/projects/topic_type_spec.rb new file mode 100644 index 00000000000..01c19e111be --- /dev/null +++ b/spec/graphql/types/projects/topic_type_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::Projects::TopicType do + specify { expect(described_class.graphql_name).to eq('Topic') } + + specify do + expect(described_class).to have_graphql_fields( + :id, + :name, + :description, + :description_html, + :avatar_url + ) + end +end diff --git a/spec/graphql/types/query_type_spec.rb b/spec/graphql/types/query_type_spec.rb index 14ef03a64f9..49f0980bd08 100644 --- a/spec/graphql/types/query_type_spec.rb +++ b/spec/graphql/types/query_type_spec.rb @@ -28,6 +28,7 @@ RSpec.describe GitlabSchema.types['Query'] do runners timelogs board_list + topics ] expect(described_class).to have_graphql_fields(*expected_fields).at_least diff --git a/spec/graphql/types/release_links_type_spec.rb b/spec/graphql/types/release_links_type_spec.rb index 38c38d58baa..e77c4e3ddd1 100644 --- a/spec/graphql/types/release_links_type_spec.rb +++ b/spec/graphql/types/release_links_type_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['ReleaseLinks'] do - it { expect(described_class).to require_graphql_authorizations(:download_code) } + it { expect(described_class).to require_graphql_authorizations(:read_release) } it 'has the expected fields' do expected_fields = %w[ @@ -18,4 +18,46 @@ RSpec.describe GitlabSchema.types['ReleaseLinks'] do expect(described_class).to include_graphql_fields(*expected_fields) end + + context 'individual field authorization' do + def fetch_authorizations(field_name) + described_class.fields.dig(field_name).instance_variable_get(:@authorize) + end + + describe 'openedMergeRequestsUrl' do + it 'has valid authorization' do + expect(fetch_authorizations('openedMergeRequestsUrl')).to include(:download_code) + end + end + + describe 'mergedMergeRequestsUrl' do + it 'has valid authorization' do + expect(fetch_authorizations('mergedMergeRequestsUrl')).to include(:download_code) + end + end + + describe 'closedMergeRequestsUrl' do + it 'has valid authorization' do + expect(fetch_authorizations('closedMergeRequestsUrl')).to include(:download_code) + end + end + + describe 'openedIssuesUrl' do + it 'has valid authorization' do + expect(fetch_authorizations('openedIssuesUrl')).to include(:download_code) + end + end + + describe 'closedIssuesUrl' do + it 'has valid authorization' do + expect(fetch_authorizations('closedIssuesUrl')).to include(:download_code) + end + end + + describe 'editUrl' do + it 'has valid authorization' do + expect(fetch_authorizations('editUrl')).to include(:update_release) + end + end + end end diff --git a/spec/graphql/types/repository/blob_type_spec.rb b/spec/graphql/types/repository/blob_type_spec.rb index beab4dcebc2..7f37237f355 100644 --- a/spec/graphql/types/repository/blob_type_spec.rb +++ b/spec/graphql/types/repository/blob_type_spec.rb @@ -23,6 +23,7 @@ RSpec.describe Types::Repository::BlobType do :stored_externally, :raw_path, :replace_path, + :pipeline_editor_path, :simple_viewer, :rich_viewer, :plain_data, diff --git a/spec/graphql/types/user_merge_request_interaction_type_spec.rb b/spec/graphql/types/user_merge_request_interaction_type_spec.rb index f424c9200ab..1eaaa0c23d0 100644 --- a/spec/graphql/types/user_merge_request_interaction_type_spec.rb +++ b/spec/graphql/types/user_merge_request_interaction_type_spec.rb @@ -78,7 +78,7 @@ RSpec.describe GitlabSchema.types['UserMergeRequestInteraction'] do merge_request.reviewers << user end - it { is_expected.to eq(Types::MergeRequestReviewStateEnum.values['UNREVIEWED'].value) } + it { is_expected.to eq(Types::MergeRequestReviewStateEnum.values['ATTENTION_REQUESTED'].value) } it 'implies not reviewed' do expect(resolve(:reviewed)).to be false @@ -87,7 +87,8 @@ RSpec.describe GitlabSchema.types['UserMergeRequestInteraction'] do context 'when the user has provided a review' do before do - merge_request.merge_request_reviewers.create!(reviewer: user, state: MergeRequestReviewer.states['reviewed']) + reviewer = merge_request.merge_request_reviewers.create!(reviewer: user) + reviewer.update!(state: MergeRequestReviewer.states['reviewed']) end it { is_expected.to eq(Types::MergeRequestReviewStateEnum.values['REVIEWED'].value) } |