diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /spec/graphql/types | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'spec/graphql/types')
20 files changed, 192 insertions, 65 deletions
diff --git a/spec/graphql/types/admin/analytics/instance_statistics/measurement_identifier_enum_spec.rb b/spec/graphql/types/admin/analytics/instance_statistics/measurement_identifier_enum_spec.rb new file mode 100644 index 00000000000..625fb17bbf8 --- /dev/null +++ b/spec/graphql/types/admin/analytics/instance_statistics/measurement_identifier_enum_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['MeasurementIdentifier'] do + specify { expect(described_class.graphql_name).to eq('MeasurementIdentifier') } + + it 'exposes all the existing identifier values' do + identifiers = Analytics::InstanceStatistics::Measurement.identifiers.keys.map(&:upcase) + + expect(described_class.values.keys).to match_array(identifiers) + end +end diff --git a/spec/graphql/types/admin/analytics/instance_statistics/measurement_type_spec.rb b/spec/graphql/types/admin/analytics/instance_statistics/measurement_type_spec.rb new file mode 100644 index 00000000000..de8143a5466 --- /dev/null +++ b/spec/graphql/types/admin/analytics/instance_statistics/measurement_type_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['InstanceStatisticsMeasurement'] do + subject { described_class } + + it { is_expected.to have_graphql_field(:recorded_at) } + it { is_expected.to have_graphql_field(:identifier) } + it { is_expected.to have_graphql_field(:count) } +end diff --git a/spec/graphql/types/base_enum_spec.rb b/spec/graphql/types/base_enum_spec.rb index 0d0f6346f2d..b7adcf217f6 100644 --- a/spec/graphql/types/base_enum_spec.rb +++ b/spec/graphql/types/base_enum_spec.rb @@ -21,4 +21,16 @@ RSpec.describe Types::BaseEnum do expect(enum.enum).to be_a(HashWithIndifferentAccess) end end + + include_examples 'Gitlab-style deprecations' do + def subject(args = {}) + enum = Class.new(described_class) do + graphql_name 'TestEnum' + + value 'TEST_VALUE', **args + end + + enum.to_graphql.values['TEST_VALUE'] + end + end end diff --git a/spec/graphql/types/base_field_spec.rb b/spec/graphql/types/base_field_spec.rb index 73bb54e7ad0..bcfbd7f2480 100644 --- a/spec/graphql/types/base_field_spec.rb +++ b/spec/graphql/types/base_field_spec.rb @@ -167,70 +167,23 @@ RSpec.describe Types::BaseField do end end - describe '`deprecated` property' do - def test_field(args = {}) + include_examples 'Gitlab-style deprecations' do + def subject(args = {}) base_args = { name: 'test', type: GraphQL::STRING_TYPE, null: true } described_class.new(**base_args.merge(args)) end - describe 'validations' do - it 'raises an informative error if `deprecation_reason` is used' do - expect { test_field(deprecation_reason: 'foo') }.to raise_error( - ArgumentError, - 'Use `deprecated` property instead of `deprecation_reason`. ' \ - 'See https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#deprecating-fields' - ) - end - - it 'raises an error if a required property is missing', :aggregate_failures do - expect { test_field(deprecated: { milestone: '1.10' }) }.to raise_error( - ArgumentError, - 'Please provide a `reason` within `deprecated`' - ) - expect { test_field(deprecated: { reason: 'Deprecation reason' }) }.to raise_error( - ArgumentError, - 'Please provide a `milestone` within `deprecated`' - ) - end - - it 'raises an error if milestone is not a String', :aggregate_failures do - expect { test_field(deprecated: { milestone: 1.10, reason: 'Deprecation reason' }) }.to raise_error( - ArgumentError, - '`milestone` must be a `String`' - ) - end - end - - it 'adds a formatted `deprecated_reason` to the field' do - field = test_field(deprecated: { milestone: '1.10', reason: 'Deprecation reason' }) - - expect(field.deprecation_reason).to eq('Deprecation reason. Deprecated in 1.10') - end - - it 'appends to the description if given' do - field = test_field( - deprecated: { milestone: '1.10', reason: 'Deprecation reason' }, - description: 'Field description' - ) - - expect(field.description).to eq('Field description. Deprecated in 1.10: Deprecation reason') - end - - it 'does not append to the description if it is absent' do - field = test_field(deprecated: { milestone: '1.10', reason: 'Deprecation reason' }) - - expect(field.description).to be_nil - end - it 'interacts well with the `feature_flag` property' do - field = test_field( + field = subject( deprecated: { milestone: '1.10', reason: 'Deprecation reason' }, description: 'Field description', feature_flag: 'foo_flag' ) - expect(field.description).to eq('Field description. Available only when feature flag `foo_flag` is enabled. Deprecated in 1.10: Deprecation reason') + expectation = 'Field description. Available only when feature flag `foo_flag` is enabled. Deprecated in 1.10: Deprecation reason' + + expect(field.description).to eq(expectation) end end end diff --git a/spec/graphql/types/boards/board_issue_input_type_spec.rb b/spec/graphql/types/boards/board_issue_input_type_spec.rb new file mode 100644 index 00000000000..6319ff9a88e --- /dev/null +++ b/spec/graphql/types/boards/board_issue_input_type_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['BoardIssueInput'] do + it { expect(described_class.graphql_name).to eq('BoardIssueInput') } + + it 'exposes negated issue arguments' do + allowed_args = %w(labelName milestoneTitle assigneeUsername authorUsername + releaseTag myReactionEmoji not search) + + expect(described_class.arguments.keys).to include(*allowed_args) + expect(described_class.arguments['not'].type).to eq(Types::Boards::NegatedBoardIssueInputType) + end +end diff --git a/spec/graphql/types/current_user_todos_type_spec.rb b/spec/graphql/types/current_user_todos_type_spec.rb new file mode 100644 index 00000000000..a0015e96788 --- /dev/null +++ b/spec/graphql/types/current_user_todos_type_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['CurrentUserTodos'] do + specify { expect(described_class.graphql_name).to eq('CurrentUserTodos') } + + specify { expect(described_class).to have_graphql_fields(:current_user_todos).only } +end diff --git a/spec/graphql/types/design_management/design_type_spec.rb b/spec/graphql/types/design_management/design_type_spec.rb index 7a38b397965..cae98a013e1 100644 --- a/spec/graphql/types/design_management/design_type_spec.rb +++ b/spec/graphql/types/design_management/design_type_spec.rb @@ -3,8 +3,10 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['Design'] do + specify { expect(described_class.interfaces).to include(Types::CurrentUserTodos) } + it_behaves_like 'a GraphQL type with design fields' do - let(:extra_design_fields) { %i[notes discussions versions] } + let(:extra_design_fields) { %i[notes current_user_todos discussions versions] } let_it_be(:design) { create(:design, :with_versions) } let(:object_id) { GitlabSchema.id_from_object(design) } let_it_be(:object_id_b) { GitlabSchema.id_from_object(create(:design, :with_versions)) } diff --git a/spec/graphql/types/group_type_spec.rb b/spec/graphql/types/group_type_spec.rb index 0b87805c2ef..bf7ddebaf5b 100644 --- a/spec/graphql/types/group_type_spec.rb +++ b/spec/graphql/types/group_type_spec.rb @@ -16,7 +16,7 @@ RSpec.describe GitlabSchema.types['Group'] do web_url avatar_url share_with_group_lock project_creation_level subgroup_creation_level require_two_factor_authentication two_factor_grace_period auto_devops_enabled emails_disabled - mentions_disabled parent boards milestones + mentions_disabled parent boards milestones group_members ] expect(described_class).to include_graphql_fields(*expected_fields) @@ -30,5 +30,12 @@ RSpec.describe GitlabSchema.types['Group'] do end end + describe 'members field' do + subject { described_class.fields['groupMembers'] } + + it { is_expected.to have_graphql_type(Types::GroupMemberType.connection_type) } + it { is_expected.to have_graphql_resolver(Resolvers::GroupMembersResolver) } + end + it_behaves_like 'a GraphQL type with labels' end diff --git a/spec/graphql/types/issuable_severity_enum_spec.rb b/spec/graphql/types/issuable_severity_enum_spec.rb new file mode 100644 index 00000000000..3f8bd76fa62 --- /dev/null +++ b/spec/graphql/types/issuable_severity_enum_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::IssuableSeverityEnum do + specify { expect(described_class.graphql_name).to eq('IssuableSeverity') } + + it 'exposes all the existing issuable severity values' do + expect(described_class.values.keys).to contain_exactly( + *%w[UNKNOWN LOW MEDIUM HIGH CRITICAL] + ) + end +end diff --git a/spec/graphql/types/issue_type_spec.rb b/spec/graphql/types/issue_type_spec.rb index 24353f8fe3a..c55e624dd11 100644 --- a/spec/graphql/types/issue_type_spec.rb +++ b/spec/graphql/types/issue_type_spec.rb @@ -11,11 +11,13 @@ RSpec.describe GitlabSchema.types['Issue'] do specify { expect(described_class.interfaces).to include(Types::Notes::NoteableType) } + specify { expect(described_class.interfaces).to include(Types::CurrentUserTodos) } + it 'has specific fields' do fields = %i[id iid title description state reference author assignees participants labels milestone due_date confidential discussion_locked upvotes downvotes user_notes_count web_path web_url relative_position subscribed time_estimate total_time_spent closed_at created_at updated_at task_completion_status - designs design_collection] + designs design_collection alert_management_alert severity current_user_todos] fields.each do |field_name| expect(described_class).to have_graphql_field(field_name) diff --git a/spec/graphql/types/member_interface_spec.rb b/spec/graphql/types/member_interface_spec.rb new file mode 100644 index 00000000000..11fd09eb335 --- /dev/null +++ b/spec/graphql/types/member_interface_spec.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::MemberInterface do + it 'exposes the expected fields' do + expected_fields = %i[ + id + access_level + created_by + created_at + updated_at + expires_at + user + ] + + expect(described_class).to have_graphql_fields(*expected_fields) + end + + describe '.resolve_type' do + subject { described_class.resolve_type(object, {}) } + + context 'for project member' do + let(:object) { build(:project_member) } + + it { is_expected.to be Types::ProjectMemberType } + end + + context 'for group member' do + let(:object) { build(:group_member) } + + it { is_expected.to be Types::GroupMemberType } + end + + context 'for an unkown type' do + let(:object) { build(:user) } + + it 'raises an error' do + expect { subject }.to raise_error(Gitlab::Graphql::Errors::BaseError) + end + end + end +end diff --git a/spec/graphql/types/merge_request_sort_enum_spec.rb b/spec/graphql/types/merge_request_sort_enum_spec.rb new file mode 100644 index 00000000000..472eba1a50d --- /dev/null +++ b/spec/graphql/types/merge_request_sort_enum_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['MergeRequestSort'] do + specify { expect(described_class.graphql_name).to eq('MergeRequestSort') } + + it_behaves_like 'common sort values' + + it 'exposes all the existing issue sort values' do + expect(described_class.values.keys).to include( + *%w[MERGED_AT_ASC MERGED_AT_DESC] + ) + end +end diff --git a/spec/graphql/types/merge_request_type_spec.rb b/spec/graphql/types/merge_request_type_spec.rb index b11951190e0..46aebbdabeb 100644 --- a/spec/graphql/types/merge_request_type_spec.rb +++ b/spec/graphql/types/merge_request_type_spec.rb @@ -9,6 +9,8 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do specify { expect(described_class.interfaces).to include(Types::Notes::NoteableType) } + specify { expect(described_class.interfaces).to include(Types::CurrentUserTodos) } + it 'has the expected fields' do expected_fields = %w[ notes discussions user_permissions id iid title title_html description @@ -24,10 +26,16 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do 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 author merged_at commit_count + total_time_spent reference author merged_at commit_count current_user_todos + conflicts auto_merge_enabled ] - expected_fields << 'approved_by' if Gitlab.ee? + if Gitlab.ee? + expected_fields << 'approved' + expected_fields << 'approvals_left' + expected_fields << 'approvals_required' + expected_fields << 'approved_by' + end expect(described_class).to have_graphql_fields(*expected_fields) end diff --git a/spec/graphql/types/milestone_type_spec.rb b/spec/graphql/types/milestone_type_spec.rb index 2315c10433b..806495250ac 100644 --- a/spec/graphql/types/milestone_type_spec.rb +++ b/spec/graphql/types/milestone_type_spec.rb @@ -15,7 +15,7 @@ RSpec.describe GitlabSchema.types['Milestone'] do stats ] - expect(described_class).to have_graphql_fields(*expected_fields) + expect(described_class).to have_graphql_fields(*expected_fields).at_least end describe 'stats field' do diff --git a/spec/graphql/types/package_type_enum_spec.rb b/spec/graphql/types/package_type_enum_spec.rb index fadec9744ed..80a20a68bc2 100644 --- a/spec/graphql/types/package_type_enum_spec.rb +++ b/spec/graphql/types/package_type_enum_spec.rb @@ -4,6 +4,6 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['PackageTypeEnum'] do it 'exposes all package types' do - expect(described_class.values.keys).to contain_exactly(*%w[MAVEN NPM CONAN NUGET PYPI COMPOSER]) + expect(described_class.values.keys).to contain_exactly(*%w[MAVEN NPM CONAN NUGET PYPI COMPOSER GENERIC]) end end diff --git a/spec/graphql/types/permission_types/merge_request_spec.rb b/spec/graphql/types/permission_types/merge_request_spec.rb index 73a178540a6..2849dead9a8 100644 --- a/spec/graphql/types/permission_types/merge_request_spec.rb +++ b/spec/graphql/types/permission_types/merge_request_spec.rb @@ -7,7 +7,8 @@ RSpec.describe Types::PermissionTypes::MergeRequest do expected_permissions = [ :read_merge_request, :admin_merge_request, :update_merge_request, :create_note, :push_to_source_branch, :remove_source_branch, - :cherry_pick_on_current_merge_request, :revert_on_current_merge_request + :cherry_pick_on_current_merge_request, :revert_on_current_merge_request, + :can_merge ] expect(described_class).to have_graphql_fields(expected_permissions) diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb index 8a5d0cdf12d..44a89bfa35e 100644 --- a/spec/graphql/types/project_type_spec.rb +++ b/spec/graphql/types/project_type_spec.rb @@ -59,7 +59,7 @@ RSpec.describe GitlabSchema.types['Project'] 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 { is_expected.to have_graphql_resolver(Resolvers::ProjectMergeRequestsResolver) } it do is_expected.to have_graphql_arguments(:iids, @@ -72,7 +72,11 @@ RSpec.describe GitlabSchema.types['Project'] do :first, :last, :merged_after, - :merged_before + :merged_before, + :author_username, + :assignee_username, + :milestone_title, + :sort ) end end @@ -108,7 +112,7 @@ RSpec.describe GitlabSchema.types['Project'] do 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_type(Types::MemberInterface.connection_type) } it { is_expected.to have_graphql_resolver(Resolvers::ProjectMembersResolver) } end diff --git a/spec/graphql/types/query_type_spec.rb b/spec/graphql/types/query_type_spec.rb index ab13162b406..11f780a4f3f 100644 --- a/spec/graphql/types/query_type_spec.rb +++ b/spec/graphql/types/query_type_spec.rb @@ -20,6 +20,8 @@ RSpec.describe GitlabSchema.types['Query'] do milestone user users + issue + instance_statistics_measurements ] expect(described_class).to have_graphql_fields(*expected_fields).at_least @@ -53,4 +55,20 @@ RSpec.describe GitlabSchema.types['Query'] do is_expected.to have_graphql_resolver(Resolvers::MetadataResolver) end end + + describe 'issue field' do + subject { described_class.fields['issue'] } + + it 'returns issue' do + is_expected.to have_graphql_type(Types::IssueType) + end + end + + describe 'instance_statistics_measurements field' do + subject { described_class.fields['instanceStatisticsMeasurements'] } + + it 'returns issue' do + is_expected.to have_graphql_type(Types::Admin::Analytics::InstanceStatistics::MeasurementType.connection_type) + end + end end diff --git a/spec/graphql/types/release_asset_link_type_spec.rb b/spec/graphql/types/release_asset_link_type_spec.rb index 679431012cf..6800d5459c4 100644 --- a/spec/graphql/types/release_asset_link_type_spec.rb +++ b/spec/graphql/types/release_asset_link_type_spec.rb @@ -7,7 +7,7 @@ RSpec.describe GitlabSchema.types['ReleaseAssetLink'] do it 'has the expected fields' do expected_fields = %w[ - id name url external link_type + id name url external link_type direct_asset_url ] expect(described_class).to include_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/user_type_spec.rb b/spec/graphql/types/user_type_spec.rb index 7710b8efefe..1d5af24b3d9 100644 --- a/spec/graphql/types/user_type_spec.rb +++ b/spec/graphql/types/user_type_spec.rb @@ -25,6 +25,7 @@ RSpec.describe GitlabSchema.types['User'] do assignedMergeRequests groupMemberships projectMemberships + starredProjects ] expect(described_class).to have_graphql_fields(*expected_fields) |