diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
commit | 4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch) | |
tree | 5423a1c7516cffe36384133ade12572cf709398d /spec/graphql/subscriptions | |
parent | e570267f2f6b326480d284e0164a6464ba4081bc (diff) |
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'spec/graphql/subscriptions')
-rw-r--r-- | spec/graphql/subscriptions/issuable_updated_spec.rb | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/spec/graphql/subscriptions/issuable_updated_spec.rb b/spec/graphql/subscriptions/issuable_updated_spec.rb new file mode 100644 index 00000000000..cc88b37627d --- /dev/null +++ b/spec/graphql/subscriptions/issuable_updated_spec.rb @@ -0,0 +1,68 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Subscriptions::IssuableUpdated do + include GraphqlHelpers + + it { expect(described_class).to have_graphql_arguments(:issuable_id) } + it { expect(described_class.payload_type).to eq(Types::IssuableType) } + + describe '#resolve' do + let_it_be(:unauthorized_user) { create(:user) } + let_it_be(:issue) { create(:issue) } + + let(:current_user) { issue.author } + let(:issuable_id) { issue.to_gid } + + subject { resolver.resolve_with_support(issuable_id: issuable_id) } + + context 'initial subscription' do + let(:resolver) { resolver_instance(described_class, ctx: { current_user: current_user }, subscription_update: false) } + + it 'returns nil' do + expect(subject).to eq(nil) + end + + context 'when user is unauthorized' do + let(:current_user) { unauthorized_user } + + it 'raises an exception' do + expect { subject }.to raise_error(GraphQL::ExecutionError) + end + end + + context 'when issue does not exist' do + let(:issuable_id) { GlobalID.parse("gid://gitlab/Issue/#{non_existing_record_id}") } + + it 'raises an exception' do + expect { subject }.to raise_error(GraphQL::ExecutionError) + end + end + + context 'when a GraphQL::ID_TYPE is provided' do + let(:issuable_id) { issue.to_gid.to_s } + + it 'raises an exception' do + expect { subject }.to raise_error(Gitlab::Graphql::Errors::ArgumentError) + end + end + end + + context 'subscription updates' do + let(:resolver) { resolver_instance(described_class, obj: issue, ctx: { current_user: current_user }, subscription_update: true) } + + it 'returns the resolved object' do + expect(subject).to eq(issue) + end + + context 'when user is unauthorized' do + let(:current_user) { unauthorized_user } + + it 'unsubscribes the user' do + expect { subject }.to throw_symbol(:graphql_subscription_unsubscribed) + end + end + end + end +end |