2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
describe CycleAnalytics::ProjectLevel do
|
2020-03-09 13:42:32 +05:30
|
|
|
let_it_be(:project) { create(:project, :repository) }
|
|
|
|
let_it_be(:from_date) { 10.days.ago }
|
|
|
|
let_it_be(:user) { create(:user, :admin) }
|
|
|
|
let_it_be(:issue) { create(:issue, project: project, created_at: 2.days.ago) }
|
|
|
|
let_it_be(:milestone) { create(:milestone, project: project) }
|
2018-03-27 19:54:05 +05:30
|
|
|
let(:mr) { create_merge_request_closing_issue(user, project, issue, commit_message: "References #{issue.to_reference}") }
|
|
|
|
let(:pipeline) { create(:ci_empty_pipeline, status: 'created', project: project, ref: mr.source_branch, sha: mr.source_branch_sha, head_pipeline_of: mr) }
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
subject { described_class.new(project, options: { from: from_date }) }
|
2018-03-27 19:54:05 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
describe '#all_medians_by_stage' do
|
2018-03-27 19:54:05 +05:30
|
|
|
before do
|
2020-01-01 13:55:28 +05:30
|
|
|
allow_next_instance_of(Gitlab::ReferenceExtractor) do |instance|
|
|
|
|
allow(instance).to receive(:issues).and_return([issue])
|
|
|
|
end
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
create_cycle(user, project, issue, mr, milestone, pipeline)
|
|
|
|
deploy_master(user, project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns every median for each stage for a specific project' do
|
|
|
|
values = described_class::STAGES.each_with_object({}) do |stage_name, hsh|
|
2019-10-12 21:52:04 +05:30
|
|
|
hsh[stage_name] = subject[stage_name].project_median.presence
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
expect(subject.all_medians_by_stage).to eq(values)
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|