2019-07-25 01:21:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-13 11:11:28 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-09-28 08:10:02 -04:00
|
|
|
RSpec.describe 'cycle analytics events', :aggregate_failures do
|
|
|
|
let_it_be(:project) { create(:project, :repository) }
|
|
|
|
let_it_be(:user) { create(:user, :admin) }
|
2016-10-13 11:11:28 -04:00
|
|
|
let(:from_date) { 10.days.ago }
|
2016-11-03 10:41:46 -04:00
|
|
|
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
|
2016-10-13 11:11:28 -04:00
|
|
|
|
2016-11-23 05:28:28 -05:00
|
|
|
let(:events) do
|
2020-09-28 08:10:02 -04:00
|
|
|
CycleAnalytics::ProjectLevel
|
|
|
|
.new(project, options: { from: from_date, current_user: user })[stage]
|
|
|
|
.events
|
2016-11-23 05:28:28 -05:00
|
|
|
end
|
2016-10-13 11:11:28 -04:00
|
|
|
|
2020-09-28 08:10:02 -04:00
|
|
|
let(:event) { events.first }
|
|
|
|
|
2016-10-13 11:11:28 -04:00
|
|
|
before do
|
|
|
|
setup(context)
|
|
|
|
end
|
|
|
|
|
2016-10-19 06:47:09 -04:00
|
|
|
describe '#issue_events' do
|
2016-11-23 05:28:28 -05:00
|
|
|
let(:stage) { :issue }
|
|
|
|
|
2020-09-28 08:10:02 -04:00
|
|
|
it 'has correct attributes' do
|
|
|
|
expect(event[:total_time]).not_to be_empty
|
|
|
|
expect(event[:title]).to eq(context.title)
|
|
|
|
expect(event[:url]).not_to be_nil
|
|
|
|
expect(event[:iid]).to eq(context.iid.to_s)
|
|
|
|
expect(event[:created_at]).to end_with('ago')
|
|
|
|
expect(event[:author][:web_url]).not_to be_nil
|
|
|
|
expect(event[:author][:avatar_url]).not_to be_nil
|
|
|
|
expect(event[:author][:name]).to eq(context.author.name)
|
2016-10-13 11:11:28 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-19 06:47:09 -04:00
|
|
|
describe '#plan_events' do
|
2016-11-23 05:28:28 -05:00
|
|
|
let(:stage) { :plan }
|
|
|
|
|
2019-06-17 09:17:18 -04:00
|
|
|
before do
|
|
|
|
create_commit_referencing_issue(context)
|
2016-11-03 10:41:46 -04:00
|
|
|
end
|
2016-10-19 06:47:09 -04:00
|
|
|
|
2020-09-28 08:10:02 -04:00
|
|
|
it 'has correct attributes' do
|
|
|
|
expect(event[:total_time]).not_to be_empty
|
|
|
|
expect(event[:title]).to eq(context.title)
|
|
|
|
expect(event[:url]).not_to be_nil
|
|
|
|
expect(event[:iid]).to eq(context.iid.to_s)
|
|
|
|
expect(event[:created_at]).to end_with('ago')
|
|
|
|
expect(event[:author][:web_url]).not_to be_nil
|
|
|
|
expect(event[:author][:avatar_url]).not_to be_nil
|
|
|
|
expect(event[:author][:name]).to eq(context.author.name)
|
2016-11-03 10:41:46 -04:00
|
|
|
end
|
2016-10-20 04:08:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#code_events' do
|
2016-11-23 05:28:28 -05:00
|
|
|
let(:stage) { :code }
|
2019-06-17 09:17:18 -04:00
|
|
|
let!(:merge_request) { MergeRequest.first }
|
2016-11-23 05:28:28 -05:00
|
|
|
|
2016-10-20 04:08:53 -04:00
|
|
|
before do
|
|
|
|
create_commit_referencing_issue(context)
|
|
|
|
end
|
|
|
|
|
2020-09-28 08:10:02 -04:00
|
|
|
it 'has correct attributes' do
|
|
|
|
expect(event[:total_time]).not_to be_empty
|
|
|
|
expect(event[:title]).to eq('Awesome merge_request')
|
|
|
|
expect(event[:iid]).to eq(context.iid.to_s)
|
|
|
|
expect(event[:created_at]).to end_with('ago')
|
|
|
|
expect(event[:author][:web_url]).not_to be_nil
|
|
|
|
expect(event[:author][:avatar_url]).not_to be_nil
|
|
|
|
expect(event[:author][:name]).to eq(MergeRequest.first.author.name)
|
2016-10-19 06:47:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-23 05:06:03 -04:00
|
|
|
describe '#test_events', :sidekiq_might_not_need_inline do
|
2016-11-23 05:28:28 -05:00
|
|
|
let(:stage) { :test }
|
|
|
|
|
2016-10-20 10:20:04 -04:00
|
|
|
let(:merge_request) { MergeRequest.first }
|
2019-06-17 09:17:18 -04:00
|
|
|
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
|
2018-01-04 05:28:18 -05:00
|
|
|
|
2016-10-21 03:44:04 -04:00
|
|
|
let!(:pipeline) do
|
|
|
|
create(:ci_pipeline,
|
|
|
|
ref: merge_request.source_branch,
|
|
|
|
sha: merge_request.diff_head_sha,
|
2018-01-04 05:28:18 -05:00
|
|
|
project: project,
|
2017-05-19 16:51:07 -04:00
|
|
|
head_pipeline_of: merge_request)
|
2016-10-21 03:44:04 -04:00
|
|
|
end
|
2016-10-20 10:20:04 -04:00
|
|
|
|
|
|
|
before do
|
2018-01-04 05:28:18 -05:00
|
|
|
create(:ci_build, :success, pipeline: pipeline, author: user)
|
|
|
|
create(:ci_build, :success, pipeline: pipeline, author: user)
|
2016-11-04 06:56:24 -04:00
|
|
|
|
2016-10-20 10:20:04 -04:00
|
|
|
pipeline.run!
|
|
|
|
pipeline.succeed!
|
2019-06-17 09:17:18 -04:00
|
|
|
merge_merge_requests_closing_issue(user, project, context)
|
2016-10-20 10:20:04 -04:00
|
|
|
end
|
|
|
|
|
2020-09-28 08:10:02 -04:00
|
|
|
it 'has correct attributes' do
|
|
|
|
expect(event[:name]).not_to be_nil
|
|
|
|
expect(event[:id]).not_to be_nil
|
|
|
|
expect(event[:url]).not_to be_nil
|
|
|
|
expect(event[:branch]).not_to be_nil
|
|
|
|
expect(event[:branch][:url]).not_to be_nil
|
|
|
|
expect(event[:short_sha]).not_to be_nil
|
|
|
|
expect(event[:commit_url]).not_to be_nil
|
|
|
|
expect(event[:date]).not_to be_nil
|
|
|
|
expect(event[:total_time]).not_to be_empty
|
2016-10-20 10:20:04 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-21 02:50:27 -04:00
|
|
|
describe '#review_events' do
|
2016-11-23 05:28:28 -05:00
|
|
|
let(:stage) { :review }
|
2016-10-21 02:50:27 -04:00
|
|
|
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
|
|
|
|
|
2019-06-17 09:17:18 -04:00
|
|
|
before do
|
|
|
|
merge_merge_requests_closing_issue(user, project, context)
|
|
|
|
end
|
|
|
|
|
2020-09-28 08:10:02 -04:00
|
|
|
it 'has correct attributes' do
|
|
|
|
expect(event[:total_time]).not_to be_empty
|
|
|
|
expect(event[:title]).to eq('Awesome merge_request')
|
|
|
|
expect(event[:iid]).to eq(context.iid.to_s)
|
|
|
|
expect(event[:url]).not_to be_nil
|
|
|
|
expect(event[:state]).not_to be_nil
|
|
|
|
expect(event[:created_at]).not_to be_nil
|
|
|
|
expect(event[:author][:web_url]).not_to be_nil
|
|
|
|
expect(event[:author][:avatar_url]).not_to be_nil
|
|
|
|
expect(event[:author][:name]).to eq(MergeRequest.first.author.name)
|
2016-10-21 02:50:27 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-23 05:06:03 -04:00
|
|
|
describe '#staging_events', :sidekiq_might_not_need_inline do
|
2016-11-23 05:28:28 -05:00
|
|
|
let(:stage) { :staging }
|
2016-10-21 05:33:37 -04:00
|
|
|
let(:merge_request) { MergeRequest.first }
|
2018-01-04 05:28:18 -05:00
|
|
|
|
2016-10-21 05:33:37 -04:00
|
|
|
let!(:pipeline) do
|
|
|
|
create(:ci_pipeline,
|
|
|
|
ref: merge_request.source_branch,
|
|
|
|
sha: merge_request.diff_head_sha,
|
2018-01-04 05:28:18 -05:00
|
|
|
project: project,
|
2017-05-19 16:51:07 -04:00
|
|
|
head_pipeline_of: merge_request)
|
2016-10-21 05:33:37 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2018-01-04 05:28:18 -05:00
|
|
|
create(:ci_build, :success, pipeline: pipeline, author: user)
|
|
|
|
create(:ci_build, :success, pipeline: pipeline, author: user)
|
2016-11-04 10:59:27 -04:00
|
|
|
|
2016-10-21 05:33:37 -04:00
|
|
|
pipeline.run!
|
|
|
|
pipeline.succeed!
|
2016-11-03 10:41:46 -04:00
|
|
|
|
2018-02-21 07:13:56 -05:00
|
|
|
merge_merge_requests_closing_issue(user, project, context)
|
|
|
|
deploy_master(user, project)
|
2016-10-21 05:33:37 -04:00
|
|
|
end
|
|
|
|
|
2020-09-28 08:10:02 -04:00
|
|
|
it 'has correct attributes' do
|
|
|
|
expect(event[:name]).not_to be_nil
|
|
|
|
expect(event[:id]).not_to be_nil
|
|
|
|
expect(event[:url]).not_to be_nil
|
|
|
|
expect(event[:branch]).not_to be_nil
|
|
|
|
expect(event[:branch][:url]).not_to be_nil
|
|
|
|
expect(event[:short_sha]).not_to be_nil
|
|
|
|
expect(event[:commit_url]).not_to be_nil
|
|
|
|
expect(event[:date]).not_to be_nil
|
|
|
|
expect(event[:total_time]).not_to be_empty
|
|
|
|
expect(event[:author][:web_url]).not_to be_nil
|
|
|
|
expect(event[:author][:avatar_url]).not_to be_nil
|
|
|
|
expect(event[:author][:name]).to eq(MergeRequest.first.author.name)
|
2016-10-21 05:33:37 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-13 11:11:28 -04:00
|
|
|
def setup(context)
|
2016-10-14 11:33:21 -04:00
|
|
|
milestone = create(:milestone, project: project)
|
2020-09-28 08:10:02 -04:00
|
|
|
context.update!(milestone: milestone)
|
2018-02-21 07:13:56 -05:00
|
|
|
mr = create_merge_request_closing_issue(user, project, context, commit_message: "References #{context.to_reference}")
|
2016-11-16 06:01:10 -05:00
|
|
|
|
2016-11-24 09:07:44 -05:00
|
|
|
ProcessCommitWorker.new.perform(project.id, user.id, mr.commits.last.to_hash)
|
2016-10-13 11:11:28 -04:00
|
|
|
end
|
|
|
|
end
|