debian-mirror-gitlab/spec/graphql/mutations/todos/restore_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

65 lines
2.1 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 Mutations::Todos::Restore do
2021-01-03 14:25:43 +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) }
2021-08-04 16:29:09 +05:30
let_it_be(:todo1) { create(:todo, user: current_user, author: author, state: :done, target: issue) }
let_it_be(:todo2) { 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: :done) }
2020-04-08 14:13:33 +05:30
let(:mutation) { described_class.new(object: nil, context: { current_user: current_user }, field: nil) }
2020-01-01 13:55:28 +05:30
2021-08-04 16:29:09 +05:30
before_all do
project.add_developer(current_user)
end
2020-05-24 23:13:21 +05:30
specify { expect(described_class).to require_graphql_authorizations(:update_todo) }
2020-01-01 13:55:28 +05:30
describe '#resolve' do
it 'restores a single todo' do
result = restore_mutation(todo1)
expect(todo1.reload.state).to eq('pending')
expect(todo2.reload.state).to eq('pending')
expect(other_user_todo.reload.state).to eq('done')
todo = result[:todo]
expect(todo.id).to eq(todo1.id)
expect(todo.state).to eq('pending')
end
it 'handles a todo which is already pending as expected' do
result = restore_mutation(todo2)
expect(todo1.reload.state).to eq('done')
expect(todo2.reload.state).to eq('pending')
expect(other_user_todo.reload.state).to eq('done')
todo = result[:todo]
expect(todo.id).to eq(todo2.id)
expect(todo.state).to eq('pending')
end
it 'ignores requests for todos which do not belong to the current user' do
expect { restore_mutation(other_user_todo) }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
expect(todo1.reload.state).to eq('done')
expect(todo2.reload.state).to eq('pending')
expect(other_user_todo.reload.state).to eq('done')
end
end
def restore_mutation(todo)
mutation.resolve(id: global_id_of(todo))
end
end