diff options
Diffstat (limited to 'spec/graphql/types')
22 files changed, 283 insertions, 23 deletions
diff --git a/spec/graphql/types/ci/pipeline_schedule_status_enum_spec.rb b/spec/graphql/types/ci/pipeline_schedule_status_enum_spec.rb index d271e72b17f..dcf37df5070 100644 --- a/spec/graphql/types/ci/pipeline_schedule_status_enum_spec.rb +++ b/spec/graphql/types/ci/pipeline_schedule_status_enum_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe Types::Ci::PipelineScheduleStatusEnum do - specify { expect(described_class.graphql_name ).to eq('PipelineScheduleStatus') } + specify { expect(described_class.graphql_name).to eq('PipelineScheduleStatus') } it 'exposes the status of a pipeline schedule' do expect(described_class.values.keys).to match_array(%w[ACTIVE INACTIVE]) diff --git a/spec/graphql/types/ci/pipeline_type_spec.rb b/spec/graphql/types/ci/pipeline_type_spec.rb index 9dee834d05f..5683b3f86c4 100644 --- a/spec/graphql/types/ci/pipeline_type_spec.rb +++ b/spec/graphql/types/ci/pipeline_type_spec.rb @@ -18,7 +18,10 @@ RSpec.describe Types::Ci::PipelineType do ] if Gitlab.ee? - expected_fields += %w[security_report_summary security_report_findings code_quality_reports dast_profile] + expected_fields += %w[ + security_report_summary security_report_findings security_report_finding + code_quality_reports dast_profile + ] end expect(described_class).to have_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/commit_signature_interface_spec.rb b/spec/graphql/types/commit_signature_interface_spec.rb new file mode 100644 index 00000000000..4962131d9b5 --- /dev/null +++ b/spec/graphql/types/commit_signature_interface_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['CommitSignature'] do + it 'exposes the expected fields' do + expect(described_class).to have_graphql_fields(:verification_status, :commit_sha, :project) + end + + describe '.resolve_type' do + it 'resolves gpg signatures' do + expect(described_class.resolve_type(build(:gpg_signature), {})).to eq( + Types::CommitSignatures::GpgSignatureType) + end + + it 'resolves x509 signatures' do + expect(described_class.resolve_type(build(:x509_commit_signature), {})).to eq( + Types::CommitSignatures::X509SignatureType) + end + + it 'raises an error when type is not known' do + expect { described_class.resolve_type(Class, {}) }.to raise_error('Unsupported commit signature type') + end + end +end diff --git a/spec/graphql/types/commit_signatures/gpg_signature_type_spec.rb b/spec/graphql/types/commit_signatures/gpg_signature_type_spec.rb new file mode 100644 index 00000000000..0b69ee169f2 --- /dev/null +++ b/spec/graphql/types/commit_signatures/gpg_signature_type_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['GpgSignature'] do + specify { expect(described_class.graphql_name).to eq('GpgSignature') } + + specify { expect(described_class).to require_graphql_authorizations(:download_code) } + + specify { expect(described_class).to include(Types::CommitSignatureInterface) } + + it 'contains attributes related to GPG signatures' do + expect(described_class).to have_graphql_fields( + :user, :verification_status, :commit_sha, :project, + :gpg_key_user_name, :gpg_key_user_email, :gpg_key_primary_keyid + ) + end +end diff --git a/spec/graphql/types/commit_signatures/verification_status_enum_spec.rb b/spec/graphql/types/commit_signatures/verification_status_enum_spec.rb new file mode 100644 index 00000000000..cb7ce19c9fc --- /dev/null +++ b/spec/graphql/types/commit_signatures/verification_status_enum_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['VerificationStatus'] do + specify { expect(described_class.graphql_name).to eq('VerificationStatus') } + + it 'exposes all signature verification states' do + expect(described_class.values.keys) + .to match_array(%w[ + UNVERIFIED UNVERIFIED_KEY VERIFIED + SAME_USER_DIFFERENT_EMAIL OTHER_USER UNKNOWN_KEY + MULTIPLE_SIGNATURES + ]) + end +end diff --git a/spec/graphql/types/commit_signatures/x509_signature_type_spec.rb b/spec/graphql/types/commit_signatures/x509_signature_type_spec.rb new file mode 100644 index 00000000000..e268bd5b3b4 --- /dev/null +++ b/spec/graphql/types/commit_signatures/x509_signature_type_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['X509Signature'] do + specify { expect(described_class.graphql_name).to eq('X509Signature') } + + specify { expect(described_class).to require_graphql_authorizations(:download_code) } + + specify { expect(described_class).to include(Types::CommitSignatureInterface) } + + it 'contains attributes related to X.509 signatures' do + expect(described_class).to have_graphql_fields( + :user, :verification_status, :commit_sha, :project, + :x509_certificate + ) + end +end diff --git a/spec/graphql/types/commit_type_spec.rb b/spec/graphql/types/commit_type_spec.rb index fe8df15028d..561d165148b 100644 --- a/spec/graphql/types/commit_type_spec.rb +++ b/spec/graphql/types/commit_type_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['Commit'] do specify { expect(described_class.graphql_name).to eq('Commit') } - specify { expect(described_class).to require_graphql_authorizations(:download_code) } + specify { expect(described_class).to require_graphql_authorizations(:read_code) } specify { expect(described_class).to include(Types::TodoableInterface) } @@ -13,7 +13,7 @@ RSpec.describe GitlabSchema.types['Commit'] do expect(described_class).to have_graphql_fields( :id, :sha, :short_id, :title, :full_title, :full_title_html, :description, :description_html, :message, :title_html, :authored_date, :author_name, :author_email, :author_gravatar, :author, :web_url, :web_path, - :pipelines, :signature_html + :pipelines, :signature_html, :signature ) end end diff --git a/spec/graphql/types/deployment_details_type_spec.rb b/spec/graphql/types/deployment_details_type_spec.rb index 70fdc38019e..7dc0c8f97ac 100644 --- a/spec/graphql/types/deployment_details_type_spec.rb +++ b/spec/graphql/types/deployment_details_type_spec.rb @@ -10,7 +10,7 @@ RSpec.describe GitlabSchema.types['DeploymentDetails'] do id iid ref tag tags sha created_at updated_at finished_at status commit job triggerer ] - expect(described_class).to have_graphql_fields(*expected_fields) + expect(described_class).to include_graphql_fields(*expected_fields) end specify { expect(described_class).to require_graphql_authorizations(:read_deployment) } diff --git a/spec/graphql/types/incident_management/timeline_event_tag_type_spec.rb b/spec/graphql/types/incident_management/timeline_event_tag_type_spec.rb new file mode 100644 index 00000000000..831a598ab66 --- /dev/null +++ b/spec/graphql/types/incident_management/timeline_event_tag_type_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['TimelineEventTagType'] do + specify { expect(described_class.graphql_name).to eq('TimelineEventTagType') } + + specify { expect(described_class).to require_graphql_authorizations(:read_incident_management_timeline_event_tag) } + + it 'exposes the expected fields' do + expected_fields = %i[ + id + name + ] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/incident_management/timeline_event_type_spec.rb b/spec/graphql/types/incident_management/timeline_event_type_spec.rb index 5a6bc461f20..6805e0cdc9b 100644 --- a/spec/graphql/types/incident_management/timeline_event_type_spec.rb +++ b/spec/graphql/types/incident_management/timeline_event_type_spec.rb @@ -21,6 +21,7 @@ RSpec.describe GitlabSchema.types['TimelineEventType'] do occurred_at created_at updated_at + timeline_event_tags ] expect(described_class).to have_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/issue_type_enum_spec.rb b/spec/graphql/types/issue_type_enum_spec.rb index 8f4b6f3bf74..cd1737c3ebb 100644 --- a/spec/graphql/types/issue_type_enum_spec.rb +++ b/spec/graphql/types/issue_type_enum_spec.rb @@ -5,9 +5,9 @@ require 'spec_helper' RSpec.describe Types::IssueTypeEnum do specify { expect(described_class.graphql_name).to eq('IssueType') } - it 'exposes all the existing issue type values' do + it 'exposes all the existing issue type values except key_result' do expect(described_class.values.keys).to match_array( - %w[ISSUE INCIDENT TEST_CASE REQUIREMENT TASK] + %w[ISSUE INCIDENT TEST_CASE REQUIREMENT TASK OBJECTIVE] ) end end diff --git a/spec/graphql/types/issue_type_spec.rb b/spec/graphql/types/issue_type_spec.rb index 2a0ae79b2c4..dc444f90627 100644 --- a/spec/graphql/types/issue_type_spec.rb +++ b/spec/graphql/types/issue_type_spec.rb @@ -17,7 +17,7 @@ RSpec.describe GitlabSchema.types['Issue'] do fields = %i[id iid title description state reference author assignees updated_by participants labels milestone due_date confidential hidden discussion_locked upvotes downvotes merge_requests_count user_notes_count user_discussions_count web_path web_url relative_position emails_disabled subscribed time_estimate total_time_spent human_time_estimate human_total_time_spent closed_at created_at updated_at task_completion_status - design_collection alert_management_alert severity current_user_todos moved moved_to + design_collection alert_management_alert alert_management_alerts severity current_user_todos moved moved_to closed_as_duplicate_of create_note_email timelogs project_id customer_relations_contacts escalation_status] fields.each do |field_name| diff --git a/spec/graphql/types/permission_types/ci/runner_spec.rb b/spec/graphql/types/permission_types/ci/runner_spec.rb index e5fbbb346e4..b4685794950 100644 --- a/spec/graphql/types/permission_types/ci/runner_spec.rb +++ b/spec/graphql/types/permission_types/ci/runner_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' RSpec.describe Types::PermissionTypes::Ci::Runner do it do expected_permissions = [ - :read_runner, :update_runner, :delete_runner + :read_runner, :update_runner, :delete_runner, :assign_runner ] expected_permissions.each do |permission| diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb index b435f3ed5ff..30fabb8e9e2 100644 --- a/spec/graphql/types/project_type_spec.rb +++ b/spec/graphql/types/project_type_spec.rb @@ -36,7 +36,8 @@ RSpec.describe GitlabSchema.types['Project'] do cluster_agent cluster_agents agent_configurations ci_template timelogs merge_commit_template squash_commit_template work_item_types recent_issue_boards ci_config_path_or_default packages_cleanup_policy ci_variables - timelog_categories fork_targets branch_rules ci_config_variables pipeline_schedules + timelog_categories fork_targets branch_rules ci_config_variables pipeline_schedules languages + incident_management_timeline_event_tags ] expect(described_class).to include_graphql_fields(*expected_fields) @@ -212,8 +213,8 @@ RSpec.describe GitlabSchema.types['Project'] do it "returns the project's sast configuration for analyzer variables" do analyzer = subject.dig('data', 'project', 'sastCiConfiguration', 'analyzers', 'nodes').first - expect(analyzer['name']).to eq('bandit') - expect(analyzer['label']).to eq('Bandit') + expect(analyzer['name']).to eq('brakeman') + expect(analyzer['label']).to eq('Brakeman') expect(analyzer['enabled']).to eq(true) end @@ -290,14 +291,14 @@ RSpec.describe GitlabSchema.types['Project'] do subject { described_class.fields['issue'] } it { is_expected.to have_graphql_type(Types::IssueType) } - it { is_expected.to have_graphql_resolver(Resolvers::IssuesResolver.single) } + it { is_expected.to have_graphql_resolver(Resolvers::ProjectIssuesResolver.single) } end describe 'issues field' do subject { described_class.fields['issues'] } it { is_expected.to have_graphql_type(Types::IssueType.connection_type) } - it { is_expected.to have_graphql_resolver(Resolvers::IssuesResolver) } + it { is_expected.to have_graphql_resolver(Resolvers::ProjectIssuesResolver) } end describe 'merge_request field' do @@ -508,6 +509,12 @@ RSpec.describe GitlabSchema.types['Project'] do it { is_expected.to have_graphql_resolver(Resolvers::Ci::JobTokenScopeResolver) } end + describe 'incident_management_timeline_event_tags field' do + subject { described_class.fields['incidentManagementTimelineEventTags'] } + + it { is_expected.to have_graphql_type(Types::IncidentManagement::TimelineEventTagType) } + end + describe 'agent_configurations' do let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user) } @@ -731,4 +738,114 @@ RSpec.describe GitlabSchema.types['Project'] do end end end + + describe 'timeline_event_tags' do + let_it_be(:user) { create(:user) } + let_it_be(:project) do + create(:project, + :private, + :repository, + creator_id: user.id, + namespace: user.namespace) + end + + let_it_be(:tag1) do + create(:incident_management_timeline_event_tag, + project: project, + name: 'Tag 1') + end + + let_it_be(:tag2) do + create(:incident_management_timeline_event_tag, + project: project, + name: 'Tag 2') + end + + let(:query) do + %( + query { + project(fullPath: "#{project.full_path}") { + incidentManagementTimelineEventTags { + name + id + } + } + } + ) + end + + let(:tags) do + subject.dig('data', 'project', 'incidentManagementTimelineEventTags') + end + + subject { GitlabSchema.execute(query, context: { current_user: user }).as_json } + + context 'when user has permissions to read project' do + before do + project.add_developer(user) + end + + it 'contains timeline event tags' do + expect(tags.count).to eq(2) + expect(tags.first['name']).to eq(tag1.name) + expect(tags.last['name']).to eq(tag2.name) + end + end + end + + describe 'languages' do + let_it_be(:user) { create(:user) } + let_it_be(:project) do + create(:project, + :private, + :repository, + creator_id: user.id, + namespace: user.namespace) + end + + let(:query) do + %( + query { + project(fullPath: "#{project.full_path}") { + languages { + name + share + color + } + } + } + ) + end + + let(:mock_languages) { [] } + + before do + allow_next_instance_of(::Projects::RepositoryLanguagesService) do |service| + allow(service).to receive(:execute).and_return(mock_languages) + end + end + + subject { GitlabSchema.execute(query, context: { current_user: user }).as_json } + + let(:languages) { subject.dig('data', 'project', 'languages') } + + context "when the languages haven't been detected yet" do + it 'returns an empty array' do + expect(languages).to eq([]) + end + end + + context 'when the languages were detected before' do + let(:mock_languages) do + [{ share: 66.69, name: "Ruby", color: "#701516" }, + { share: 22.98, name: "JavaScript", color: "#f1e05a" }, + { share: 7.91, name: "HTML", color: "#e34c26" }, + { share: 2.42, name: "CoffeeScript", color: "#244776" }] + end + + it 'returns the repository languages' do + expect(languages).to eq(mock_languages.map(&:stringify_keys)) + end + end + end end diff --git a/spec/graphql/types/projects/branch_rule_type_spec.rb b/spec/graphql/types/projects/branch_rule_type_spec.rb index 119ecf8a097..54ea4f6857b 100644 --- a/spec/graphql/types/projects/branch_rule_type_spec.rb +++ b/spec/graphql/types/projects/branch_rule_type_spec.rb @@ -12,12 +12,13 @@ RSpec.describe GitlabSchema.types['BranchRule'] do name isDefault branch_protection + matching_branches_count created_at updated_at ] end - specify { is_expected.to require_graphql_authorizations(:read_protected_branch) } + it { is_expected.to require_graphql_authorizations(:read_protected_branch) } - specify { is_expected.to have_graphql_fields(fields).at_least } + it { is_expected.to have_graphql_fields(fields).at_least } end diff --git a/spec/graphql/types/projects/repository_language_type_spec.rb b/spec/graphql/types/projects/repository_language_type_spec.rb new file mode 100644 index 00000000000..fd3e0ee4e90 --- /dev/null +++ b/spec/graphql/types/projects/repository_language_type_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::Projects::RepositoryLanguageType do + specify { expect(described_class.graphql_name).to eq('RepositoryLanguage') } + + specify do + expect(described_class).to have_graphql_fields( + :name, + :share, + :color + ) + end +end diff --git a/spec/graphql/types/release_links_type_spec.rb b/spec/graphql/types/release_links_type_spec.rb index e77c4e3ddd1..5a29050a4a2 100644 --- a/spec/graphql/types/release_links_type_spec.rb +++ b/spec/graphql/types/release_links_type_spec.rb @@ -26,31 +26,31 @@ RSpec.describe GitlabSchema.types['ReleaseLinks'] do describe 'openedMergeRequestsUrl' do it 'has valid authorization' do - expect(fetch_authorizations('openedMergeRequestsUrl')).to include(:download_code) + expect(fetch_authorizations('openedMergeRequestsUrl')).to include(:read_code) end end describe 'mergedMergeRequestsUrl' do it 'has valid authorization' do - expect(fetch_authorizations('mergedMergeRequestsUrl')).to include(:download_code) + expect(fetch_authorizations('mergedMergeRequestsUrl')).to include(:read_code) end end describe 'closedMergeRequestsUrl' do it 'has valid authorization' do - expect(fetch_authorizations('closedMergeRequestsUrl')).to include(:download_code) + expect(fetch_authorizations('closedMergeRequestsUrl')).to include(:read_code) end end describe 'openedIssuesUrl' do it 'has valid authorization' do - expect(fetch_authorizations('openedIssuesUrl')).to include(:download_code) + expect(fetch_authorizations('openedIssuesUrl')).to include(:read_code) end end describe 'closedIssuesUrl' do it 'has valid authorization' do - expect(fetch_authorizations('closedIssuesUrl')).to include(:download_code) + expect(fetch_authorizations('closedIssuesUrl')).to include(:read_code) end end diff --git a/spec/graphql/types/release_source_type_spec.rb b/spec/graphql/types/release_source_type_spec.rb index 69a1ca30dbc..52f1e3a4ff5 100644 --- a/spec/graphql/types/release_source_type_spec.rb +++ b/spec/graphql/types/release_source_type_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['ReleaseSource'] do - it { expect(described_class).to require_graphql_authorizations(:download_code) } + it { expect(described_class).to require_graphql_authorizations(:read_code) } it 'has the expected fields' do expected_fields = %w[ diff --git a/spec/graphql/types/repository_type_spec.rb b/spec/graphql/types/repository_type_spec.rb index 5488d78b720..4ff2cbcad46 100644 --- a/spec/graphql/types/repository_type_spec.rb +++ b/spec/graphql/types/repository_type_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['Repository'] do specify { expect(described_class.graphql_name).to eq('Repository') } - specify { expect(described_class).to require_graphql_authorizations(:download_code) } + specify { expect(described_class).to require_graphql_authorizations(:read_code) } specify { expect(described_class).to have_graphql_field(:root_ref) } diff --git a/spec/graphql/types/subscription_type_spec.rb b/spec/graphql/types/subscription_type_spec.rb index c23a14deaf3..04f0c72b06f 100644 --- a/spec/graphql/types/subscription_type_spec.rb +++ b/spec/graphql/types/subscription_type_spec.rb @@ -11,6 +11,7 @@ RSpec.describe GitlabSchema.types['Subscription'] do issuable_description_updated issuable_labels_updated issuable_dates_updated + issuable_milestone_updated merge_request_reviewers_updated merge_request_merge_status_updated ] diff --git a/spec/graphql/types/x509_certificate_type_spec.rb b/spec/graphql/types/x509_certificate_type_spec.rb new file mode 100644 index 00000000000..e59d1f83b28 --- /dev/null +++ b/spec/graphql/types/x509_certificate_type_spec.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['X509Certificate'] do + specify { expect(described_class.graphql_name).to eq('X509Certificate') } + + it 'contains attributes for X.509 certifcates' do + expect(described_class).to have_graphql_fields( + :certificate_status, :created_at, :email, :id, :serial_number, :subject, + :subject_key_identifier, :updated_at, :x509_issuer + ) + end +end diff --git a/spec/graphql/types/x509_issuer_type_spec.rb b/spec/graphql/types/x509_issuer_type_spec.rb new file mode 100644 index 00000000000..5446dcf07c7 --- /dev/null +++ b/spec/graphql/types/x509_issuer_type_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['X509Issuer'] do + specify { expect(described_class.graphql_name).to eq('X509Issuer') } + + it 'contains attributes for X.509 issuers' do + expect(described_class).to have_graphql_fields( + :created_at, :crl_url, :id, :subject, :subject_key_identifier, :updated_at + ) + end +end |