2020-10-24 23:57:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
RSpec.describe 'Resolvers::ProjectMilestonesResolver' do
|
2020-10-24 23:57:45 +05:30
|
|
|
include GraphqlHelpers
|
|
|
|
|
|
|
|
describe '#resolve' do
|
2022-07-23 23:45:48 +05:30
|
|
|
let_it_be(:described_class) { Resolvers::ProjectMilestonesResolver }
|
2020-10-24 23:57:45 +05:30
|
|
|
let_it_be(:project) { create(:project, :private) }
|
|
|
|
let_it_be(:current_user) { create(:user) }
|
2022-07-23 23:45:48 +05:30
|
|
|
let_it_be(:now) { Time.now }
|
|
|
|
let_it_be(:now_date) { now.to_date }
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
before_all do
|
|
|
|
project.add_developer(current_user)
|
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
def args(**arguments)
|
|
|
|
satisfy("contain only #{arguments.inspect}") do |passed|
|
|
|
|
expect(passed.compact).to match(arguments)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
def resolve_project_milestones(args = {}, context = { current_user: current_user })
|
|
|
|
resolve(described_class, obj: project, args: args, ctx: context)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls MilestonesFinder to retrieve all milestones' do
|
|
|
|
expect(MilestonesFinder).to receive(:new)
|
2022-07-23 23:45:48 +05:30
|
|
|
.with(args(project_ids: project.id, state: 'all', sort: :due_date_asc))
|
2020-10-24 23:57:45 +05:30
|
|
|
.and_call_original
|
|
|
|
|
|
|
|
resolve_project_milestones
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when including ancestor milestones' do
|
|
|
|
let(:parent_group) { create(:group) }
|
|
|
|
let(:group) { create(:group, parent: parent_group) }
|
|
|
|
let(:project) { create(:project, group: group) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls MilestonesFinder with correct parameters' do
|
|
|
|
expect(MilestonesFinder).to receive(:new)
|
2022-07-23 23:45:48 +05:30
|
|
|
.with(args(project_ids: project.id, group_ids: contain_exactly(group, parent_group),
|
|
|
|
state: 'all', sort: :due_date_asc))
|
2020-10-24 23:57:45 +05:30
|
|
|
.and_call_original
|
|
|
|
|
|
|
|
resolve_project_milestones(include_ancestors: true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'by ids' do
|
|
|
|
it 'calls MilestonesFinder with correct parameters' do
|
|
|
|
milestone = create(:milestone, project: project)
|
|
|
|
|
|
|
|
expect(MilestonesFinder).to receive(:new)
|
2022-07-23 23:45:48 +05:30
|
|
|
.with(args(ids: [milestone.id.to_s], project_ids: project.id, state: 'all', sort: :due_date_asc))
|
2020-10-24 23:57:45 +05:30
|
|
|
.and_call_original
|
|
|
|
|
|
|
|
resolve_project_milestones(ids: [milestone.to_global_id])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'by state' do
|
|
|
|
it 'calls MilestonesFinder with correct parameters' do
|
|
|
|
expect(MilestonesFinder).to receive(:new)
|
2022-07-23 23:45:48 +05:30
|
|
|
.with(args(project_ids: project.id, state: 'closed', sort: :due_date_asc))
|
2020-10-24 23:57:45 +05:30
|
|
|
.and_call_original
|
|
|
|
|
|
|
|
resolve_project_milestones(state: 'closed')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
context 'by sort' do
|
|
|
|
it 'calls MilestonesFinder with correct parameters' do
|
|
|
|
expect(MilestonesFinder).to receive(:new)
|
2022-07-23 23:45:48 +05:30
|
|
|
.with(args(project_ids: project.id, state: 'all', sort: :due_date_asc))
|
2021-09-30 23:02:18 +05:30
|
|
|
.and_call_original
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
resolve_project_milestones(sort: 'DUE_DATE_ASC')
|
2021-09-30 23:02:18 +05:30
|
|
|
end
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
%w[EXPIRED_LAST_DUE_DATE_ASC EXPIRED_LAST_DUE_DATE_DESC].each do |sort_by|
|
2021-09-30 23:02:18 +05:30
|
|
|
it "uses offset-pagination when sorting by #{sort_by}" do
|
|
|
|
resolved = resolve_project_milestones(sort: sort_by)
|
|
|
|
|
|
|
|
expect(resolved).to be_a(::Gitlab::Graphql::Pagination::OffsetActiveRecordRelationConnection)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
context 'by timeframe' do
|
|
|
|
context 'when start_date and end_date are present' do
|
|
|
|
it 'calls MilestonesFinder with correct parameters' do
|
2022-07-23 23:45:48 +05:30
|
|
|
start_date = now
|
|
|
|
end_date = now + 5.days
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
expect(MilestonesFinder).to receive(:new)
|
2022-07-23 23:45:48 +05:30
|
|
|
.with(args(project_ids: project.id, state: 'all',
|
|
|
|
start_date: start_date, end_date: end_date, sort: :due_date_asc))
|
2020-10-24 23:57:45 +05:30
|
|
|
.and_call_original
|
|
|
|
|
|
|
|
resolve_project_milestones(start_date: start_date, end_date: end_date)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when start date is after end_date' do
|
2022-05-07 20:08:51 +05:30
|
|
|
it 'generates an error' do
|
|
|
|
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, 'startDate is after endDate') do
|
2022-07-23 23:45:48 +05:30
|
|
|
resolve_project_milestones(start_date: now, end_date: now - 2.days)
|
2022-05-07 20:08:51 +05:30
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when only start_date is present' do
|
2022-05-07 20:08:51 +05:30
|
|
|
it 'generates an error' do
|
|
|
|
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, /Both startDate and endDate/) do
|
2022-07-23 23:45:48 +05:30
|
|
|
resolve_project_milestones(start_date: now)
|
2022-05-07 20:08:51 +05:30
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when only end_date is present' do
|
2022-05-07 20:08:51 +05:30
|
|
|
it 'generates an error' do
|
|
|
|
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError, /Both startDate and endDate/) do
|
2022-07-23 23:45:48 +05:30
|
|
|
resolve_project_milestones(end_date: now)
|
2022-05-07 20:08:51 +05:30
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
context 'when passing a timeframe' do
|
|
|
|
it 'calls MilestonesFinder with correct parameters' do
|
2022-07-23 23:45:48 +05:30
|
|
|
start_date = now_date
|
|
|
|
end_date = now_date + 5.days
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
expect(MilestonesFinder).to receive(:new)
|
2022-07-23 23:45:48 +05:30
|
|
|
.with(args(project_ids: project.id, state: 'all',
|
|
|
|
sort: :due_date_asc, start_date: start_date, end_date: end_date))
|
2021-01-03 14:25:43 +05:30
|
|
|
.and_call_original
|
|
|
|
|
|
|
|
resolve_project_milestones(timeframe: { start: start_date, end: end_date })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when title is present' do
|
|
|
|
it 'calls MilestonesFinder with correct parameters' do
|
|
|
|
expect(MilestonesFinder).to receive(:new)
|
2022-07-23 23:45:48 +05:30
|
|
|
.with(args(title: '13.5', state: 'all', sort: :due_date_asc, project_ids: project.id))
|
2021-01-03 14:25:43 +05:30
|
|
|
.and_call_original
|
|
|
|
|
|
|
|
resolve_project_milestones(title: '13.5')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when search_title is present' do
|
|
|
|
it 'calls MilestonesFinder with correct parameters' do
|
|
|
|
expect(MilestonesFinder).to receive(:new)
|
2022-07-23 23:45:48 +05:30
|
|
|
.with(args(search_title: '13', state: 'all', sort: :due_date_asc, project_ids: project.id))
|
2021-01-03 14:25:43 +05:30
|
|
|
.and_call_original
|
|
|
|
|
|
|
|
resolve_project_milestones(search_title: '13')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when containing date is present' do
|
|
|
|
it 'calls MilestonesFinder with correct parameters' do
|
2022-07-23 23:45:48 +05:30
|
|
|
t = now
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
expect(MilestonesFinder).to receive(:new)
|
2022-07-23 23:45:48 +05:30
|
|
|
.with(args(containing_date: t, state: 'all', sort: :due_date_asc, project_ids: project.id))
|
2021-01-03 14:25:43 +05:30
|
|
|
.and_call_original
|
|
|
|
|
|
|
|
resolve_project_milestones(containing_date: t)
|
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|