debian-mirror-gitlab/spec/requests/api/graphql/mutations/todos/mark_all_done_spec.rb

71 lines
2.2 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 'Marking all todos done' do
2020-01-01 13:55:28 +05:30
include GraphqlHelpers
2021-08-04 16:29:09 +05:30
let_it_be(:project) { create(:project) }
let_it_be(:issue) { create(:issue, project: project) }
2020-01-01 13:55:28 +05:30
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) }
2021-08-04 16:29:09 +05:30
let_it_be(:todo1) { create(:todo, user: current_user, author: author, state: :pending, target: issue) }
let_it_be(:todo2) { create(:todo, user: current_user, author: author, state: :done, target: issue) }
let_it_be(:todo3) { create(:todo, user: current_user, author: author, state: :pending, target: issue) }
2020-01-01 13:55:28 +05:30
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
2021-09-04 01:27:46 +05:30
todos { id }
2020-01-01 13:55:28 +05:30
errors
QL
)
end
2021-08-04 16:29:09 +05:30
before_all do
project.add_developer(current_user)
end
2020-01-01 13:55:28 +05:30
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')
2021-09-04 01:27:46 +05:30
updated_todo_ids = mutation_response['todos'].map { |todo| todo['id'] }
2020-01-01 13:55:28 +05:30
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')
2021-09-04 01:27:46 +05:30
updated_todo_ids = mutation_response['todos']
2020-01-01 13:55:28 +05:30
expect(updated_todo_ids).to be_empty
end
context 'when user is not logged in' do
let(:current_user) { nil }
2020-11-24 15:15:51 +05:30
it_behaves_like 'a mutation that returns a top-level access error'
2020-01-01 13:55:28 +05:30
end
end