debian-mirror-gitlab/spec/graphql/resolvers/project_milestones_resolver_spec.rb

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

187 lines
6 KiB
Ruby
Raw Normal View History

2020-10-24 23:57:45 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Resolvers::ProjectMilestonesResolver do
include GraphqlHelpers
describe '#resolve' do
let_it_be(:project) { create(:project, :private) }
let_it_be(:current_user) { create(:user) }
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)
2021-01-03 14:25:43 +05:30
.with(args(project_ids: project.id, state: 'all'))
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)
2021-01-03 14:25:43 +05:30
.with(args(project_ids: project.id, group_ids: contain_exactly(group, parent_group), state: 'all'))
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)
2021-01-03 14:25:43 +05:30
.with(args(ids: [milestone.id.to_s], project_ids: project.id, state: 'all'))
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)
2021-01-03 14:25:43 +05:30
.with(args(project_ids: project.id, state: 'closed'))
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)
.with(args(project_ids: project.id, state: 'all', sort: :due_date_desc))
.and_call_original
resolve_project_milestones(sort: :due_date_desc)
end
%i[expired_last_due_date_asc expired_last_due_date_desc].each do |sort_by|
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
start_date = Time.now
end_date = Time.now + 5.days
expect(MilestonesFinder).to receive(:new)
2021-01-03 14:25:43 +05:30
.with(args(project_ids: project.id, state: 'all', start_date: start_date, end_date: end_date))
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
2020-10-24 23:57:45 +05:30
resolve_project_milestones(start_date: Time.now, end_date: Time.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
2020-10-24 23:57:45 +05:30
resolve_project_milestones(start_date: Time.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
2020-10-24 23:57:45 +05:30
resolve_project_milestones(end_date: Time.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
start_date = Time.now
end_date = Time.now + 5.days
expect(MilestonesFinder).to receive(:new)
.with(args(project_ids: project.id, state: 'all', start_date: start_date, end_date: end_date))
.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)
.with(args(title: '13.5', state: 'all', project_ids: project.id))
.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)
.with(args(search_title: '13', state: 'all', project_ids: project.id))
.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
t = Time.now
expect(MilestonesFinder).to receive(:new)
.with(args(containing_date: t, state: 'all', project_ids: project.id))
.and_call_original
resolve_project_milestones(containing_date: t)
end
2020-10-24 23:57:45 +05:30
end
context 'when user cannot read milestones' do
2022-05-07 20:08:51 +05:30
it 'generates an error' do
2020-10-24 23:57:45 +05:30
unauthorized_user = create(:user)
2022-05-07 20:08:51 +05:30
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ResourceNotAvailable) do
2020-10-24 23:57:45 +05:30
resolve_project_milestones({}, { current_user: unauthorized_user })
2022-05-07 20:08:51 +05:30
end
2020-10-24 23:57:45 +05:30
end
end
end
end