2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-07 04:41:24 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-06-29 00:13:10 -04:00
|
|
|
describe 'CycleAnalytics#test' do
|
2016-09-20 15:17:37 -04:00
|
|
|
extend CycleAnalyticsHelpers::TestGeneration
|
|
|
|
|
2020-01-08 16:08:08 -05:00
|
|
|
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) }
|
|
|
|
let_it_be(:project_level) { CycleAnalytics::ProjectLevel.new(project, options: { from: from_date }) }
|
|
|
|
let!(:merge_request) { create_merge_request_closing_issue(user, project, issue) }
|
2019-07-10 07:42:54 -04:00
|
|
|
|
2020-01-08 16:08:08 -05:00
|
|
|
subject { project_level }
|
2016-09-07 04:41:24 -04:00
|
|
|
|
2016-09-20 15:17:37 -04:00
|
|
|
generate_cycle_analytics_spec(
|
|
|
|
phase: :test,
|
|
|
|
data_fn: lambda do |context|
|
2020-01-08 16:08:08 -05:00
|
|
|
issue = context.issue
|
2018-02-21 07:13:56 -05:00
|
|
|
merge_request = context.create_merge_request_closing_issue(context.user, context.project, issue)
|
2017-05-19 16:51:07 -04:00
|
|
|
pipeline = context.create(:ci_pipeline, ref: merge_request.source_branch, sha: merge_request.diff_head_sha, project: context.project, head_pipeline_of: merge_request)
|
2016-09-20 15:17:37 -04:00
|
|
|
{ pipeline: pipeline, issue: issue }
|
|
|
|
end,
|
|
|
|
start_time_conditions: [["pipeline is started", -> (context, data) { data[:pipeline].run! }]],
|
|
|
|
end_time_conditions: [["pipeline is finished", -> (context, data) { data[:pipeline].succeed! }]],
|
|
|
|
post_fn: -> (context, data) do
|
|
|
|
end)
|
2016-09-07 04:41:24 -04:00
|
|
|
|
|
|
|
context "when the pipeline is for a regular merge request (that doesn't close an issue)" do
|
|
|
|
it "returns nil" do
|
2017-01-29 17:53:48 -05:00
|
|
|
pipeline = create(:ci_pipeline, ref: "refs/heads/#{merge_request.source_branch}", sha: merge_request.diff_head_sha)
|
2016-09-07 04:41:24 -04:00
|
|
|
|
2017-01-29 17:53:48 -05:00
|
|
|
pipeline.run!
|
|
|
|
pipeline.succeed!
|
2016-09-20 01:47:36 -04:00
|
|
|
|
2019-07-04 10:42:31 -04:00
|
|
|
expect(subject[:test].project_median).to be_nil
|
2016-09-07 04:41:24 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the pipeline is not for a merge request" do
|
|
|
|
it "returns nil" do
|
2017-01-29 17:53:48 -05:00
|
|
|
pipeline = create(:ci_pipeline, ref: "refs/heads/master", sha: project.repository.commit('master').sha)
|
2016-09-07 04:41:24 -04:00
|
|
|
|
2017-01-29 17:53:48 -05:00
|
|
|
pipeline.run!
|
|
|
|
pipeline.succeed!
|
2016-09-07 04:41:24 -04:00
|
|
|
|
2019-07-04 10:42:31 -04:00
|
|
|
expect(subject[:test].project_median).to be_nil
|
2016-09-07 04:41:24 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the pipeline is dropped (failed)" do
|
|
|
|
it "returns nil" do
|
2017-01-29 17:53:48 -05:00
|
|
|
pipeline = create(:ci_pipeline, ref: "refs/heads/#{merge_request.source_branch}", sha: merge_request.diff_head_sha)
|
2016-09-07 04:41:24 -04:00
|
|
|
|
2017-01-29 17:53:48 -05:00
|
|
|
pipeline.run!
|
|
|
|
pipeline.drop!
|
2016-09-20 01:47:36 -04:00
|
|
|
|
2019-07-04 10:42:31 -04:00
|
|
|
expect(subject[:test].project_median).to be_nil
|
2016-09-07 04:41:24 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the pipeline is cancelled" do
|
|
|
|
it "returns nil" do
|
2017-01-29 17:53:48 -05:00
|
|
|
pipeline = create(:ci_pipeline, ref: "refs/heads/#{merge_request.source_branch}", sha: merge_request.diff_head_sha)
|
2016-09-07 04:41:24 -04:00
|
|
|
|
2017-01-29 17:53:48 -05:00
|
|
|
pipeline.run!
|
|
|
|
pipeline.cancel!
|
2016-09-20 01:47:36 -04:00
|
|
|
|
2019-07-04 10:42:31 -04:00
|
|
|
expect(subject[:test].project_median).to be_nil
|
2016-09-07 04:41:24 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|