2019-10-17 11:06:17 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2022-06-28 14:08:20 -04:00
|
|
|
RSpec.describe Resolvers::TodosResolver do
|
2019-10-17 11:06:17 -04:00
|
|
|
include GraphqlHelpers
|
2021-08-03 17:09:39 -04:00
|
|
|
include DesignManagementTestHelpers
|
2019-10-17 11:06:17 -04:00
|
|
|
|
2020-11-09 19:08:52 -05:00
|
|
|
specify do
|
|
|
|
expect(described_class).to have_nullable_graphql_type(Types::TodoType.connection_type)
|
|
|
|
end
|
|
|
|
|
2019-10-17 11:06:17 -04:00
|
|
|
describe '#resolve' do
|
2021-08-03 17:09:39 -04:00
|
|
|
let_it_be(:project) { create(:project) }
|
2019-10-17 11:06:17 -04:00
|
|
|
let_it_be(:current_user) { create(:user) }
|
2021-08-03 17:09:39 -04:00
|
|
|
let_it_be(:issue) { create(:issue, project: project) }
|
2019-10-17 11:06:17 -04:00
|
|
|
let_it_be(:author1) { create(:user) }
|
|
|
|
let_it_be(:author2) { create(:user) }
|
|
|
|
|
2021-08-03 17:09:39 -04:00
|
|
|
let_it_be(:issue_todo_done) { create(:todo, user: current_user, state: :done, action: Todo::ASSIGNED, author: author2, target: issue) }
|
|
|
|
let_it_be(:issue_todo_pending) { create(:todo, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author1, target: issue) }
|
|
|
|
|
|
|
|
let(:merge_request) { create(:merge_request, source_project: project) }
|
|
|
|
let!(:merge_request_todo_pending) { create(:todo, user: current_user, target: merge_request, state: :pending, action: Todo::MENTIONED, author: author1) }
|
|
|
|
|
|
|
|
before_all do
|
|
|
|
project.add_developer(current_user)
|
|
|
|
end
|
2019-10-17 11:06:17 -04:00
|
|
|
|
|
|
|
it 'calls TodosFinder' do
|
|
|
|
expect_next_instance_of(TodosFinder) do |finder|
|
2020-12-13 22:10:06 -05:00
|
|
|
expect(finder).to receive(:execute).and_call_original
|
2019-10-17 11:06:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
resolve_todos
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when using no filter' do
|
2020-06-24 14:09:03 -04:00
|
|
|
it 'returns pending todos' do
|
|
|
|
expect(resolve_todos).to contain_exactly(merge_request_todo_pending, issue_todo_pending)
|
2019-10-17 11:06:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when using filters' do
|
2019-11-19 16:06:22 -05:00
|
|
|
it 'returns the todos for multiple states' do
|
2020-06-24 14:09:03 -04:00
|
|
|
todos = resolve_todos(state: [:done, :pending])
|
2019-10-17 11:06:17 -04:00
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
expect(todos).to contain_exactly(merge_request_todo_pending, issue_todo_done, issue_todo_pending)
|
2019-10-17 11:06:17 -04:00
|
|
|
end
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
it 'returns the todos for multiple filters' do
|
2021-08-03 17:09:39 -04:00
|
|
|
enable_design_management
|
|
|
|
design = create(:design, issue: issue)
|
|
|
|
design_todo_pending = create(:todo, target: design, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author1)
|
2019-10-17 11:06:17 -04:00
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
todos = resolve_todos(type: ['MergeRequest', 'DesignManagement::Design'])
|
|
|
|
|
|
|
|
expect(todos).to contain_exactly(merge_request_todo_pending, design_todo_pending)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the todos for single filter' do
|
2020-12-13 22:10:06 -05:00
|
|
|
todos = resolve_todos(type: ['MergeRequest'])
|
2020-06-24 14:09:03 -04:00
|
|
|
|
|
|
|
expect(todos).to contain_exactly(merge_request_todo_pending)
|
2019-10-17 11:06:17 -04:00
|
|
|
end
|
|
|
|
|
2019-11-19 16:06:22 -05:00
|
|
|
it 'returns the todos for multiple groups' do
|
|
|
|
group1 = create(:group)
|
|
|
|
group2 = create(:group)
|
|
|
|
group3 = create(:group)
|
|
|
|
|
|
|
|
group1.add_developer(current_user)
|
2021-08-03 17:09:39 -04:00
|
|
|
issue1 = create(:issue, project: create(:project, group: group1))
|
2019-11-19 16:06:22 -05:00
|
|
|
group2.add_developer(current_user)
|
2021-08-03 17:09:39 -04:00
|
|
|
issue2 = create(:issue, project: create(:project, group: group2))
|
|
|
|
group3.add_developer(current_user)
|
|
|
|
issue3 = create(:issue, project: create(:project, group: group3))
|
2019-10-17 11:06:17 -04:00
|
|
|
|
2021-08-03 17:09:39 -04:00
|
|
|
todo4 = create(:todo, group: group1, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author1, target: issue1)
|
|
|
|
todo5 = create(:todo, group: group2, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author1, target: issue2)
|
|
|
|
create(:todo, group: group3, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author1, target: issue3)
|
2019-10-17 11:06:17 -04:00
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
todos = resolve_todos(group_id: [group2.id, group1.id])
|
2019-11-19 16:06:22 -05:00
|
|
|
|
|
|
|
expect(todos).to contain_exactly(todo4, todo5)
|
2019-10-17 11:06:17 -04:00
|
|
|
end
|
|
|
|
|
2019-11-19 16:06:22 -05:00
|
|
|
it 'returns the todos for multiple authors' do
|
|
|
|
author3 = create(:user)
|
2019-10-17 11:06:17 -04:00
|
|
|
|
2019-11-19 16:06:22 -05:00
|
|
|
create(:todo, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author3)
|
2019-10-17 11:06:17 -04:00
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
todos = resolve_todos(author_id: [author2.id, author1.id])
|
2019-10-17 11:06:17 -04:00
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
expect(todos).to contain_exactly(merge_request_todo_pending, issue_todo_pending)
|
2019-10-17 11:06:17 -04:00
|
|
|
end
|
|
|
|
|
2019-11-19 16:06:22 -05:00
|
|
|
it 'returns the todos for multiple actions' do
|
|
|
|
create(:todo, user: current_user, state: :pending, action: Todo::DIRECTLY_ADDRESSED, author: author1)
|
2019-10-17 11:06:17 -04:00
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
todos = resolve_todos(action: [Todo::MENTIONED, Todo::ASSIGNED])
|
2019-10-17 11:06:17 -04:00
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
expect(todos).to contain_exactly(merge_request_todo_pending, issue_todo_pending)
|
2019-11-19 16:06:22 -05:00
|
|
|
end
|
2019-10-17 11:06:17 -04:00
|
|
|
|
2019-11-19 16:06:22 -05:00
|
|
|
it 'returns the todos for multiple projects' do
|
|
|
|
project1 = create(:project)
|
|
|
|
project2 = create(:project)
|
|
|
|
project3 = create(:project)
|
2019-10-17 11:06:17 -04:00
|
|
|
|
2021-08-03 17:09:39 -04:00
|
|
|
project1.add_developer(current_user)
|
|
|
|
project2.add_developer(current_user)
|
|
|
|
project3.add_developer(current_user)
|
|
|
|
|
|
|
|
todo4 = create(:todo, project: project1, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author1, target: create(:issue, project: project1))
|
|
|
|
todo5 = create(:todo, project: project2, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author1, target: create(:issue, project: project2))
|
|
|
|
create(:todo, project: project3, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author1, target: create(:issue, project: project3))
|
2019-10-17 11:06:17 -04:00
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
todos = resolve_todos(project_id: [project2.id, project1.id])
|
2019-10-17 11:06:17 -04:00
|
|
|
|
2019-11-19 16:06:22 -05:00
|
|
|
expect(todos).to contain_exactly(todo4, todo5)
|
2019-10-17 11:06:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-03 11:09:44 -04:00
|
|
|
context 'when no target is provided' do
|
2019-10-17 11:06:17 -04:00
|
|
|
it 'returns no todos' do
|
|
|
|
todos = resolve(described_class, obj: nil, args: {}, ctx: { current_user: current_user })
|
|
|
|
|
|
|
|
expect(todos).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-03 11:09:44 -04:00
|
|
|
context 'when target user is not the current user' do
|
2019-10-17 11:06:17 -04:00
|
|
|
it 'returns no todos' do
|
2019-11-19 16:06:22 -05:00
|
|
|
other_user = create(:user)
|
|
|
|
|
|
|
|
todos = resolve(described_class, obj: other_user, args: {}, ctx: { current_user: current_user })
|
2019-10-17 11:06:17 -04:00
|
|
|
|
|
|
|
expect(todos).to be_empty
|
|
|
|
end
|
|
|
|
end
|
2020-08-03 11:09:44 -04:00
|
|
|
|
|
|
|
context 'when request is for a todo target' do
|
|
|
|
it 'returns only the todos for the target' do
|
|
|
|
target = issue_todo_pending.target
|
|
|
|
|
|
|
|
todos = resolve(described_class, obj: target, args: {}, ctx: { current_user: current_user })
|
|
|
|
|
|
|
|
expect(todos).to contain_exactly(issue_todo_pending)
|
|
|
|
end
|
|
|
|
end
|
2019-10-17 11:06:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def resolve_todos(args = {}, context = { current_user: current_user })
|
|
|
|
resolve(described_class, obj: current_user, args: args, ctx: context)
|
|
|
|
end
|
|
|
|
end
|