diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/support/shared_examples/graphql | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/support/shared_examples/graphql')
4 files changed, 59 insertions, 7 deletions
diff --git a/spec/support/shared_examples/graphql/mutations/incident_management_timeline_events_shared_examples.rb b/spec/support/shared_examples/graphql/mutations/incident_management_timeline_events_shared_examples.rb new file mode 100644 index 00000000000..b989dbc6524 --- /dev/null +++ b/spec/support/shared_examples/graphql/mutations/incident_management_timeline_events_shared_examples.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'spec_helper' + +# Requres: +# * subject with a 'resolve' name +# * Defined expected timeline event via `let(:expected_timeline_event) { instance_double(...) }` +RSpec.shared_examples 'creating an incident timeline event' do + it 'creates a timeline event' do + expect { resolve }.to change(IncidentManagement::TimelineEvent, :count).by(1) + end + + it 'responds with a timeline event', :aggregate_failures do + response = resolve + timeline_event = IncidentManagement::TimelineEvent.last! + + expect(response).to match(timeline_event: timeline_event, errors: be_empty) + + expect(timeline_event.promoted_from_note).to eq(expected_timeline_event.promoted_from_note) + expect(timeline_event.note).to eq(expected_timeline_event.note) + expect(timeline_event.occurred_at.to_s).to eq(expected_timeline_event.occurred_at) + expect(timeline_event.incident).to eq(expected_timeline_event.incident) + expect(timeline_event.author).to eq(expected_timeline_event.author) + end +end + +# Requres +# * subject with a 'resolve' name +# * a user factory with a 'current_user' name +RSpec.shared_examples 'failing to create an incident timeline event' do + context 'when a user has no permissions to create timeline event' do + before do + project.add_guest(current_user) + end + + it 'raises an error' do + expect { resolve }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + end + end +end + +# Requres: +# * subject with a 'resolve' name +RSpec.shared_examples 'responding with an incident timeline errors' do |errors:| + it 'returns errors' do + expect(resolve).to eq(timeline_event: nil, errors: errors) + end +end diff --git a/spec/support/shared_examples/graphql/resolvers/packages_resolvers_shared_examples.rb b/spec/support/shared_examples/graphql/resolvers/packages_resolvers_shared_examples.rb index 3d6fec85490..da8562161e7 100644 --- a/spec/support/shared_examples/graphql/resolvers/packages_resolvers_shared_examples.rb +++ b/spec/support/shared_examples/graphql/resolvers/packages_resolvers_shared_examples.rb @@ -4,7 +4,11 @@ RSpec.shared_examples 'group and projects packages resolver' do context 'without sort' do let_it_be(:npm_package) { create(:package, project: project) } - it { is_expected.to contain_exactly(npm_package) } + it 'returns the proper packages' do + expect(::Packages::Package).not_to receive(:preload_pipelines) + + expect(subject).to contain_exactly(npm_package) + end end context 'with sorting and filtering' do diff --git a/spec/support/shared_examples/graphql/sorted_paginated_query_shared_examples.rb b/spec/support/shared_examples/graphql/sorted_paginated_query_shared_examples.rb index 37a805902a9..6d6e7b761f6 100644 --- a/spec/support/shared_examples/graphql/sorted_paginated_query_shared_examples.rb +++ b/spec/support/shared_examples/graphql/sorted_paginated_query_shared_examples.rb @@ -101,7 +101,7 @@ RSpec.shared_examples 'sorted paginated query' do |conditions = {}| context 'when sorting' do it 'sorts correctly' do - expect(results).to eq all_records + expect(results).to match all_records end context 'when paginating' do @@ -110,17 +110,17 @@ RSpec.shared_examples 'sorted paginated query' do |conditions = {}| let(:rest) { all_records.drop(first_param) } it 'paginates correctly' do - expect(results).to eq first_page + expect(results).to match first_page fwds = pagination_query(sort_argument.merge(after: end_cursor)) post_graphql(fwds, current_user: current_user) - expect(results).to eq rest + expect(results).to match rest bwds = pagination_query(sort_argument.merge(before: start_cursor)) post_graphql(bwds, current_user: current_user) - expect(results).to eq first_page + expect(results).to match first_page end end @@ -130,7 +130,7 @@ RSpec.shared_examples 'sorted paginated query' do |conditions = {}| it 'fetches last elements without error' do post_graphql(pagination_query(params), current_user: current_user) - expect(results.first).to eq(all_records.last) + expect(results.first).to match all_records.last end end end diff --git a/spec/support/shared_examples/graphql/types/gitlab_style_deprecations_shared_examples.rb b/spec/support/shared_examples/graphql/types/gitlab_style_deprecations_shared_examples.rb index 3caf153c2fa..cf9c36fafe8 100644 --- a/spec/support/shared_examples/graphql/types/gitlab_style_deprecations_shared_examples.rb +++ b/spec/support/shared_examples/graphql/types/gitlab_style_deprecations_shared_examples.rb @@ -6,7 +6,7 @@ RSpec.shared_examples 'Gitlab-style deprecations' do expect { subject(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-arguments-and-enum-values' + 'See https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#deprecating-schema-items' ) end |