diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /spec/graphql/resolvers/user_discussions_count_resolver_spec.rb | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) | |
download | gitlab-ce-8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca.tar.gz |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/graphql/resolvers/user_discussions_count_resolver_spec.rb')
-rw-r--r-- | spec/graphql/resolvers/user_discussions_count_resolver_spec.rb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/spec/graphql/resolvers/user_discussions_count_resolver_spec.rb b/spec/graphql/resolvers/user_discussions_count_resolver_spec.rb new file mode 100644 index 00000000000..cc855bbcb53 --- /dev/null +++ b/spec/graphql/resolvers/user_discussions_count_resolver_spec.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Resolvers::UserDiscussionsCountResolver do + include GraphqlHelpers + + describe '#resolve' do + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :public) } + let_it_be(:private_project) { create(:project, :private) } + let_it_be(:issue) { create(:issue, project: project) } + let_it_be(:private_issue) { create(:issue, project: private_project) } + let_it_be(:public_discussions) { create_list(:discussion_note_on_issue, 2, noteable: issue, project: project) } + let_it_be(:system_discussion) { create(:discussion_note_on_issue, system: true, noteable: issue, project: project) } + let_it_be(:private_discussion) { create_list(:discussion_note_on_issue, 3, noteable: private_issue, project: private_project) } + + specify do + expect(described_class).to have_nullable_graphql_type(GraphQL::INT_TYPE) + end + + context 'when counting discussions from a public issue' do + subject { batch_sync { resolve_user_discussions_count(issue) } } + + it 'returns the number of discussions for the issue' do + expect(subject).to eq(2) + end + end + + context 'when a user has permission to view discussions' do + before do + private_project.add_developer(user) + end + + subject { batch_sync { resolve_user_discussions_count(private_issue) } } + + it 'returns the number of non-system discussions for the issue' do + expect(subject).to eq(3) + end + end + + context 'when a user does not have permission to view discussions' do + subject { batch_sync { resolve_user_discussions_count(private_issue) } } + + it 'returns no discussions' do + expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + end + end + end + + def resolve_user_discussions_count(obj) + resolve(described_class, obj: obj, ctx: { current_user: user }) + end +end |