2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe MilestonesFinder do
|
2020-03-09 13:42:32 +05:30
|
|
|
let(:now) { Time.now }
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:project_1) { create(:project, namespace: group) }
|
|
|
|
let(:project_2) { create(:project, namespace: group) }
|
2020-03-09 13:42:32 +05:30
|
|
|
let!(:milestone_1) { create(:milestone, group: group, title: 'one test', start_date: now - 1.day, due_date: now) }
|
|
|
|
let!(:milestone_2) { create(:milestone, group: group, start_date: now + 1.day, due_date: now + 2.days) }
|
|
|
|
let!(:milestone_3) { create(:milestone, project: project_1, state: 'active', start_date: now + 2.days, due_date: now + 3.days) }
|
|
|
|
let!(:milestone_4) { create(:milestone, project: project_2, state: 'active', start_date: now + 4.days, due_date: now + 5.days) }
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
it 'returns milestones for projects' do
|
2017-09-10 17:25:29 +05:30
|
|
|
result = described_class.new(project_ids: [project_1.id, project_2.id], state: 'all').execute
|
|
|
|
|
|
|
|
expect(result).to contain_exactly(milestone_3, milestone_4)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns milestones for groups' do
|
|
|
|
result = described_class.new(group_ids: group.id, state: 'all').execute
|
|
|
|
|
|
|
|
expect(result).to contain_exactly(milestone_1, milestone_2)
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'milestones for groups and project' do
|
|
|
|
let(:result) do
|
|
|
|
described_class.new(project_ids: [project_1.id, project_2.id], group_ids: group.id, state: 'all').execute
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns milestones for groups and projects' do
|
|
|
|
expect(result).to contain_exactly(milestone_1, milestone_2, milestone_3, milestone_4)
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'orders milestones by due date' do
|
2020-03-09 13:42:32 +05:30
|
|
|
milestone = create(:milestone, group: group, due_date: now - 2.days)
|
|
|
|
|
|
|
|
expect(result.first).to eq(milestone)
|
|
|
|
expect(result.second).to eq(milestone_1)
|
|
|
|
expect(result.third).to eq(milestone_2)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'with filters' do
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
project_ids: [project_1.id, project_2.id],
|
|
|
|
group_ids: group.id,
|
|
|
|
state: 'all'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
milestone_1.close
|
|
|
|
milestone_3.close
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters by active state' do
|
|
|
|
params[:state] = 'active'
|
|
|
|
result = described_class.new(params).execute
|
|
|
|
|
|
|
|
expect(result).to contain_exactly(milestone_2, milestone_4)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters by closed state' do
|
|
|
|
params[:state] = 'closed'
|
|
|
|
result = described_class.new(params).execute
|
|
|
|
|
|
|
|
expect(result).to contain_exactly(milestone_1, milestone_3)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters by title' do
|
|
|
|
result = described_class.new(params.merge(title: 'one test')).execute
|
|
|
|
|
|
|
|
expect(result.to_a).to contain_exactly(milestone_1)
|
|
|
|
end
|
2019-03-02 22:35:43 +05:30
|
|
|
|
|
|
|
it 'filters by search_title' do
|
|
|
|
result = described_class.new(params.merge(search_title: 'one t')).execute
|
|
|
|
|
|
|
|
expect(result.to_a).to contain_exactly(milestone_1)
|
|
|
|
end
|
2020-03-09 13:42:32 +05:30
|
|
|
|
|
|
|
context 'by timeframe' do
|
|
|
|
it 'returns milestones with start_date and due_date between timeframe' do
|
|
|
|
params.merge!(start_date: now - 1.day, end_date: now + 3.days)
|
|
|
|
|
|
|
|
milestones = described_class.new(params).execute
|
|
|
|
|
|
|
|
expect(milestones).to match_array([milestone_1, milestone_2, milestone_3])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns milestones which starts before the timeframe' do
|
|
|
|
milestone = create(:milestone, project: project_2, start_date: now - 5.days)
|
|
|
|
params.merge!(start_date: now - 3.days, end_date: now - 2.days)
|
|
|
|
|
|
|
|
milestones = described_class.new(params).execute
|
|
|
|
|
|
|
|
expect(milestones).to match_array([milestone])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns milestones which ends after the timeframe' do
|
|
|
|
milestone = create(:milestone, project: project_2, due_date: now + 6.days)
|
|
|
|
params.merge!(start_date: now + 6.days, end_date: now + 7.days)
|
|
|
|
|
|
|
|
milestones = described_class.new(params).execute
|
|
|
|
|
|
|
|
expect(milestones).to match_array([milestone])
|
|
|
|
end
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
describe '#find_by' do
|
|
|
|
it 'finds a single milestone' do
|
|
|
|
finder = described_class.new(project_ids: [project_1.id], state: 'all')
|
|
|
|
|
|
|
|
expect(finder.find_by(iid: milestone_3.iid)).to eq(milestone_3)
|
|
|
|
end
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|