diff options
Diffstat (limited to 'spec/graphql/types')
-rw-r--r-- | spec/graphql/types/base_field_spec.rb | 4 | ||||
-rw-r--r-- | spec/graphql/types/design_management/design_collection_copy_state_enum_spec.rb | 11 | ||||
-rw-r--r-- | spec/graphql/types/design_management/design_collection_type_spec.rb | 2 | ||||
-rw-r--r-- | spec/graphql/types/global_id_type_spec.rb | 26 | ||||
-rw-r--r-- | spec/graphql/types/issue_sort_enum_spec.rb | 2 | ||||
-rw-r--r-- | spec/graphql/types/package_type_enum_spec.rb | 2 | ||||
-rw-r--r-- | spec/graphql/types/project_type_spec.rb | 9 | ||||
-rw-r--r-- | spec/graphql/types/snippet_type_spec.rb | 52 | ||||
-rw-r--r-- | spec/graphql/types/terraform/state_type_spec.rb | 21 |
9 files changed, 112 insertions, 17 deletions
diff --git a/spec/graphql/types/base_field_spec.rb b/spec/graphql/types/base_field_spec.rb index bcfbd7f2480..d61ea6aa6e9 100644 --- a/spec/graphql/types/base_field_spec.rb +++ b/spec/graphql/types/base_field_spec.rb @@ -126,6 +126,10 @@ RSpec.describe Types::BaseField do let(:field) { described_class.new(name: 'test', type: GraphQL::STRING_TYPE, feature_flag: flag, null: false) } let(:context) { {} } + before do + skip_feature_flags_yaml_validation + end + it 'returns false if the feature is not enabled' do stub_feature_flags(flag => false) diff --git a/spec/graphql/types/design_management/design_collection_copy_state_enum_spec.rb b/spec/graphql/types/design_management/design_collection_copy_state_enum_spec.rb new file mode 100644 index 00000000000..f536d91aeda --- /dev/null +++ b/spec/graphql/types/design_management/design_collection_copy_state_enum_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['DesignCollectionCopyState'] do + it { expect(described_class.graphql_name).to eq('DesignCollectionCopyState') } + + it 'exposes the correct event states' do + expect(described_class.values.keys).to match_array(%w(READY IN_PROGRESS ERROR)) + end +end diff --git a/spec/graphql/types/design_management/design_collection_type_spec.rb b/spec/graphql/types/design_management/design_collection_type_spec.rb index 6b1d3a87c2d..83208705249 100644 --- a/spec/graphql/types/design_management/design_collection_type_spec.rb +++ b/spec/graphql/types/design_management/design_collection_type_spec.rb @@ -6,7 +6,7 @@ RSpec.describe GitlabSchema.types['DesignCollection'] do it { expect(described_class).to require_graphql_authorizations(:read_design) } it 'has the expected fields' do - expected_fields = %i[project issue designs versions version designAtVersion design] + expected_fields = %i[project issue designs versions version designAtVersion design copyState] expect(described_class).to have_graphql_fields(*expected_fields) end diff --git a/spec/graphql/types/global_id_type_spec.rb b/spec/graphql/types/global_id_type_spec.rb index 2a7b26f66b0..7589b0e285e 100644 --- a/spec/graphql/types/global_id_type_spec.rb +++ b/spec/graphql/types/global_id_type_spec.rb @@ -99,8 +99,6 @@ RSpec.describe Types::GlobalIDType do end describe 'compatibility' do - # Simplified schema to test compatibility - def query(doc, vars) GraphQL::Query.new(schema, document: doc, context: {}, variables: vars) end @@ -112,6 +110,7 @@ RSpec.describe Types::GlobalIDType do all_types = [::GraphQL::ID_TYPE, ::Types::GlobalIDType, ::Types::GlobalIDType[::Project]] shared_examples 'a working query' do + # Simplified schema to test compatibility let!(:schema) do # capture values so they can be closed over arg_type = argument_type @@ -135,10 +134,21 @@ RSpec.describe Types::GlobalIDType do argument :id, arg_type, required: true end + # This is needed so that all types are always registered as input types + field :echo, String, null: true do + argument :id, ::GraphQL::ID_TYPE, required: false + argument :gid, ::Types::GlobalIDType, required: false + argument :pid, ::Types::GlobalIDType[::Project], required: false + end + def project_by_id(id:) gid = ::Types::GlobalIDType[::Project].coerce_isolated_input(id) gid.model_class.find(gid.model_id) end + + def echo(id: nil, gid: nil, pid: nil) + "id: #{id}, gid: #{gid}, pid: #{pid}" + end end) end end @@ -152,7 +162,7 @@ RSpec.describe Types::GlobalIDType do end end - context 'when the argument is declared as ID' do + context 'when the client declares the argument as ID the actual argument can be any type' do let(:document) do <<-GRAPHQL query($projectId: ID!){ @@ -163,16 +173,16 @@ RSpec.describe Types::GlobalIDType do GRAPHQL end - let(:argument_type) { ::GraphQL::ID_TYPE } - - where(:result_type) { all_types } + where(:result_type, :argument_type) do + all_types.flat_map { |arg_type| all_types.zip([arg_type].cycle) } + end with_them do it_behaves_like 'a working query' end end - context 'when the argument is declared as GlobalID' do + context 'when the client passes the argument as GlobalID' do let(:document) do <<-GRAPHQL query($projectId: GlobalID!) { @@ -192,7 +202,7 @@ RSpec.describe Types::GlobalIDType do end end - context 'when the argument is declared as ProjectID' do + context 'when the client passes the argument as ProjectID' do let(:document) do <<-GRAPHQL query($projectId: ProjectID!) { diff --git a/spec/graphql/types/issue_sort_enum_spec.rb b/spec/graphql/types/issue_sort_enum_spec.rb index 9313d3aee84..4433709d193 100644 --- a/spec/graphql/types/issue_sort_enum_spec.rb +++ b/spec/graphql/types/issue_sort_enum_spec.rb @@ -9,7 +9,7 @@ RSpec.describe GitlabSchema.types['IssueSort'] do it 'exposes all the existing issue sort values' do expect(described_class.values.keys).to include( - *%w[DUE_DATE_ASC DUE_DATE_DESC RELATIVE_POSITION_ASC] + *%w[DUE_DATE_ASC DUE_DATE_DESC RELATIVE_POSITION_ASC SEVERITY_ASC SEVERITY_DESC] ) end end diff --git a/spec/graphql/types/package_type_enum_spec.rb b/spec/graphql/types/package_type_enum_spec.rb index 80a20a68bc2..638f8ccbaee 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 GENERIC]) + expect(described_class.values.keys).to contain_exactly(*%w[MAVEN NPM CONAN NUGET PYPI COMPOSER GENERIC GOLANG]) end end diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb index 44a89bfa35e..8aa9e1138cc 100644 --- a/spec/graphql/types/project_type_spec.rb +++ b/spec/graphql/types/project_type_spec.rb @@ -27,7 +27,7 @@ RSpec.describe GitlabSchema.types['Project'] do environment boards jira_import_status jira_imports services releases release alert_management_alerts alert_management_alert alert_management_alert_status_counts container_expiration_policy service_desk_enabled service_desk_address - issue_status_counts + issue_status_counts terraform_states ] expect(described_class).to include_graphql_fields(*expected_fields) @@ -154,5 +154,12 @@ RSpec.describe GitlabSchema.types['Project'] do it { is_expected.to have_graphql_type(Types::ContainerExpirationPolicyType) } end + describe 'terraform states field' do + subject { described_class.fields['terraformStates'] } + + it { is_expected.to have_graphql_type(Types::Terraform::StateType.connection_type) } + it { is_expected.to have_graphql_resolver(Resolvers::Terraform::StatesResolver) } + end + it_behaves_like 'a GraphQL type with labels' end diff --git a/spec/graphql/types/snippet_type_spec.rb b/spec/graphql/types/snippet_type_spec.rb index 86af69f1294..2ea215450cb 100644 --- a/spec/graphql/types/snippet_type_spec.rb +++ b/spec/graphql/types/snippet_type_spec.rb @@ -16,6 +16,15 @@ RSpec.describe GitlabSchema.types['Snippet'] do expect(described_class).to have_graphql_fields(*expected_fields) end + describe 'blobs field' do + subject { described_class.fields['blobs'] } + + it 'returns blobs' do + is_expected.to have_graphql_type(Types::Snippets::BlobType.connection_type) + is_expected.to have_graphql_resolver(Resolvers::Snippets::BlobsResolver) + end + end + context 'when restricted visibility level is set to public' do let_it_be(:snippet) { create(:personal_snippet, :repository, :public, author: user) } @@ -142,9 +151,30 @@ RSpec.describe GitlabSchema.types['Snippet'] do describe '#blobs' do let_it_be(:snippet) { create(:personal_snippet, :public, author: user) } - let(:query_blobs) { subject.dig('data', 'snippets', 'edges')[0]['node']['blobs'] } + let(:query_blobs) { subject.dig('data', 'snippets', 'edges')[0].dig('node', 'blobs', 'edges') } + let(:paths) { [] } + let(:query) do + %( + { + snippets { + edges { + node { + blobs(paths: #{paths}) { + edges { + node { + name + path + } + } + } + } + } + } + } + ) + end - subject { GitlabSchema.execute(snippet_query_for(field: 'blobs'), context: { current_user: user }).as_json } + subject { GitlabSchema.execute(query, context: { current_user: user }).as_json } shared_examples 'an array' do it 'returns an array of snippet blobs' do @@ -158,8 +188,8 @@ RSpec.describe GitlabSchema.types['Snippet'] do 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 + expect(query_blobs.first['node']['name']).to eq blob.name + expect(query_blobs.first['node']['path']).to eq blob.path end end @@ -170,10 +200,22 @@ RSpec.describe GitlabSchema.types['Snippet'] do it_behaves_like 'an array' it 'contains all the blobs from the repository' do - resulting_blobs_names = query_blobs.map { |b| b['name'] } + resulting_blobs_names = query_blobs.map { |b| b['node']['name'] } expect(resulting_blobs_names).to match_array(blobs.map(&:name)) end + + context 'when specific path is set' do + let(:paths) { ['CHANGELOG'] } + + it_behaves_like 'an array' + + it 'returns specific files' do + resulting_blobs_names = query_blobs.map { |b| b['node']['name'] } + + expect(resulting_blobs_names).to match(paths) + end + end end end diff --git a/spec/graphql/types/terraform/state_type_spec.rb b/spec/graphql/types/terraform/state_type_spec.rb new file mode 100644 index 00000000000..51508208046 --- /dev/null +++ b/spec/graphql/types/terraform/state_type_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['TerraformState'] do + it { expect(described_class.graphql_name).to eq('TerraformState') } + it { expect(described_class).to require_graphql_authorizations(:read_terraform_state) } + + describe 'fields' do + let(:fields) { %i[id name locked_by_user locked_at created_at updated_at] } + + it { expect(described_class).to have_graphql_fields(fields) } + + it { expect(described_class.fields['id'].type).to be_non_null } + it { expect(described_class.fields['name'].type).to be_non_null } + it { expect(described_class.fields['lockedByUser'].type).not_to be_non_null } + it { expect(described_class.fields['lockedAt'].type).not_to be_non_null } + it { expect(described_class.fields['createdAt'].type).to be_non_null } + it { expect(described_class.fields['updatedAt'].type).to be_non_null } + end +end |