diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/graphql/types | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/graphql/types')
34 files changed, 500 insertions, 56 deletions
diff --git a/spec/graphql/types/access_level_enum_spec.rb b/spec/graphql/types/access_level_enum_spec.rb new file mode 100644 index 00000000000..05a6d6d5545 --- /dev/null +++ b/spec/graphql/types/access_level_enum_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe GitlabSchema.types['AccessLevelEnum'] do + specify { expect(described_class.graphql_name).to eq('AccessLevelEnum') } + + it 'exposes all the existing access levels' do + expect(described_class.values.keys).to match_array(%w[NO_ACCESS GUEST REPORTER DEVELOPER MAINTAINER OWNER]) + end +end diff --git a/spec/graphql/types/access_level_type_spec.rb b/spec/graphql/types/access_level_type_spec.rb new file mode 100644 index 00000000000..b9711a9aa4b --- /dev/null +++ b/spec/graphql/types/access_level_type_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true +require 'spec_helper' + +describe GitlabSchema.types['AccessLevel'] do + specify { expect(described_class.graphql_name).to eq('AccessLevel') } + specify { expect(described_class).to require_graphql_authorizations(nil) } + + it 'has expected fields' do + expected_fields = [:integer_value, :string_value] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/alert_management/alert_type_spec.rb b/spec/graphql/types/alert_management/alert_type_spec.rb index 9c326f30e3c..5acbf8ebb7a 100644 --- a/spec/graphql/types/alert_management/alert_type_spec.rb +++ b/spec/graphql/types/alert_management/alert_type_spec.rb @@ -24,6 +24,9 @@ describe GitlabSchema.types['AlertManagementAlert'] do details created_at updated_at + assignees + notes + discussions ] expect(described_class).to have_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/base_field_spec.rb b/spec/graphql/types/base_field_spec.rb index daed5725e26..3ec33c75803 100644 --- a/spec/graphql/types/base_field_spec.rb +++ b/spec/graphql/types/base_field_spec.rb @@ -135,25 +135,6 @@ describe Types::BaseField do it 'returns true if the feature is enabled' do expect(field.visible?(context)).to eq(true) end - - context 'falsey feature_flag values' do - using RSpec::Parameterized::TableSyntax - - where(:flag, :feature_value, :visible) do - '' | false | true - '' | true | true - nil | false | true - nil | true | true - end - - with_them do - it 'returns the correct value' do - stub_feature_flags(flag => feature_value) - - expect(field.visible?(context)).to eq(visible) - end - end - end end end end diff --git a/spec/graphql/types/commit_action_mode_enum_spec.rb b/spec/graphql/types/commit_action_mode_enum_spec.rb new file mode 100644 index 00000000000..9e1a27ea254 --- /dev/null +++ b/spec/graphql/types/commit_action_mode_enum_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe GitlabSchema.types['CommitActionMode'] do + it { expect(described_class.graphql_name).to eq('CommitActionMode') } + + it 'exposes all the existing commit actions' do + expect(described_class.values.keys).to match_array(%w[CREATE UPDATE MOVE DELETE CHMOD]) + end +end diff --git a/spec/graphql/types/commit_encoding_enum_spec.rb b/spec/graphql/types/commit_encoding_enum_spec.rb new file mode 100644 index 00000000000..30686a0c712 --- /dev/null +++ b/spec/graphql/types/commit_encoding_enum_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe GitlabSchema.types['CommitEncoding'] do + it { expect(described_class.graphql_name).to eq('CommitEncoding') } + + it 'exposes all the existing encoding option' do + expect(described_class.values.keys).to match_array(%w[TEXT BASE64]) + end +end diff --git a/spec/graphql/types/container_expiration_policy_cadence_enum_spec.rb b/spec/graphql/types/container_expiration_policy_cadence_enum_spec.rb new file mode 100644 index 00000000000..08c777cd365 --- /dev/null +++ b/spec/graphql/types/container_expiration_policy_cadence_enum_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe GitlabSchema.types['ContainerExpirationPolicyCadenceEnum'] do + let_it_be(:expected_values) { %w[EVERY_DAY EVERY_WEEK EVERY_TWO_WEEKS EVERY_MONTH EVERY_THREE_MONTHS] } + + it_behaves_like 'exposing container expiration policy option', :cadence +end diff --git a/spec/graphql/types/container_expiration_policy_keep_enum_spec.rb b/spec/graphql/types/container_expiration_policy_keep_enum_spec.rb new file mode 100644 index 00000000000..1a5b4bdd3bb --- /dev/null +++ b/spec/graphql/types/container_expiration_policy_keep_enum_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe GitlabSchema.types['ContainerExpirationPolicyKeepEnum'] do + let_it_be(:expected_values) { %w[ONE_TAG FIVE_TAGS TEN_TAGS TWENTY_FIVE_TAGS FIFTY_TAGS ONE_HUNDRED_TAGS] } + + it_behaves_like 'exposing container expiration policy option', :keep_n +end diff --git a/spec/graphql/types/container_expiration_policy_older_than_enum_spec.rb b/spec/graphql/types/container_expiration_policy_older_than_enum_spec.rb new file mode 100644 index 00000000000..47f0ca22522 --- /dev/null +++ b/spec/graphql/types/container_expiration_policy_older_than_enum_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe GitlabSchema.types['ContainerExpirationPolicyOlderThanEnum'] do + let_it_be(:expected_values) { %w[SEVEN_DAYS FOURTEEN_DAYS THIRTY_DAYS NINETY_DAYS] } + + it_behaves_like 'exposing container expiration policy option', :older_than +end diff --git a/spec/graphql/types/container_expiration_policy_type_spec.rb b/spec/graphql/types/container_expiration_policy_type_spec.rb new file mode 100644 index 00000000000..8924ab67847 --- /dev/null +++ b/spec/graphql/types/container_expiration_policy_type_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe GitlabSchema.types['ContainerExpirationPolicy'] do + specify { expect(described_class.graphql_name).to eq('ContainerExpirationPolicy') } + + specify { expect(described_class.description).to eq('A tag expiration policy designed to keep only the images that matter most') } + + specify { expect(described_class).to require_graphql_authorizations(:destroy_container_image) } + + describe 'older_than field' do + subject { described_class.fields['olderThan'] } + + it 'returns older_than enum' do + is_expected.to have_graphql_type(Types::ContainerExpirationPolicyOlderThanEnum) + end + end + + describe 'keep n field' do + subject { described_class.fields['keepN'] } + + it 'returns keep enum' do + is_expected.to have_graphql_type(Types::ContainerExpirationPolicyKeepEnum) + end + end +end diff --git a/spec/graphql/types/evidence_type_spec.rb b/spec/graphql/types/evidence_type_spec.rb new file mode 100644 index 00000000000..4a11f7bcda9 --- /dev/null +++ b/spec/graphql/types/evidence_type_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe GitlabSchema.types['ReleaseEvidence'] do + it { expect(described_class).to require_graphql_authorizations(:download_code) } + + it 'has the expected fields' do + expected_fields = %w[ + id sha filepath collected_at + ] + + expect(described_class).to include_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/group_member_type_spec.rb b/spec/graphql/types/group_member_type_spec.rb new file mode 100644 index 00000000000..5d09e60d21c --- /dev/null +++ b/spec/graphql/types/group_member_type_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Types::GroupMemberType do + specify { expect(described_class).to expose_permissions_using(Types::PermissionTypes::Group) } + + specify { expect(described_class.graphql_name).to eq('GroupMember') } + + specify { expect(described_class).to require_graphql_authorizations(:read_group) } + + it 'has the expected fields' do + expected_fields = %w[ + access_level created_by created_at updated_at expires_at group + ] + + expect(described_class).to include_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/group_type_spec.rb b/spec/graphql/types/group_type_spec.rb index a834a9038db..c56cd40ef12 100644 --- a/spec/graphql/types/group_type_spec.rb +++ b/spec/graphql/types/group_type_spec.rb @@ -29,4 +29,6 @@ describe GitlabSchema.types['Group'] do is_expected.to have_graphql_type(Types::BoardType.connection_type) end end + + it_behaves_like 'a GraphQL type with labels' end diff --git a/spec/graphql/types/jira_import_type_spec.rb b/spec/graphql/types/jira_import_type_spec.rb index ac1aa672e30..fa1152aec41 100644 --- a/spec/graphql/types/jira_import_type_spec.rb +++ b/spec/graphql/types/jira_import_type_spec.rb @@ -6,6 +6,9 @@ describe GitlabSchema.types['JiraImport'] do specify { expect(described_class.graphql_name).to eq('JiraImport') } it 'has the expected fields' do - expect(described_class).to have_graphql_fields(:jira_project_key, :createdAt, :scheduled_at, :scheduled_by) + expect(described_class).to have_graphql_fields( + :jira_project_key, :created_at, :scheduled_at, :scheduled_by, + :failed_to_import_count, :imported_issues_count, :total_issue_count + ) end end diff --git a/spec/graphql/types/merge_request_type_spec.rb b/spec/graphql/types/merge_request_type_spec.rb index e7ab2100084..0f48264c99f 100644 --- a/spec/graphql/types/merge_request_type_spec.rb +++ b/spec/graphql/types/merge_request_type_spec.rb @@ -19,10 +19,11 @@ describe GitlabSchema.types['MergeRequest'] do force_remove_source_branch merge_status in_progress_merge_commit_sha merge_error allow_collaboration should_be_rebased rebase_commit_sha rebase_in_progress merge_commit_message default_merge_commit_message - merge_ongoing source_branch_exists mergeable_discussions_state web_url + merge_ongoing mergeable_discussions_state web_url + source_branch_exists target_branch_exists upvotes downvotes head_pipeline pipelines task_completion_status milestone assignees participants subscribed labels discussion_locked time_estimate - total_time_spent reference + total_time_spent reference author merged_at ] expect(described_class).to have_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/metrics/dashboard_type_spec.rb b/spec/graphql/types/metrics/dashboard_type_spec.rb index 81219c596a7..0dbd0d8b38d 100644 --- a/spec/graphql/types/metrics/dashboard_type_spec.rb +++ b/spec/graphql/types/metrics/dashboard_type_spec.rb @@ -7,7 +7,7 @@ describe GitlabSchema.types['MetricsDashboard'] do it 'has the expected fields' do expected_fields = %w[ - path annotations + path annotations schema_validation_warnings ] expect(described_class).to have_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/notes/diff_position_type_spec.rb b/spec/graphql/types/notes/diff_position_type_spec.rb index 01f355cb278..87f3810d55c 100644 --- a/spec/graphql/types/notes/diff_position_type_spec.rb +++ b/spec/graphql/types/notes/diff_position_type_spec.rb @@ -1,11 +1,22 @@ # frozen_string_literal: true + require 'spec_helper' describe GitlabSchema.types['DiffPosition'] do it 'exposes the expected fields' do - expected_fields = [:diff_refs, :file_path, :old_path, - :new_path, :position_type, :old_line, :new_line, :x, :y, - :width, :height] + expected_fields = %i[ + diff_refs + file_path + height + new_line + new_path + old_line + old_path + position_type + width + x + y + ] expect(described_class).to have_graphql_fields(*expected_fields) end diff --git a/spec/graphql/types/notes/discussion_type_spec.rb b/spec/graphql/types/notes/discussion_type_spec.rb index 44774594d17..177000b01b2 100644 --- a/spec/graphql/types/notes/discussion_type_spec.rb +++ b/spec/graphql/types/notes/discussion_type_spec.rb @@ -1,8 +1,22 @@ # frozen_string_literal: true + require 'spec_helper' describe GitlabSchema.types['Discussion'] do - specify { expect(described_class).to have_graphql_fields(:id, :created_at, :notes, :reply_id) } + it 'exposes the expected fields' do + expected_fields = %i[ + created_at + id + notes + reply_id + resolvable + resolved + resolved_at + resolved_by + ] + + expect(described_class).to have_graphql_fields(*expected_fields) + end specify { expect(described_class).to require_graphql_authorizations(:read_note) } end diff --git a/spec/graphql/types/notes/note_type_spec.rb b/spec/graphql/types/notes/note_type_spec.rb index 019f742ee77..d6cd0800234 100644 --- a/spec/graphql/types/notes/note_type_spec.rb +++ b/spec/graphql/types/notes/note_type_spec.rb @@ -1,11 +1,27 @@ # frozen_string_literal: true + require 'spec_helper' describe GitlabSchema.types['Note'] do it 'exposes the expected fields' do - expected_fields = [:id, :project, :author, :body, :created_at, - :updated_at, :discussion, :resolvable, :position, :user_permissions, - :resolved_by, :resolved_at, :system, :body_html, :confidential] + expected_fields = %i[ + author + body + body_html + confidential + created_at + discussion + id + position + project + resolvable + resolved + resolved_at + resolved_by + system + updated_at + user_permissions + ] expect(described_class).to have_graphql_fields(*expected_fields) end diff --git a/spec/graphql/types/notes/noteable_type_spec.rb b/spec/graphql/types/notes/noteable_type_spec.rb index 4a81f45bd4e..88d8eae56d1 100644 --- a/spec/graphql/types/notes/noteable_type_spec.rb +++ b/spec/graphql/types/notes/noteable_type_spec.rb @@ -1,14 +1,23 @@ # frozen_string_literal: true + require 'spec_helper' describe Types::Notes::NoteableType do - specify { expect(described_class).to have_graphql_fields(:notes, :discussions) } + it 'exposes the expected fields' do + expected_fields = %i[ + discussions + notes + ] + + expect(described_class).to have_graphql_fields(*expected_fields) + end describe ".resolve_type" do it 'knows the correct type for objects' do expect(described_class.resolve_type(build(:issue), {})).to eq(Types::IssueType) expect(described_class.resolve_type(build(:merge_request), {})).to eq(Types::MergeRequestType) expect(described_class.resolve_type(build(:design), {})).to eq(Types::DesignManagement::DesignType) + expect(described_class.resolve_type(build(:alert_management_alert), {})).to eq(Types::AlertManagement::AlertType) end end end diff --git a/spec/graphql/types/project_member_type_spec.rb b/spec/graphql/types/project_member_type_spec.rb new file mode 100644 index 00000000000..1b1f6c24a32 --- /dev/null +++ b/spec/graphql/types/project_member_type_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Types::ProjectMemberType do + specify { expect(described_class).to expose_permissions_using(Types::PermissionTypes::Project) } + + specify { expect(described_class.graphql_name).to eq('ProjectMember') } + + specify { expect(described_class).to require_graphql_authorizations(:read_project) } + + it 'has the expected fields' do + expected_fields = %w[ + access_level created_by created_at updated_at expires_at project user + ] + + 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 6368f743720..8ee9aa9cf3a 100644 --- a/spec/graphql/types/project_type_spec.rb +++ b/spec/graphql/types/project_type_spec.rb @@ -26,6 +26,7 @@ describe GitlabSchema.types['Project'] do grafanaIntegration autocloseReferencedIssues suggestion_commit_message environments boards jira_import_status jira_imports services releases release alert_management_alerts alert_management_alert alert_management_alert_status_counts + container_expiration_policy ] expect(described_class).to include_graphql_fields(*expected_fields) @@ -45,18 +46,32 @@ describe GitlabSchema.types['Project'] do it { is_expected.to have_graphql_resolver(Resolvers::IssuesResolver) } end - describe 'merge_requests field' do + describe 'merge_request field' do subject { described_class.fields['mergeRequest'] } it { is_expected.to have_graphql_type(Types::MergeRequestType) } it { is_expected.to have_graphql_resolver(Resolvers::MergeRequestsResolver.single) } + it { is_expected.to have_graphql_arguments(:iid) } end - describe 'merge_request field' do + describe 'merge_requests field' do subject { described_class.fields['mergeRequests'] } it { is_expected.to have_graphql_type(Types::MergeRequestType.connection_type) } it { is_expected.to have_graphql_resolver(Resolvers::MergeRequestsResolver) } + + it do + is_expected.to have_graphql_arguments(:iids, + :source_branches, + :target_branches, + :state, + :labels, + :before, + :after, + :first, + :last + ) + end end describe 'snippets field' do @@ -80,6 +95,13 @@ describe GitlabSchema.types['Project'] do it { is_expected.to have_graphql_resolver(Resolvers::EnvironmentsResolver) } end + describe 'members field' do + subject { described_class.fields['projectMembers'] } + + it { is_expected.to have_graphql_type(Types::ProjectMemberType.connection_type) } + it { is_expected.to have_graphql_resolver(Resolvers::ProjectMembersResolver) } + end + describe 'boards field' do subject { described_class.fields['boards'] } @@ -111,4 +133,12 @@ describe GitlabSchema.types['Project'] do it { is_expected.to have_graphql_type(Types::ReleaseType.connection_type) } it { is_expected.to have_graphql_resolver(Resolvers::ReleasesResolver) } end + + describe 'container expiration policy field' do + subject { described_class.fields['containerExpirationPolicy'] } + + it { is_expected.to have_graphql_type(Types::ContainerExpirationPolicyType) } + end + + it_behaves_like 'a GraphQL type with labels' end diff --git a/spec/graphql/types/projects/jira_project_type_spec.rb b/spec/graphql/types/projects/jira_project_type_spec.rb new file mode 100644 index 00000000000..cbb01117717 --- /dev/null +++ b/spec/graphql/types/projects/jira_project_type_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe GitlabSchema.types['JiraProject'] do + it { expect(described_class.graphql_name).to eq('JiraProject') } + + it 'has basic expected fields' do + expect(described_class).to have_graphql_fields(:key, :project_id, :name) + end +end diff --git a/spec/graphql/types/projects/jira_service_type_spec.rb b/spec/graphql/types/projects/jira_service_type_spec.rb index 91d7e4586cb..fad0c91caab 100644 --- a/spec/graphql/types/projects/jira_service_type_spec.rb +++ b/spec/graphql/types/projects/jira_service_type_spec.rb @@ -6,7 +6,7 @@ describe GitlabSchema.types['JiraService'] do specify { expect(described_class.graphql_name).to eq('JiraService') } it 'has basic expected fields' do - expect(described_class).to have_graphql_fields(:type, :active) + expect(described_class).to have_graphql_fields(:type, :active, :projects) end specify { expect(described_class).to require_graphql_authorizations(:admin_project) } diff --git a/spec/graphql/types/query_type_spec.rb b/spec/graphql/types/query_type_spec.rb index 1f269a80d00..1194391c26a 100644 --- a/spec/graphql/types/query_type_spec.rb +++ b/spec/graphql/types/query_type_spec.rb @@ -8,7 +8,18 @@ describe GitlabSchema.types['Query'] do end it 'has the expected fields' do - expected_fields = %i[project namespace group echo metadata current_user snippets design_management] + expected_fields = %i[ + project + namespace + group + echo + metadata + current_user + snippets + design_management + user + users + ] expect(described_class).to have_graphql_fields(*expected_fields).at_least end diff --git a/spec/graphql/types/release_assets_type_spec.rb b/spec/graphql/types/release_assets_type_spec.rb new file mode 100644 index 00000000000..58f0f7ee697 --- /dev/null +++ b/spec/graphql/types/release_assets_type_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe GitlabSchema.types['ReleaseAssets'] do + it { expect(described_class).to require_graphql_authorizations(:read_release) } + + it 'has the expected fields' do + expected_fields = %w[ + assets_count links sources + ] + + expect(described_class).to include_graphql_fields(*expected_fields) + end + + describe 'links field' do + subject { described_class.fields['links'] } + + it { is_expected.to have_graphql_type(Types::ReleaseLinkType.connection_type) } + end + + describe 'sources field' do + subject { described_class.fields['sources'] } + + it { is_expected.to have_graphql_type(Types::ReleaseSourceType.connection_type) } + end +end diff --git a/spec/graphql/types/release_links_type_spec.rb b/spec/graphql/types/release_links_type_spec.rb new file mode 100644 index 00000000000..49e04e120f4 --- /dev/null +++ b/spec/graphql/types/release_links_type_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe GitlabSchema.types['ReleaseLink'] do + it { expect(described_class).to require_graphql_authorizations(:read_release) } + + it 'has the expected fields' do + expected_fields = %w[ + id name url external link_type + ] + + expect(described_class).to include_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/release_source_type_spec.rb b/spec/graphql/types/release_source_type_spec.rb new file mode 100644 index 00000000000..e471ac1a5ac --- /dev/null +++ b/spec/graphql/types/release_source_type_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe GitlabSchema.types['ReleaseSource'] do + it { expect(described_class).to require_graphql_authorizations(:read_release_sources) } + + it 'has the expected fields' do + expected_fields = %w[ + format url + ] + + expect(described_class).to include_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/release_type_spec.rb b/spec/graphql/types/release_type_spec.rb index d22a0b4f0fa..feafe5ed519 100644 --- a/spec/graphql/types/release_type_spec.rb +++ b/spec/graphql/types/release_type_spec.rb @@ -9,19 +9,31 @@ describe GitlabSchema.types['Release'] do expected_fields = %w[ tag_name tag_path description description_html - name milestones author commit + name assets milestones evidences author commit created_at released_at ] expect(described_class).to include_graphql_fields(*expected_fields) end + describe 'assets field' do + subject { described_class.fields['assets'] } + + it { is_expected.to have_graphql_type(Types::ReleaseAssetsType) } + end + describe 'milestones field' do subject { described_class.fields['milestones'] } it { is_expected.to have_graphql_type(Types::MilestoneType.connection_type) } end + describe 'evidences field' do + subject { described_class.fields['evidences'] } + + it { is_expected.to have_graphql_type(Types::EvidenceType.connection_type) } + end + describe 'author field' do subject { described_class.fields['author'] } diff --git a/spec/graphql/types/resolvable_interface_spec.rb b/spec/graphql/types/resolvable_interface_spec.rb new file mode 100644 index 00000000000..231287f9969 --- /dev/null +++ b/spec/graphql/types/resolvable_interface_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Types::ResolvableInterface do + it 'exposes the expected fields' do + expected_fields = %i[ + resolvable + resolved + resolved_at + resolved_by + ] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/snippet_type_spec.rb b/spec/graphql/types/snippet_type_spec.rb index adc13d4d651..f24419ce9cc 100644 --- a/spec/graphql/types/snippet_type_spec.rb +++ b/spec/graphql/types/snippet_type_spec.rb @@ -11,11 +11,49 @@ describe GitlabSchema.types['Snippet'] do :visibility_level, :created_at, :updated_at, :web_url, :raw_url, :ssh_url_to_repo, :http_url_to_repo, :notes, :discussions, :user_permissions, - :description_html, :blob] + :description_html, :blob, :blobs] expect(described_class).to have_graphql_fields(*expected_fields) end + context 'when restricted visibility level is set to public' do + let_it_be(:snippet) { create(:personal_snippet, :repository, :public, author: user) } + + let(:current_user) { user } + let(:query) do + %( + { + snippets { + nodes { + author { + id + } + } + } + } + ) + end + let(:response) { subject.dig('data', 'snippets', 'nodes')[0] } + + subject { GitlabSchema.execute(query, context: { current_user: current_user }).as_json } + + before do + stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC]) + end + + it 'returns snippet author' do + expect(response['author']).to be_present + end + + context 'when user is not logged in' do + let(:current_user) { nil } + + it 'returns snippet author as nil' do + expect(response['author']).to be_nil + end + end + end + describe 'authorizations' do specify { expect(described_class).to require_graphql_authorizations(:read_snippet) } end @@ -76,30 +114,14 @@ describe GitlabSchema.types['Snippet'] do describe '#blob' do let(:query_blob) { subject.dig('data', 'snippets', 'edges')[0]['node']['blob'] } - let(:query) do - %( - { - snippets { - edges { - node { - blob { - name - path - } - } - } - } - } - ) - end - subject { GitlabSchema.execute(query, context: { current_user: user }).as_json } + subject { GitlabSchema.execute(snippet_query_for(field: 'blob'), context: { current_user: user }).as_json } context 'when snippet has repository' do let!(:snippet) { create(:personal_snippet, :repository, :public, author: user) } let(:blob) { snippet.blobs.first } - it 'returns blob from the repository' do + it 'returns the first blob from the repository' do expect(query_blob['name']).to eq blob.name expect(query_blob['path']).to eq blob.path end @@ -115,4 +137,58 @@ describe GitlabSchema.types['Snippet'] do end end end + + describe '#blobs' do + let_it_be(:snippet) { create(:personal_snippet, :public, author: user) } + let(:query_blobs) { subject.dig('data', 'snippets', 'edges')[0]['node']['blobs'] } + + subject { GitlabSchema.execute(snippet_query_for(field: 'blobs'), context: { current_user: user }).as_json } + + shared_examples 'an array' do + it 'returns an array of snippet blobs' do + expect(query_blobs).to be_an(Array) + end + end + + context 'when snippet does not have a repository' do + let(:blob) { snippet.blob } + + it_behaves_like 'an array' + + it 'contains the first blob from the snippet' do + expect(query_blobs.first['name']).to eq blob.name + expect(query_blobs.first['path']).to eq blob.path + end + end + + context 'when snippet has repository' do + let_it_be(:snippet) { create(:personal_snippet, :repository, :public, author: user) } + let(:blobs) { snippet.blobs } + + it_behaves_like 'an array' + + it 'contains all the blobs from the repository' do + resulting_blobs_names = query_blobs.map { |b| b['name'] } + + expect(resulting_blobs_names).to match_array(blobs.map(&:name)) + end + end + end + + def snippet_query_for(field:) + %( + { + snippets { + edges { + node { + #{field} { + name + path + } + } + } + } + } + ) + end end diff --git a/spec/graphql/types/snippets/file_input_action_enum_spec.rb b/spec/graphql/types/snippets/file_input_action_enum_spec.rb new file mode 100644 index 00000000000..2ccc8b04b8f --- /dev/null +++ b/spec/graphql/types/snippets/file_input_action_enum_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Types::Snippets::FileInputActionEnum do + specify { expect(described_class.graphql_name).to eq('SnippetFileInputActionEnum') } + + it 'exposes all file input action types' do + expect(described_class.values.keys).to eq(%w[create update delete move]) + end +end diff --git a/spec/graphql/types/snippets/file_input_type_spec.rb b/spec/graphql/types/snippets/file_input_type_spec.rb new file mode 100644 index 00000000000..62e5caf20b7 --- /dev/null +++ b/spec/graphql/types/snippets/file_input_type_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Types::Snippets::FileInputType do + specify { expect(described_class.graphql_name).to eq('SnippetFileInputType') } + + it 'has the correct arguments' do + expect(described_class.arguments.keys).to match_array(%w[filePath action previousPath content]) + end + + it 'sets the type of action argument to FileInputActionEnum' do + expect(described_class.arguments['action'].type.of_type).to eq(Types::Snippets::FileInputActionEnum) + end +end diff --git a/spec/graphql/types/user_type_spec.rb b/spec/graphql/types/user_type_spec.rb index cf1e91afb80..7b34588b0ff 100644 --- a/spec/graphql/types/user_type_spec.rb +++ b/spec/graphql/types/user_type_spec.rb @@ -9,7 +9,19 @@ describe GitlabSchema.types['User'] do it 'has the expected fields' do expected_fields = %w[ - id user_permissions snippets name username avatarUrl webUrl todos state + id + user_permissions + snippets + name + username + avatarUrl + webUrl + todos + state + authoredMergeRequests + assignedMergeRequests + groupMemberships + projectMemberships ] expect(described_class).to have_graphql_fields(*expected_fields) |