Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/graphql')
-rw-r--r--spec/graphql/mutations/concerns/mutations/resolves_group_spec.rb21
-rw-r--r--spec/graphql/resolvers/todo_resolver_spec.rb113
-rw-r--r--spec/graphql/types/query_type_spec.rb2
-rw-r--r--spec/graphql/types/todo_type_spec.rb13
4 files changed, 148 insertions, 1 deletions
diff --git a/spec/graphql/mutations/concerns/mutations/resolves_group_spec.rb b/spec/graphql/mutations/concerns/mutations/resolves_group_spec.rb
new file mode 100644
index 00000000000..897b8f4e9ef
--- /dev/null
+++ b/spec/graphql/mutations/concerns/mutations/resolves_group_spec.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Mutations::ResolvesGroup do
+ let(:mutation_class) do
+ Class.new(Mutations::BaseMutation) do
+ include Mutations::ResolvesGroup
+ end
+ end
+
+ let(:context) { double }
+ subject(:mutation) { mutation_class.new(object: nil, context: context) }
+
+ it 'uses the GroupsResolver to resolve groups by path' do
+ group = create(:group)
+
+ expect(Resolvers::GroupResolver).to receive(:new).with(object: nil, context: context).and_call_original
+ expect(mutation.resolve_group(full_path: group.full_path).sync).to eq(group)
+ end
+end
diff --git a/spec/graphql/resolvers/todo_resolver_spec.rb b/spec/graphql/resolvers/todo_resolver_spec.rb
new file mode 100644
index 00000000000..fef761d7243
--- /dev/null
+++ b/spec/graphql/resolvers/todo_resolver_spec.rb
@@ -0,0 +1,113 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Resolvers::TodoResolver do
+ include GraphqlHelpers
+
+ describe '#resolve' do
+ let_it_be(:current_user) { create(:user) }
+ let_it_be(:user) { create(:user) }
+ let_it_be(:author1) { create(:user) }
+ let_it_be(:author2) { create(:user) }
+
+ let_it_be(:todo1) { create(:todo, user: user, target_type: 'MergeRequest', state: :pending, action: Todo::MENTIONED, author: author1) }
+ let_it_be(:todo2) { create(:todo, user: user, state: :done, action: Todo::ASSIGNED, author: author2) }
+ let_it_be(:todo3) { create(:todo, user: user, state: :pending, action: Todo::ASSIGNED, author: author1) }
+
+ it 'calls TodosFinder' do
+ expect_next_instance_of(TodosFinder) do |finder|
+ expect(finder).to receive(:execute)
+ end
+
+ resolve_todos
+ end
+
+ context 'when using no filter' do
+ it 'returns expected todos' do
+ todos = resolve(described_class, obj: user, args: {}, ctx: { current_user: user })
+
+ expect(todos).to contain_exactly(todo1, todo3)
+ end
+ end
+
+ context 'when using filters' do
+ # TODO These can be removed as soon as we support filtering for multiple field contents for todos
+
+ it 'just uses the first state' do
+ todos = resolve(described_class, obj: user, args: { state: [:done, :pending] }, ctx: { current_user: user })
+
+ expect(todos).to contain_exactly(todo2)
+ end
+
+ it 'just uses the first action' do
+ todos = resolve(described_class, obj: user, args: { action: [Todo::MENTIONED, Todo::ASSIGNED] }, ctx: { current_user: user })
+
+ expect(todos).to contain_exactly(todo1)
+ end
+
+ it 'just uses the first author id' do
+ # We need a pending todo for now because of TodosFinder's state query
+ todo4 = create(:todo, user: user, state: :pending, action: Todo::ASSIGNED, author: author2)
+
+ todos = resolve(described_class, obj: user, args: { author_id: [author2.id, author1.id] }, ctx: { current_user: user })
+
+ expect(todos).to contain_exactly(todo4)
+ end
+
+ it 'just uses the first project id' do
+ project1 = create(:project)
+ project2 = create(:project)
+
+ create(:todo, project: project1, user: user, state: :pending, action: Todo::ASSIGNED, author: author1)
+ todo5 = create(:todo, project: project2, user: user, state: :pending, action: Todo::ASSIGNED, author: author1)
+
+ todos = resolve(described_class, obj: user, args: { project_id: [project2.id, project1.id] }, ctx: { current_user: user })
+
+ expect(todos).to contain_exactly(todo5)
+ end
+
+ it 'just uses the first group id' do
+ group1 = create(:group)
+ group2 = create(:group)
+
+ group1.add_developer(user)
+ group2.add_developer(user)
+
+ create(:todo, group: group1, user: user, state: :pending, action: Todo::ASSIGNED, author: author1)
+ todo5 = create(:todo, group: group2, user: user, state: :pending, action: Todo::ASSIGNED, author: author1)
+
+ todos = resolve(described_class, obj: user, args: { group_id: [group2.id, group1.id] }, ctx: { current_user: user })
+
+ expect(todos).to contain_exactly(todo5)
+ end
+
+ it 'just uses the first target' do
+ todos = resolve(described_class, obj: user, args: { type: %w[Issue MergeRequest] }, ctx: { current_user: user })
+
+ # Just todo3 because todo2 is in state "done"
+ expect(todos).to contain_exactly(todo3)
+ end
+ end
+
+ context 'when no user is provided' do
+ it 'returns no todos' do
+ todos = resolve(described_class, obj: nil, args: {}, ctx: { current_user: current_user })
+
+ expect(todos).to be_empty
+ end
+ end
+
+ context 'when provided user is not current user' do
+ it 'returns no todos' do
+ todos = resolve(described_class, obj: user, args: {}, ctx: { current_user: current_user })
+
+ expect(todos).to be_empty
+ end
+ end
+ end
+
+ def resolve_todos(args = {}, context = { current_user: current_user })
+ resolve(described_class, obj: current_user, args: args, ctx: context)
+ end
+end
diff --git a/spec/graphql/types/query_type_spec.rb b/spec/graphql/types/query_type_spec.rb
index 784a4f4b4c9..1365bc0dc14 100644
--- a/spec/graphql/types/query_type_spec.rb
+++ b/spec/graphql/types/query_type_spec.rb
@@ -7,7 +7,7 @@ describe GitlabSchema.types['Query'] do
expect(described_class.graphql_name).to eq('Query')
end
- it { is_expected.to have_graphql_fields(:project, :namespace, :group, :echo, :metadata) }
+ it { is_expected.to have_graphql_fields(:project, :namespace, :group, :echo, :metadata, :current_user) }
describe 'namespace field' do
subject { described_class.fields['namespace'] }
diff --git a/spec/graphql/types/todo_type_spec.rb b/spec/graphql/types/todo_type_spec.rb
new file mode 100644
index 00000000000..a5ea5bcffb0
--- /dev/null
+++ b/spec/graphql/types/todo_type_spec.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe GitlabSchema.types['Todo'] do
+ it 'has the correct fields' do
+ expected_fields = [:id, :project, :group, :author, :action, :target_type, :body, :state, :created_at]
+
+ is_expected.to have_graphql_fields(*expected_fields)
+ end
+
+ it { expect(described_class).to require_graphql_authorizations(:read_todo) }
+end