diff options
Diffstat (limited to 'spec/support/shared_examples/graphql/mutations')
-rw-r--r-- | spec/support/shared_examples/graphql/mutations/can_mutate_spammable_examples.rb | 6 | ||||
-rw-r--r-- | spec/support/shared_examples/graphql/mutations/resolves_subscription_shared_examples.rb | 53 |
2 files changed, 26 insertions, 33 deletions
diff --git a/spec/support/shared_examples/graphql/mutations/can_mutate_spammable_examples.rb b/spec/support/shared_examples/graphql/mutations/can_mutate_spammable_examples.rb index fc795012ce7..5e15c91cd41 100644 --- a/spec/support/shared_examples/graphql/mutations/can_mutate_spammable_examples.rb +++ b/spec/support/shared_examples/graphql/mutations/can_mutate_spammable_examples.rb @@ -6,9 +6,9 @@ RSpec.shared_examples 'a mutation which can mutate a spammable' do describe "#additional_spam_params" do it 'passes additional spam params to the service' do args = [ - anything, - anything, - hash_including( + project: anything, + current_user: anything, + params: hash_including( api: true, request: instance_of(ActionDispatch::Request), captcha_response: captcha_response, diff --git a/spec/support/shared_examples/graphql/mutations/resolves_subscription_shared_examples.rb b/spec/support/shared_examples/graphql/mutations/resolves_subscription_shared_examples.rb index ebba312e895..678bb908343 100644 --- a/spec/support/shared_examples/graphql/mutations/resolves_subscription_shared_examples.rb +++ b/spec/support/shared_examples/graphql/mutations/resolves_subscription_shared_examples.rb @@ -2,44 +2,37 @@ require 'spec_helper' -RSpec.shared_examples 'a subscribeable graphql resource' do - let(:project) { resource.project } - let_it_be(:user) { create(:user) } - - subject(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) } +RSpec.shared_examples 'a subscribeable not accessible graphql resource' do + let(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) } - specify { expect(described_class).to require_graphql_authorizations(permission_name) } + subject { mutation.resolve(project_path: resource.project.full_path, iid: resource.iid, subscribed_state: true) } - describe '#resolve' do - let(:subscribe) { true } - let(:mutated_resource) { subject[resource.class.name.underscore.to_sym] } - - subject { mutation.resolve(project_path: resource.project.full_path, iid: resource.iid, subscribed_state: subscribe) } + it 'raises an error if the resource is not accessible to the user' do + expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + end +end - it 'raises an error if the resource is not accessible to the user' do - expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) - end +RSpec.shared_examples 'a subscribeable graphql resource' do + let(:mutated_resource) { subject[resource.class.name.underscore.to_sym] } + let(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) } + let(:subscribe) { true } - context 'when the user can update the resource' do - before do - resource.project.add_developer(user) - end + subject { mutation.resolve(project_path: resource.project.full_path, iid: resource.iid, subscribed_state: subscribe) } - it 'subscribes to the resource' do - expect(mutated_resource).to eq(resource) - expect(mutated_resource.subscribed?(user, project)).to eq(true) - expect(subject[:errors]).to be_empty - end + it 'subscribes to the resource' do + expect(mutated_resource).to eq(resource) + expect(mutated_resource.subscribed?(user, project)).to eq(true) + expect(subject[:errors]).to be_empty + end - context 'when passing subscribe as false' do - let(:subscribe) { false } + context 'when passing subscribe as false' do + let(:subscribe) { false } - it 'unsubscribes from the discussion' do - resource.subscribe(user, project) + it 'unsubscribes from the discussion' do + resource.subscribe(user, project) - expect(mutated_resource.subscribed?(user, project)).to eq(false) - end - end + expect(mutated_resource.subscribed?(user, project)).to eq(false) + expect(subject[:errors]).to be_empty end end end |