diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-12 15:06:26 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-12 15:06:26 +0000 |
commit | 69944ffb68788d190e81ff7e33db5dcb6c903184 (patch) | |
tree | 4112a1285f186c140749e8410a8a2788b6812500 /spec/graphql/mutations | |
parent | 1b7381e998ff4b33ec8f633766030082e95f10c8 (diff) | |
download | gitlab-ce-69944ffb68788d190e81ff7e33db5dcb6c903184.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/graphql/mutations')
-rw-r--r-- | spec/graphql/mutations/todos/mark_done_spec.rb | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/spec/graphql/mutations/todos/mark_done_spec.rb b/spec/graphql/mutations/todos/mark_done_spec.rb new file mode 100644 index 00000000000..761b153d5d1 --- /dev/null +++ b/spec/graphql/mutations/todos/mark_done_spec.rb @@ -0,0 +1,66 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Mutations::Todos::MarkDone do + 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(:other_user_todo) { create(:todo, user: other_user, author: author, state: :pending) } + + let(:mutation) { described_class.new(object: nil, context: { current_user: current_user }) } + + describe '#resolve' do + it 'marks a single todo as done' do + result = mark_done_mutation(todo1) + + expect(todo1.reload.state).to eq('done') + expect(todo2.reload.state).to eq('done') + expect(other_user_todo.reload.state).to eq('pending') + + todo = result[:todo] + expect(todo.id).to eq(todo1.id) + expect(todo.state).to eq('done') + end + + it 'handles a todo which is already done as expected' do + result = mark_done_mutation(todo2) + + expect(todo1.reload.state).to eq('pending') + expect(todo2.reload.state).to eq('done') + expect(other_user_todo.reload.state).to eq('pending') + + todo = result[:todo] + expect(todo.id).to eq(todo2.id) + expect(todo.state).to eq('done') + end + + it 'ignores requests for todos which do not belong to the current user' do + expect { mark_done_mutation(other_user_todo) }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + + expect(todo1.reload.state).to eq('pending') + expect(todo2.reload.state).to eq('done') + expect(other_user_todo.reload.state).to eq('pending') + end + + it 'ignores invalid GIDs' do + expect { mutation.resolve(id: 'invalid_gid') }.to raise_error(Gitlab::Graphql::Errors::ArgumentError) + + expect(todo1.reload.state).to eq('pending') + expect(todo2.reload.state).to eq('done') + expect(other_user_todo.reload.state).to eq('pending') + end + end + + 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 |