diff options
Diffstat (limited to 'spec/graphql/mutations/todos')
-rw-r--r-- | spec/graphql/mutations/todos/create_spec.rb | 44 | ||||
-rw-r--r-- | spec/graphql/mutations/todos/mark_all_done_spec.rb | 2 | ||||
-rw-r--r-- | spec/graphql/mutations/todos/restore_many_spec.rb | 19 |
3 files changed, 56 insertions, 9 deletions
diff --git a/spec/graphql/mutations/todos/create_spec.rb b/spec/graphql/mutations/todos/create_spec.rb new file mode 100644 index 00000000000..bbb033e2f33 --- /dev/null +++ b/spec/graphql/mutations/todos/create_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Mutations::Todos::Create do + include GraphqlHelpers + include DesignManagementTestHelpers + + describe '#resolve' do + context 'when target does not support todos' do + it 'raises error' do + current_user = create(:user) + mutation = described_class.new(object: nil, context: { current_user: current_user }, field: nil) + + target = create(:milestone) + + expect { mutation.resolve(target_id: global_id_of(target)) } + .to raise_error(GraphQL::CoercionError) + end + end + + context 'with issue as target' do + it_behaves_like 'create todo mutation' do + let_it_be(:target) { create(:issue) } + end + end + + context 'with merge request as target' do + it_behaves_like 'create todo mutation' do + let_it_be(:target) { create(:merge_request) } + end + end + + context 'with design as target' do + before do + enable_design_management + end + + it_behaves_like 'create todo mutation' do + let_it_be(:target) { create(:design) } + end + end + end +end diff --git a/spec/graphql/mutations/todos/mark_all_done_spec.rb b/spec/graphql/mutations/todos/mark_all_done_spec.rb index 2f167164050..f3b6bf52ef7 100644 --- a/spec/graphql/mutations/todos/mark_all_done_spec.rb +++ b/spec/graphql/mutations/todos/mark_all_done_spec.rb @@ -28,7 +28,7 @@ RSpec.describe Mutations::Todos::MarkAllDone do 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)) + expect(updated_todo_ids).to contain_exactly(todo1.id, todo3.id) expect(todos).to contain_exactly(todo1, todo3) end diff --git a/spec/graphql/mutations/todos/restore_many_spec.rb b/spec/graphql/mutations/todos/restore_many_spec.rb index 59995e33f2d..dc10355ef22 100644 --- a/spec/graphql/mutations/todos/restore_many_spec.rb +++ b/spec/graphql/mutations/todos/restore_many_spec.rb @@ -24,11 +24,11 @@ RSpec.describe Mutations::Todos::RestoreMany do expect(todo2.reload.state).to eq('pending') expect(other_user_todo.reload.state).to eq('done') - todo_ids = result[:updated_ids] - expect(todo_ids.size).to eq(1) - expect(todo_ids.first).to eq(todo1.to_global_id.to_s) - - expect(result[:todos]).to contain_exactly(todo1) + expect(result).to match( + errors: be_empty, + updated_ids: contain_exactly(todo1.id), + todos: contain_exactly(todo1) + ) end it 'handles a todo which is already pending as expected' do @@ -36,8 +36,11 @@ RSpec.describe Mutations::Todos::RestoreMany do expect_states_were_not_changed - expect(result[:updated_ids]).to eq([]) - expect(result[:todos]).to be_empty + expect(result).to match( + errors: be_empty, + updated_ids: be_empty, + todos: be_empty + ) end it 'ignores requests for todos which do not belong to the current user' do @@ -61,7 +64,7 @@ RSpec.describe Mutations::Todos::RestoreMany do expect(result[:updated_ids].size).to eq(2) returned_todo_ids = result[:updated_ids] - expect(returned_todo_ids).to contain_exactly(todo1.to_global_id.to_s, todo4.to_global_id.to_s) + expect(returned_todo_ids).to contain_exactly(todo1.id, todo4.id) expect(result[:todos]).to contain_exactly(todo1, todo4) expect(todo1.reload.state).to eq('pending') |