2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Resolvers::TodoResolver do
|
|
|
|
include GraphqlHelpers
|
|
|
|
|
|
|
|
describe '#resolve' do
|
|
|
|
let_it_be(:current_user) { create(:user) }
|
|
|
|
let_it_be(:author1) { create(:user) }
|
|
|
|
let_it_be(:author2) { create(:user) }
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
let_it_be(:todo1) { create(:todo, user: current_user, target_type: 'MergeRequest', state: :pending, action: Todo::MENTIONED, author: author1) }
|
|
|
|
let_it_be(:todo2) { create(:todo, user: current_user, state: :done, action: Todo::ASSIGNED, author: author2) }
|
|
|
|
let_it_be(:todo3) { create(:todo, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author1) }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
it 'calls TodosFinder' do
|
|
|
|
expect_next_instance_of(TodosFinder) do |finder|
|
|
|
|
expect(finder).to receive(:execute)
|
|
|
|
end
|
|
|
|
|
|
|
|
resolve_todos
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when using no filter' do
|
|
|
|
it 'returns expected todos' do
|
2020-01-01 13:55:28 +05:30
|
|
|
expect(resolve_todos).to contain_exactly(todo1, todo3)
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when using filters' do
|
2020-01-01 13:55:28 +05:30
|
|
|
it 'returns the todos for multiple states' do
|
|
|
|
todos = resolve_todos({ state: [:done, :pending] })
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
expect(todos).to contain_exactly(todo1, todo2, todo3)
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
it 'returns the todos for multiple types' do
|
|
|
|
todos = resolve_todos({ type: %w[Issue MergeRequest] })
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
expect(todos).to contain_exactly(todo1, todo3)
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
it 'returns the todos for multiple groups' do
|
|
|
|
group1 = create(:group)
|
|
|
|
group2 = create(:group)
|
|
|
|
group3 = create(:group)
|
|
|
|
|
|
|
|
group1.add_developer(current_user)
|
|
|
|
group2.add_developer(current_user)
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
todo4 = create(:todo, group: group1, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author1)
|
|
|
|
todo5 = create(:todo, group: group2, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author1)
|
|
|
|
create(:todo, group: group3, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author1)
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
todos = resolve_todos({ group_id: [group2.id, group1.id] })
|
|
|
|
|
|
|
|
expect(todos).to contain_exactly(todo4, todo5)
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
it 'returns the todos for multiple authors' do
|
|
|
|
author3 = create(:user)
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
todo4 = create(:todo, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author2)
|
|
|
|
create(:todo, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author3)
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
todos = resolve_todos({ author_id: [author2.id, author1.id] })
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
expect(todos).to contain_exactly(todo1, todo3, todo4)
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
it 'returns the todos for multiple actions' do
|
|
|
|
create(:todo, user: current_user, state: :pending, action: Todo::DIRECTLY_ADDRESSED, author: author1)
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
todos = resolve_todos({ action: [Todo::MENTIONED, Todo::ASSIGNED] })
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
expect(todos).to contain_exactly(todo1, todo3)
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
it 'returns the todos for multiple projects' do
|
|
|
|
project1 = create(:project)
|
|
|
|
project2 = create(:project)
|
|
|
|
project3 = create(:project)
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
todo4 = create(:todo, project: project1, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author1)
|
|
|
|
todo5 = create(:todo, project: project2, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author1)
|
|
|
|
create(:todo, project: project3, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author1)
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
todos = resolve_todos({ project_id: [project2.id, project1.id] })
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
expect(todos).to contain_exactly(todo4, todo5)
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when no user is provided' do
|
|
|
|
it 'returns no todos' do
|
|
|
|
todos = resolve(described_class, obj: nil, args: {}, ctx: { current_user: current_user })
|
|
|
|
|
|
|
|
expect(todos).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when provided user is not current user' do
|
|
|
|
it 'returns no todos' do
|
2020-01-01 13:55:28 +05:30
|
|
|
other_user = create(:user)
|
|
|
|
|
|
|
|
todos = resolve(described_class, obj: other_user, args: {}, ctx: { current_user: current_user })
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
expect(todos).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def resolve_todos(args = {}, context = { current_user: current_user })
|
|
|
|
resolve(described_class, obj: current_user, args: args, ctx: context)
|
|
|
|
end
|
|
|
|
end
|