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:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-11-21 21:06:26 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-11-21 21:06:26 +0300
commit7aada820a908502f40080274fb181281afd44615 (patch)
treee82fbe264cb5d410fce7acea0a7fd74a962952ba /spec/graphql/mutations
parentb5ad06174bb1de39438c90847abb86ac6988e944 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/graphql/mutations')
-rw-r--r--spec/graphql/mutations/todos/mark_all_done_spec.rb53
-rw-r--r--spec/graphql/mutations/todos/mark_done_spec.rb6
2 files changed, 55 insertions, 4 deletions
diff --git a/spec/graphql/mutations/todos/mark_all_done_spec.rb b/spec/graphql/mutations/todos/mark_all_done_spec.rb
new file mode 100644
index 00000000000..cce69d0dcdc
--- /dev/null
+++ b/spec/graphql/mutations/todos/mark_all_done_spec.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Mutations::Todos::MarkAllDone do
+ include GraphqlHelpers
+
+ let_it_be(:current_user) { create(:user) }
+ let_it_be(:author) { create(:user) }
+ let_it_be(:other_user) { create(:user) }
+
+ let_it_be(:todo1) { create(:todo, user: current_user, author: author, state: :pending) }
+ let_it_be(:todo2) { create(:todo, user: current_user, author: author, state: :done) }
+ let_it_be(:todo3) { create(:todo, user: current_user, author: author, state: :pending) }
+
+ let_it_be(:other_user_todo) { create(:todo, user: other_user, author: author, state: :pending) }
+
+ let_it_be(:user3) { create(:user) }
+
+ describe '#resolve' do
+ it 'marks all pending todos as done' do
+ updated_todo_ids = mutation_for(current_user).resolve.dig(:updated_ids)
+
+ expect(todo1.reload.state).to eq('done')
+ expect(todo2.reload.state).to eq('done')
+ expect(todo3.reload.state).to eq('done')
+ expect(other_user_todo.reload.state).to eq('pending')
+
+ expect(updated_todo_ids).to contain_exactly(global_id_of(todo1), global_id_of(todo3))
+ end
+
+ it 'behaves as expected if there are no todos for the requesting user' do
+ updated_todo_ids = mutation_for(user3).resolve.dig(:updated_ids)
+
+ expect(todo1.reload.state).to eq('pending')
+ expect(todo2.reload.state).to eq('done')
+ expect(todo3.reload.state).to eq('pending')
+ expect(other_user_todo.reload.state).to eq('pending')
+
+ expect(updated_todo_ids).to be_empty
+ end
+
+ context 'when user is not logged in' do
+ it 'fails with the expected error' do
+ expect { mutation_for(nil).resolve }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ end
+ end
+ end
+
+ def mutation_for(user)
+ described_class.new(object: nil, context: { current_user: user })
+ end
+end
diff --git a/spec/graphql/mutations/todos/mark_done_spec.rb b/spec/graphql/mutations/todos/mark_done_spec.rb
index 761b153d5d1..ff61ef76db6 100644
--- a/spec/graphql/mutations/todos/mark_done_spec.rb
+++ b/spec/graphql/mutations/todos/mark_done_spec.rb
@@ -3,6 +3,8 @@
require 'spec_helper'
describe Mutations::Todos::MarkDone do
+ include GraphqlHelpers
+
let_it_be(:current_user) { create(:user) }
let_it_be(:author) { create(:user) }
let_it_be(:other_user) { create(:user) }
@@ -59,8 +61,4 @@ describe Mutations::Todos::MarkDone do
def mark_done_mutation(todo)
mutation.resolve(id: global_id_of(todo))
end
-
- def global_id_of(todo)
- todo.to_global_id.to_s
- end
end