diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /spec/graphql/types | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'spec/graphql/types')
25 files changed, 317 insertions, 31 deletions
diff --git a/spec/graphql/types/alert_management/alert_type_spec.rb b/spec/graphql/types/alert_management/alert_type_spec.rb index e14c189d4b6..82b48a20708 100644 --- a/spec/graphql/types/alert_management/alert_type_spec.rb +++ b/spec/graphql/types/alert_management/alert_type_spec.rb @@ -32,6 +32,7 @@ RSpec.describe GitlabSchema.types['AlertManagementAlert'] do todos details_url prometheus_alert + environment ] expect(described_class).to have_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/alert_management/status_enum_spec.rb b/spec/graphql/types/alert_management/status_enum_spec.rb index ac7a8eb53f6..1252efabe4c 100644 --- a/spec/graphql/types/alert_management/status_enum_spec.rb +++ b/spec/graphql/types/alert_management/status_enum_spec.rb @@ -9,10 +9,10 @@ RSpec.describe GitlabSchema.types['AlertManagementStatus'] do using RSpec::Parameterized::TableSyntax where(:status_name, :status_value) do - 'TRIGGERED' | 0 - 'ACKNOWLEDGED' | 1 - 'RESOLVED' | 2 - 'IGNORED' | 3 + 'TRIGGERED' | :triggered + 'ACKNOWLEDGED' | :acknowledged + 'RESOLVED' | :resolved + 'IGNORED' | :ignored end with_them do 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/ci/detailed_status_type_spec.rb b/spec/graphql/types/ci/detailed_status_type_spec.rb index 67199848df0..ddb3a1450df 100644 --- a/spec/graphql/types/ci/detailed_status_type_spec.rb +++ b/spec/graphql/types/ci/detailed_status_type_spec.rb @@ -8,6 +8,6 @@ RSpec.describe Types::Ci::DetailedStatusType do it "has all fields" do expect(described_class).to have_graphql_fields(:group, :icon, :favicon, :details_path, :has_details, - :label, :text, :tooltip) + :label, :text, :tooltip, :action) end end diff --git a/spec/graphql/types/ci/group_type_spec.rb b/spec/graphql/types/ci/group_type_spec.rb index 8d547b19af3..d7ce5602612 100644 --- a/spec/graphql/types/ci/group_type_spec.rb +++ b/spec/graphql/types/ci/group_type_spec.rb @@ -10,6 +10,7 @@ RSpec.describe Types::Ci::GroupType do name size jobs + detailedStatus ] expect(described_class).to have_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/ci/job_type_spec.rb b/spec/graphql/types/ci/job_type_spec.rb index faf3a95cf25..3a54ed2efed 100644 --- a/spec/graphql/types/ci/job_type_spec.rb +++ b/spec/graphql/types/ci/job_type_spec.rb @@ -9,6 +9,8 @@ RSpec.describe Types::Ci::JobType do expected_fields = %i[ name needs + detailedStatus + scheduledAt ] expect(described_class).to have_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/ci/runner_architecture_type_spec.rb b/spec/graphql/types/ci/runner_architecture_type_spec.rb new file mode 100644 index 00000000000..527adef8cf9 --- /dev/null +++ b/spec/graphql/types/ci/runner_architecture_type_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::Ci::RunnerArchitectureType do + specify { expect(described_class.graphql_name).to eq('RunnerArchitecture') } + + it 'exposes the expected fields' do + expected_fields = %i[ + name + download_location + ] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/ci/runner_platform_type_spec.rb b/spec/graphql/types/ci/runner_platform_type_spec.rb new file mode 100644 index 00000000000..66b83f607d0 --- /dev/null +++ b/spec/graphql/types/ci/runner_platform_type_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::Ci::RunnerPlatformType do + specify { expect(described_class.graphql_name).to eq('RunnerPlatform') } + + it 'exposes the expected fields' do + expected_fields = %i[ + name + human_readable_name + architectures + ] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/ci/stage_type_spec.rb b/spec/graphql/types/ci/stage_type_spec.rb index 0c352ed27aa..9a8d4fa96a3 100644 --- a/spec/graphql/types/ci/stage_type_spec.rb +++ b/spec/graphql/types/ci/stage_type_spec.rb @@ -9,6 +9,7 @@ RSpec.describe Types::Ci::StageType do expected_fields = %i[ name groups + detailedStatus ] expect(described_class).to have_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/ci/status_action_type_spec.rb b/spec/graphql/types/ci/status_action_type_spec.rb new file mode 100644 index 00000000000..8a99068e44f --- /dev/null +++ b/spec/graphql/types/ci/status_action_type_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::Ci::StatusActionType do + specify { expect(described_class.graphql_name).to eq('StatusAction') } + + it 'exposes the expected fields' do + expected_fields = %i[ + buttonTitle + icon + path + method + title + ] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end 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/environment_type_spec.rb b/spec/graphql/types/environment_type_spec.rb index abeeeba543f..2220f847e4e 100644 --- a/spec/graphql/types/environment_type_spec.rb +++ b/spec/graphql/types/environment_type_spec.rb @@ -7,7 +7,7 @@ RSpec.describe GitlabSchema.types['Environment'] do it 'has the expected fields' do expected_fields = %w[ - name id state metrics_dashboard latest_opened_most_severe_alert + name id state metrics_dashboard latest_opened_most_severe_alert path ] expect(described_class).to have_graphql_fields(*expected_fields) @@ -28,6 +28,7 @@ RSpec.describe GitlabSchema.types['Environment'] do project(fullPath: "#{project.full_path}") { environment(name: "#{environment.name}") { name + path state } } @@ -43,6 +44,18 @@ RSpec.describe GitlabSchema.types['Environment'] do expect(subject['data']['project']['environment']['name']).to eq(environment.name) end + it 'returns the path when the feature is enabled' do + expect(subject['data']['project']['environment']['path']).to eq( + Gitlab::Routing.url_helpers.project_environment_path(project, environment) + ) + end + + it 'does not return the path when the feature is disabled' do + stub_feature_flags(expose_environment_path_in_alert_details: false) + + expect(subject['data']['project']['environment']['path']).to be_nil + end + context 'when query alert data for the environment' do let_it_be(:query) do %( 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/group_type_spec.rb b/spec/graphql/types/group_type_spec.rb index bf7ddebaf5b..7d14ef87551 100644 --- a/spec/graphql/types/group_type_spec.rb +++ b/spec/graphql/types/group_type_spec.rb @@ -17,6 +17,7 @@ RSpec.describe GitlabSchema.types['Group'] do subgroup_creation_level require_two_factor_authentication two_factor_grace_period auto_devops_enabled emails_disabled mentions_disabled parent boards milestones group_members + merge_requests ] expect(described_class).to include_graphql_fields(*expected_fields) 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/merge_request_type_spec.rb b/spec/graphql/types/merge_request_type_spec.rb index 46aebbdabeb..9d901655b7b 100644 --- a/spec/graphql/types/merge_request_type_spec.rb +++ b/spec/graphql/types/merge_request_type_spec.rb @@ -27,16 +27,51 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do 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 current_user_todos - conflicts auto_merge_enabled + conflicts auto_merge_enabled approved_by ] 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 + + describe '#diff_stats_summary' do + subject { GitlabSchema.execute(query, context: { current_user: current_user }).as_json } + + let(:current_user) { create :admin } + let(:query) do + %( + { + project(fullPath: "#{project.full_path}") { + mergeRequests { + nodes { + diffStatsSummary { + additions, deletions + } + } + } + } + } + ) + end + + let(:project) { create(:project, :public) } + let(:merge_request) { create(:merge_request, target_project: project, source_project: project) } + + let(:response) { subject.dig('data', 'project', 'mergeRequests', 'nodes').first['diffStatsSummary'] } + + context 'when MR metrics has additions and deletions' do + before do + merge_request.metrics.update!(added_lines: 5, removed_lines: 8) + end + + it 'pulls out data from metrics object' do + expect(response).to match('additions' => 5, 'deletions' => 8) + end + end + end end diff --git a/spec/graphql/types/package_type_enum_spec.rb b/spec/graphql/types/package_type_enum_spec.rb index 80a20a68bc2..407d5786f65 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 DEBIAN]) 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/query_type_spec.rb b/spec/graphql/types/query_type_spec.rb index 11f780a4f3f..1d9ca8323f8 100644 --- a/spec/graphql/types/query_type_spec.rb +++ b/spec/graphql/types/query_type_spec.rb @@ -22,6 +22,7 @@ RSpec.describe GitlabSchema.types['Query'] do users issue instance_statistics_measurements + runner_platforms ] expect(described_class).to have_graphql_fields(*expected_fields).at_least @@ -67,8 +68,16 @@ RSpec.describe GitlabSchema.types['Query'] do describe 'instance_statistics_measurements field' do subject { described_class.fields['instanceStatisticsMeasurements'] } - it 'returns issue' do + it 'returns instance statistics measurements' do is_expected.to have_graphql_type(Types::Admin::Analytics::InstanceStatistics::MeasurementType.connection_type) end end + + describe 'runner_platforms field' do + subject { described_class.fields['runnerPlatforms'] } + + it 'returns runner platforms' do + is_expected.to have_graphql_type(Types::Ci::RunnerPlatformType.connection_type) + end + end end diff --git a/spec/graphql/types/range_input_type_spec.rb b/spec/graphql/types/range_input_type_spec.rb new file mode 100644 index 00000000000..aa6fd72cf13 --- /dev/null +++ b/spec/graphql/types/range_input_type_spec.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ::Types::RangeInputType do + let(:of_integer) { ::GraphQL::INT_TYPE } + + context 'parameterized on Integer' do + let(:type) { described_class[of_integer] } + + it 'accepts start and end' do + input = { start: 1, end: 10 } + output = { start: 1, end: 10 } + + expect(type.coerce_isolated_input(input)).to eq(output) + end + + it 'rejects inverted ranges' do + input = { start: 10, end: 1 } + + expect { type.coerce_isolated_input(input) }.to raise_error(Gitlab::Graphql::Errors::ArgumentError) + end + end + + it 'follows expected subtyping relationships for instances' do + context = GraphQL::Query::Context.new( + query: OpenStruct.new(schema: nil), + values: {}, + object: nil + ) + instance = described_class[of_integer].new(context: context, defaults_used: [], ruby_kwargs: {}) + + expect(instance).to be_a_kind_of(described_class) + expect(instance).to be_a_kind_of(described_class[of_integer]) + expect(instance).not_to be_a_kind_of(described_class[GraphQL::ID_TYPE]) + end + + it 'follows expected subtyping relationships for classes' do + expect(described_class[of_integer]).to be < described_class + expect(described_class[of_integer]).not_to be < described_class[GraphQL::ID_TYPE] + expect(described_class[of_integer]).not_to be < described_class[of_integer, false] + end +end diff --git a/spec/graphql/types/root_storage_statistics_type_spec.rb b/spec/graphql/types/root_storage_statistics_type_spec.rb index f01c55cbccb..79d474f13ad 100644 --- a/spec/graphql/types/root_storage_statistics_type_spec.rb +++ b/spec/graphql/types/root_storage_statistics_type_spec.rb @@ -7,7 +7,8 @@ RSpec.describe GitlabSchema.types['RootStorageStatistics'] do it 'has all the required fields' do expect(described_class).to have_graphql_fields(:storage_size, :repository_size, :lfs_objects_size, - :build_artifacts_size, :packages_size, :wiki_size, :snippets_size) + :build_artifacts_size, :packages_size, :wiki_size, :snippets_size, + :pipeline_artifacts_size) end specify { expect(described_class).to require_graphql_authorizations(:read_statistics) } diff --git a/spec/graphql/types/snippet_type_spec.rb b/spec/graphql/types/snippet_type_spec.rb index 86af69f1294..e73665a1b1d 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) } @@ -115,7 +124,7 @@ RSpec.describe GitlabSchema.types['Snippet'] do end describe '#blob' do - let(:query_blob) { subject.dig('data', 'snippets', 'edges')[0]['node']['blob'] } + let(:query_blob) { subject.dig('data', 'snippets', 'nodes')[0]['blob'] } subject { GitlabSchema.execute(snippet_query_for(field: 'blob'), context: { current_user: user }).as_json } @@ -142,9 +151,26 @@ 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', 'nodes')[0].dig('blobs', 'nodes') } + let(:paths) { [] } + let(:query) do + %( + { + snippets { + nodes { + blobs(paths: #{paths}) { + nodes { + 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 @@ -174,6 +200,18 @@ RSpec.describe GitlabSchema.types['Snippet'] do 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['name'] } + + expect(resulting_blobs_names).to match(paths) + end + end end end @@ -181,12 +219,10 @@ RSpec.describe GitlabSchema.types['Snippet'] do %( { snippets { - edges { - node { - #{field} { - name - path - } + nodes { + #{field} { + name + path } } } 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 diff --git a/spec/graphql/types/timeframe_type_spec.rb b/spec/graphql/types/timeframe_type_spec.rb new file mode 100644 index 00000000000..dfde3242897 --- /dev/null +++ b/spec/graphql/types/timeframe_type_spec.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['Timeframe'] do + let(:input) { { start: "2018-06-04", end: "2020-10-06" } } + let(:output) { { start: Date.parse(input[:start]), end: Date.parse(input[:end]) } } + + it 'coerces ISO-dates into Time objects' do + expect(described_class.coerce_isolated_input(input)).to eq(output) + end + + it 'rejects invalid input' do + input[:start] = 'foo' + + expect { described_class.coerce_isolated_input(input) } + .to raise_error(GraphQL::CoercionError) + end + + it 'accepts times as input' do + with_time = input.merge(start: '2018-06-04T13:48:14Z') + + expect(described_class.coerce_isolated_input(with_time)).to eq(output) + end + + it 'requires both ends of the range' do + types = described_class.arguments.slice('start', 'end').values.map(&:type) + + expect(types).to all(be_non_null) + end + + it 'rejects invalid range' do + input.merge!(start: input[:end], end: input[:start]) + + expect { described_class.coerce_isolated_input(input) } + .to raise_error(::Gitlab::Graphql::Errors::ArgumentError, 'start must be before end') + end +end |