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

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

56 lines
1.8 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::MarkAllDone do
2020-01-01 13:55:28 +05:30
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(: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_it_be(:user3) { create(:user) }
2020-05-24 23:13:21 +05:30
specify { expect(described_class).to require_graphql_authorizations(:update_user) }
2020-01-01 13:55:28 +05:30
describe '#resolve' do
it 'marks all pending todos as done' do
2021-09-04 01:27:46 +05:30
todos = mutation_for(current_user).resolve[:todos]
2020-01-01 13:55:28 +05:30
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')
2020-07-28 23:09:34 +05:30
expect(todos).to contain_exactly(todo1, todo3)
2020-01-01 13:55:28 +05:30
end
it 'behaves as expected if there are no todos for the requesting user' do
2021-09-04 01:27:46 +05:30
todos = mutation_for(user3).resolve[:todos]
2020-01-01 13:55:28 +05:30
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
expect(todos).to be_empty
2020-01-01 13:55:28 +05:30
end
context 'when user is not logged in' do
it 'fails with the expected error' do
expect { mutation_for(nil).resolve }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end
end
def mutation_for(user)
2020-04-08 14:13:33 +05:30
described_class.new(object: nil, context: { current_user: user }, field: nil)
2020-01-01 13:55:28 +05:30
end
end