debian-mirror-gitlab/spec/graphql/resolvers/users/snippets_resolver_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

84 lines
3.1 KiB
Ruby
Raw Normal View History

2020-01-01 13:55:28 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Resolvers::Users::SnippetsResolver do
2020-01-01 13:55:28 +05:30
include GraphqlHelpers
describe '#resolve' do
let_it_be(:current_user) { create(:user) }
let_it_be(:other_user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:private_personal_snippet) { create(:personal_snippet, :private, author: current_user) }
let_it_be(:public_personal_snippet) { create(:personal_snippet, :public, author: current_user) }
let_it_be(:other_personal_snippet) { create(:personal_snippet, :internal, author: other_user) }
let_it_be(:internal_project_snippet) { create(:project_snippet, :internal, author: current_user, project: project) }
let_it_be(:other_project_snippet) { create(:project_snippet, :public, author: other_user, project: project) }
before do
project.add_developer(current_user)
end
it 'calls SnippetsFinder' do
expect_next_instance_of(SnippetsFinder) do |finder|
expect(finder).to receive(:execute)
end
resolve_snippets
end
context 'when using no filter' do
it 'returns expected authored snippets' do
expect(resolve_snippets).to contain_exactly(private_personal_snippet, public_personal_snippet, internal_project_snippet)
end
end
context 'when using filters' do
it 'returns the snippets by visibility' do
aggregate_failures do
expect(resolve_snippets(args: { visibility: 'are_private' })).to contain_exactly(private_personal_snippet)
expect(resolve_snippets(args: { visibility: 'are_internal' })).to contain_exactly(internal_project_snippet)
expect(resolve_snippets(args: { visibility: 'are_public' })).to contain_exactly(public_personal_snippet)
end
end
it 'returns the snippets by type' do
aggregate_failures do
expect(resolve_snippets(args: { type: 'personal' })).to contain_exactly(private_personal_snippet, public_personal_snippet)
expect(resolve_snippets(args: { type: 'project' })).to contain_exactly(internal_project_snippet)
end
end
it 'returns the snippets by single gid' do
2021-02-22 17:27:13 +05:30
snippets = resolve_snippets(args: { ids: [global_id_of(private_personal_snippet)] })
2020-01-01 13:55:28 +05:30
expect(snippets).to contain_exactly(private_personal_snippet)
end
it 'returns the snippets by array of gid' do
2021-02-22 17:27:13 +05:30
snippets = [private_personal_snippet, public_personal_snippet]
args = { ids: snippets.map { |s| global_id_of(s) } }
2020-01-01 13:55:28 +05:30
2021-02-22 17:27:13 +05:30
found = resolve_snippets(args: args)
2020-01-01 13:55:28 +05:30
2021-02-22 17:27:13 +05:30
expect(found).to match_array(snippets)
2020-01-01 13:55:28 +05:30
end
end
2021-04-29 21:17:54 +05:30
context 'when user profile is private' do
it 'does not return snippets for that user' do
expect(resolve_snippets(obj: other_user)).to contain_exactly(other_personal_snippet, other_project_snippet)
other_user.update!(private_profile: true)
expect(resolve_snippets(obj: other_user)).to be_empty
end
end
2020-01-01 13:55:28 +05:30
end
2021-04-29 21:17:54 +05:30
def resolve_snippets(args: {}, context_user: current_user, obj: current_user)
resolve(described_class, args: args, ctx: { current_user: context_user }, obj: obj)
2020-01-01 13:55:28 +05:30
end
end