2016-10-13 15:11:28 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2016-11-23 10:28:28 +00:00
|
|
|
describe 'cycle analytics events' do
|
2017-08-01 18:51:52 +00:00
|
|
|
let(:project) { create(:project, :repository) }
|
2016-10-13 15:11:28 +00:00
|
|
|
let(:from_date) { 10.days.ago }
|
|
|
|
let(:user) { create(:user, :admin) }
|
2016-11-03 14:41:46 +00:00
|
|
|
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
|
2016-10-13 15:11:28 +00:00
|
|
|
|
2016-11-23 10:28:28 +00:00
|
|
|
let(:events) do
|
2016-12-01 10:21:24 +00:00
|
|
|
CycleAnalytics.new(project, { from: from_date, current_user: user })[stage].events
|
2016-11-23 10:28:28 +00:00
|
|
|
end
|
2016-10-13 15:11:28 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
setup(context)
|
|
|
|
end
|
|
|
|
|
2016-10-19 10:47:09 +00:00
|
|
|
describe '#issue_events' do
|
2016-11-23 10:28:28 +00:00
|
|
|
let(:stage) { :issue }
|
|
|
|
|
2016-10-19 10:47:09 +00:00
|
|
|
it 'has the total time' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:total_time]).not_to be_empty
|
2016-10-17 12:57:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has a title' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:title]).to eq(context.title)
|
2016-10-17 12:57:23 +00:00
|
|
|
end
|
|
|
|
|
2016-11-04 15:16:15 +00:00
|
|
|
it 'has the URL' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:url]).not_to be_nil
|
2016-11-04 15:16:15 +00:00
|
|
|
end
|
|
|
|
|
2016-10-17 12:57:23 +00:00
|
|
|
it 'has an iid' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:iid]).to eq(context.iid.to_s)
|
2016-10-17 12:57:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has a created_at timestamp' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:created_at]).to end_with('ago')
|
2016-10-17 12:57:23 +00:00
|
|
|
end
|
|
|
|
|
2016-11-03 12:06:14 +00:00
|
|
|
it "has the author's URL" do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:author][:web_url]).not_to be_nil
|
2016-11-03 12:06:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "has the author's avatar URL" do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:author][:avatar_url]).not_to be_nil
|
2016-10-27 16:52:42 +00:00
|
|
|
end
|
|
|
|
|
2016-10-17 12:57:23 +00:00
|
|
|
it "has the author's name" do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:author][:name]).to eq(context.author.name)
|
2016-10-13 15:11:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-19 10:47:09 +00:00
|
|
|
describe '#plan_events' do
|
2016-11-23 10:28:28 +00:00
|
|
|
let(:stage) { :plan }
|
|
|
|
|
2016-11-03 14:41:46 +00:00
|
|
|
it 'has a title' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:title]).not_to be_nil
|
2016-11-03 14:41:46 +00:00
|
|
|
end
|
2016-10-19 10:47:09 +00:00
|
|
|
|
2016-11-03 14:41:46 +00:00
|
|
|
it 'has a sha short ID' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:short_sha]).not_to be_nil
|
2016-11-15 12:23:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the URL' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:commit_url]).not_to be_nil
|
2016-10-19 10:47:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the total time' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:total_time]).not_to be_empty
|
2016-10-20 08:08:53 +00:00
|
|
|
end
|
2016-11-03 14:41:46 +00:00
|
|
|
|
|
|
|
it "has the author's URL" do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:author][:web_url]).not_to be_nil
|
2016-11-03 14:41:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "has the author's avatar URL" do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:author][:avatar_url]).not_to be_nil
|
2016-11-03 14:41:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "has the author's name" do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:author][:name]).not_to be_nil
|
2016-11-03 14:41:46 +00:00
|
|
|
end
|
2016-10-20 08:08:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#code_events' do
|
2016-11-23 10:28:28 +00:00
|
|
|
let(:stage) { :code }
|
|
|
|
|
2016-10-20 08:08:53 +00:00
|
|
|
before do
|
|
|
|
create_commit_referencing_issue(context)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the total time' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:total_time]).not_to be_empty
|
2016-10-20 08:08:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has a title' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:title]).to eq('Awesome merge_request')
|
2016-10-20 08:08:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has an iid' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:iid]).to eq(context.iid.to_s)
|
2016-10-20 08:08:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has a created_at timestamp' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:created_at]).to end_with('ago')
|
2016-10-20 08:08:53 +00:00
|
|
|
end
|
|
|
|
|
2016-11-03 15:31:30 +00:00
|
|
|
it "has the author's URL" do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:author][:web_url]).not_to be_nil
|
2016-11-03 15:31:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "has the author's avatar URL" do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:author][:avatar_url]).not_to be_nil
|
2016-10-27 16:52:42 +00:00
|
|
|
end
|
|
|
|
|
2016-10-20 08:08:53 +00:00
|
|
|
it "has the author's name" do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:author][:name]).to eq(MergeRequest.first.author.name)
|
2016-10-19 10:47:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-20 14:20:04 +00:00
|
|
|
describe '#test_events' do
|
2016-11-23 10:28:28 +00:00
|
|
|
let(:stage) { :test }
|
|
|
|
|
2016-10-20 14:20:04 +00:00
|
|
|
let(:merge_request) { MergeRequest.first }
|
2018-01-04 10:28:18 +00:00
|
|
|
|
2016-10-21 07:44:04 +00:00
|
|
|
let!(:pipeline) do
|
|
|
|
create(:ci_pipeline,
|
|
|
|
ref: merge_request.source_branch,
|
|
|
|
sha: merge_request.diff_head_sha,
|
2018-01-04 10:28:18 +00:00
|
|
|
project: project,
|
2017-05-19 20:51:07 +00:00
|
|
|
head_pipeline_of: merge_request)
|
2016-10-21 07:44:04 +00:00
|
|
|
end
|
2016-10-20 14:20:04 +00:00
|
|
|
|
|
|
|
before do
|
2018-01-04 10:28:18 +00:00
|
|
|
create(:ci_build, :success, pipeline: pipeline, author: user)
|
|
|
|
create(:ci_build, :success, pipeline: pipeline, author: user)
|
2016-11-04 10:56:24 +00:00
|
|
|
|
2016-10-20 14:20:04 +00:00
|
|
|
pipeline.run!
|
|
|
|
pipeline.succeed!
|
|
|
|
end
|
|
|
|
|
2016-11-04 10:56:24 +00:00
|
|
|
it 'has the name' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:name]).not_to be_nil
|
2016-11-04 10:56:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the ID' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:id]).not_to be_nil
|
2016-11-04 10:56:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the URL' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:url]).not_to be_nil
|
2016-11-04 10:56:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the branch name' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:branch]).not_to be_nil
|
2016-11-04 10:56:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the branch URL' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:branch][:url]).not_to be_nil
|
2016-11-04 10:56:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the short SHA' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:short_sha]).not_to be_nil
|
2016-11-04 10:56:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the commit URL' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:commit_url]).not_to be_nil
|
2016-11-04 10:56:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the date' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:date]).not_to be_nil
|
2016-10-20 14:20:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the total time' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:total_time]).not_to be_empty
|
2016-10-20 14:20:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-21 06:50:27 +00:00
|
|
|
describe '#review_events' do
|
2016-11-23 10:28:28 +00:00
|
|
|
let(:stage) { :review }
|
2016-10-21 06:50:27 +00:00
|
|
|
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
|
|
|
|
|
|
|
|
it 'has the total time' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:total_time]).not_to be_empty
|
2016-10-21 06:50:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has a title' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:title]).to eq('Awesome merge_request')
|
2016-10-21 06:50:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has an iid' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:iid]).to eq(context.iid.to_s)
|
2016-10-21 06:50:27 +00:00
|
|
|
end
|
|
|
|
|
2016-11-04 14:59:27 +00:00
|
|
|
it 'has the URL' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:url]).not_to be_nil
|
2016-11-04 14:59:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has a state' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:state]).not_to be_nil
|
2016-11-04 14:59:27 +00:00
|
|
|
end
|
|
|
|
|
2016-10-21 06:50:27 +00:00
|
|
|
it 'has a created_at timestamp' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:created_at]).not_to be_nil
|
2016-10-21 06:50:27 +00:00
|
|
|
end
|
|
|
|
|
2016-11-04 14:59:27 +00:00
|
|
|
it "has the author's URL" do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:author][:web_url]).not_to be_nil
|
2016-11-04 14:59:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "has the author's avatar URL" do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:author][:avatar_url]).not_to be_nil
|
2016-10-27 16:52:42 +00:00
|
|
|
end
|
|
|
|
|
2016-10-21 06:50:27 +00:00
|
|
|
it "has the author's name" do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:author][:name]).to eq(MergeRequest.first.author.name)
|
2016-10-21 06:50:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-21 09:33:37 +00:00
|
|
|
describe '#staging_events' do
|
2016-11-23 10:28:28 +00:00
|
|
|
let(:stage) { :staging }
|
2016-10-21 09:33:37 +00:00
|
|
|
let(:merge_request) { MergeRequest.first }
|
2018-01-04 10:28:18 +00:00
|
|
|
|
2016-10-21 09:33:37 +00:00
|
|
|
let!(:pipeline) do
|
|
|
|
create(:ci_pipeline,
|
|
|
|
ref: merge_request.source_branch,
|
|
|
|
sha: merge_request.diff_head_sha,
|
2018-01-04 10:28:18 +00:00
|
|
|
project: project,
|
2017-05-19 20:51:07 +00:00
|
|
|
head_pipeline_of: merge_request)
|
2016-10-21 09:33:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2018-01-04 10:28:18 +00:00
|
|
|
create(:ci_build, :success, pipeline: pipeline, author: user)
|
|
|
|
create(:ci_build, :success, pipeline: pipeline, author: user)
|
2016-11-04 14:59:27 +00:00
|
|
|
|
2016-10-21 09:33:37 +00:00
|
|
|
pipeline.run!
|
|
|
|
pipeline.succeed!
|
2016-11-03 14:41:46 +00:00
|
|
|
|
2018-02-21 12:13:56 +00:00
|
|
|
merge_merge_requests_closing_issue(user, project, context)
|
|
|
|
deploy_master(user, project)
|
2016-10-21 09:33:37 +00:00
|
|
|
end
|
|
|
|
|
2016-11-04 14:59:27 +00:00
|
|
|
it 'has the name' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:name]).not_to be_nil
|
2016-11-04 14:59:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the ID' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:id]).not_to be_nil
|
2016-11-04 14:59:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the URL' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:url]).not_to be_nil
|
2016-11-04 14:59:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the branch name' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:branch]).not_to be_nil
|
2016-11-04 14:59:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the branch URL' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:branch][:url]).not_to be_nil
|
2016-11-04 14:59:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the short SHA' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:short_sha]).not_to be_nil
|
2016-11-04 14:59:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the commit URL' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:commit_url]).not_to be_nil
|
2016-11-04 14:59:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the date' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:date]).not_to be_nil
|
2016-10-21 09:33:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the total time' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:total_time]).not_to be_empty
|
2016-11-04 14:59:27 +00:00
|
|
|
end
|
|
|
|
|
2016-11-15 10:36:39 +00:00
|
|
|
it "has the author's URL" do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:author][:web_url]).not_to be_nil
|
2016-11-15 10:36:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "has the author's avatar URL" do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:author][:avatar_url]).not_to be_nil
|
2016-11-15 10:36:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "has the author's name" do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:author][:name]).to eq(MergeRequest.first.author.name)
|
2016-10-21 09:33:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-21 15:30:38 +00:00
|
|
|
describe '#production_events' do
|
2016-11-23 10:28:28 +00:00
|
|
|
let(:stage) { :production }
|
2016-10-21 15:30:38 +00:00
|
|
|
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
|
|
|
|
|
|
|
|
before do
|
2018-02-21 12:13:56 +00:00
|
|
|
merge_merge_requests_closing_issue(user, project, context)
|
|
|
|
deploy_master(user, project)
|
2016-10-21 15:30:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the total time' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:total_time]).not_to be_empty
|
2016-10-21 15:30:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has a title' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:title]).to eq(context.title)
|
2016-10-21 15:30:38 +00:00
|
|
|
end
|
|
|
|
|
2016-11-04 15:16:15 +00:00
|
|
|
it 'has the URL' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:url]).not_to be_nil
|
2016-11-04 15:16:15 +00:00
|
|
|
end
|
|
|
|
|
2016-10-21 15:30:38 +00:00
|
|
|
it 'has an iid' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:iid]).to eq(context.iid.to_s)
|
2016-10-21 15:30:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has a created_at timestamp' do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:created_at]).to end_with('ago')
|
2016-10-21 15:30:38 +00:00
|
|
|
end
|
|
|
|
|
2016-11-04 15:16:15 +00:00
|
|
|
it "has the author's URL" do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:author][:web_url]).not_to be_nil
|
2016-11-04 15:16:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "has the author's avatar URL" do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:author][:avatar_url]).not_to be_nil
|
2016-10-27 16:52:42 +00:00
|
|
|
end
|
|
|
|
|
2016-10-21 15:30:38 +00:00
|
|
|
it "has the author's name" do
|
2016-11-23 10:28:28 +00:00
|
|
|
expect(events.first[:author][:name]).to eq(context.author.name)
|
2016-10-21 15:30:38 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-13 15:11:28 +00:00
|
|
|
def setup(context)
|
2016-10-14 15:33:21 +00:00
|
|
|
milestone = create(:milestone, project: project)
|
|
|
|
context.update(milestone: milestone)
|
2018-02-21 12:13:56 +00:00
|
|
|
mr = create_merge_request_closing_issue(user, project, context, commit_message: "References #{context.to_reference}")
|
2016-11-16 11:01:10 +00:00
|
|
|
|
2016-11-24 14:07:44 +00:00
|
|
|
ProcessCommitWorker.new.perform(project.id, user.id, mr.commits.last.to_hash)
|
2016-10-13 15:11:28 +00:00
|
|
|
end
|
|
|
|
end
|