diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-21 21:06:26 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-21 21:06:26 +0300 |
commit | 7aada820a908502f40080274fb181281afd44615 (patch) | |
tree | e82fbe264cb5d410fce7acea0a7fd74a962952ba /spec/requests/api/graphql/mutations | |
parent | b5ad06174bb1de39438c90847abb86ac6988e944 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests/api/graphql/mutations')
-rw-r--r-- | spec/requests/api/graphql/mutations/todos/mark_all_done_spec.rb | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/spec/requests/api/graphql/mutations/todos/mark_all_done_spec.rb b/spec/requests/api/graphql/mutations/todos/mark_all_done_spec.rb new file mode 100644 index 00000000000..40e085027d7 --- /dev/null +++ b/spec/requests/api/graphql/mutations/todos/mark_all_done_spec.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'Marking all todos done' 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(:other_user2) { 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(:input) { {} } + + let(:mutation) do + graphql_mutation(:todos_mark_all_done, input, + <<-QL.strip_heredoc + clientMutationId + errors + updatedIds + QL + ) + end + + def mutation_response + graphql_mutation_response(:todos_mark_all_done) + end + + it 'marks all pending todos as done' do + post_graphql_mutation(mutation, current_user: current_user) + + 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') + + updated_todo_ids = mutation_response['updatedIds'] + 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 + post_graphql_mutation(mutation, current_user: other_user2) + + 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') + + updated_todo_ids = mutation_response['updatedIds'] + expect(updated_todo_ids).to be_empty + end + + context 'when user is not logged in' do + let(:current_user) { nil } + + it_behaves_like 'a mutation that returns top-level errors', + errors: ['The resource that you are attempting to access does not exist or you don\'t have permission to perform this action'] + end +end |