2016-10-13 15:11:28 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::CycleAnalytics::Events do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:from_date) { 10.days.ago }
|
|
|
|
let(:user) { create(:user, :admin) }
|
|
|
|
|
|
|
|
subject { described_class.new(project: project, from: from_date) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
setup(context)
|
|
|
|
end
|
|
|
|
|
2016-10-19 10:47:09 +00:00
|
|
|
describe '#issue_events' do
|
2016-10-17 16:03:17 +00:00
|
|
|
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
|
2016-10-13 15:11:28 +00:00
|
|
|
|
2016-10-19 10:47:09 +00:00
|
|
|
it 'has the total time' do
|
|
|
|
expect(subject.issue_events.first['total_time']).to eq('2 days')
|
2016-10-17 12:57:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has a title' do
|
2016-10-18 08:06:42 +00:00
|
|
|
expect(subject.issue_events.first['title']).to eq(context.title)
|
2016-10-17 12:57:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has an iid' do
|
2016-10-18 08:06:42 +00:00
|
|
|
expect(subject.issue_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-10-18 08:06:42 +00:00
|
|
|
expect(subject.issue_events.first['created_at']).to end_with('ago')
|
2016-10-17 12:57:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "has the author's name" do
|
2016-10-18 08:06:42 +00:00
|
|
|
expect(subject.issue_events.first['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
|
|
|
|
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
|
|
|
|
|
2016-10-19 13:40:14 +00:00
|
|
|
it 'has the first referenced commit' do
|
|
|
|
expect(subject.plan_events.first['commit'].message).to eq('commit message')
|
2016-10-19 10:47:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the total time' do
|
2016-10-20 08:08:53 +00:00
|
|
|
expect(subject.plan_events.first['total_time']).to eq('less than a minute')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#code_events' do
|
|
|
|
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create_commit_referencing_issue(context)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the total time' do
|
2016-10-20 14:20:04 +00:00
|
|
|
expect(subject.code_events.first['total_time']).to eq('less than a minute')
|
2016-10-20 08:08:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has a title' do
|
|
|
|
expect(subject.code_events.first['title']).to eq('Awesome merge_request')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has an iid' do
|
|
|
|
expect(subject.code_events.first['iid']).to eq(context.iid.to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has a created_at timestamp' do
|
|
|
|
expect(subject.code_events.first['created_at']).to end_with('ago')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has the author's name" do
|
|
|
|
expect(subject.code_events.first['name']).to eq(context.author.name)
|
2016-10-19 10:47:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-20 14:20:04 +00:00
|
|
|
describe '#test_events' do
|
|
|
|
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
|
|
|
|
let(:merge_request) { MergeRequest.first }
|
|
|
|
let!(:pipeline) { create(:ci_pipeline,
|
|
|
|
ref: merge_request.source_branch,
|
|
|
|
sha: merge_request.diff_head_sha,
|
|
|
|
project: context.project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
pipeline.run!
|
|
|
|
pipeline.succeed!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the build info as a pipeline' do
|
|
|
|
expect(subject.test_events.first['pipeline']).to eq(pipeline)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the total time' do
|
|
|
|
expect(subject.test_events.first['total_time']).to eq('less than a minute')
|
|
|
|
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)
|
2016-10-13 15:11:28 +00:00
|
|
|
create_merge_request_closing_issue(context)
|
|
|
|
end
|
|
|
|
end
|