2016-10-24 10:24:56 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'cycle analytics events' do
|
2017-01-16 14:39:38 -05:00
|
|
|
include ApiHelpers
|
|
|
|
|
2016-10-24 10:24:56 -04:00
|
|
|
let(:user) { create(:user) }
|
2017-01-26 18:51:57 -05:00
|
|
|
let(:project) { create(:project, :repository, public_builds: false) }
|
2016-11-16 09:55:20 -05:00
|
|
|
let(:issue) { create(:issue, project: project, created_at: 2.days.ago) }
|
2016-10-24 10:24:56 -04:00
|
|
|
|
|
|
|
describe 'GET /:namespace/:project/cycle_analytics/events/issues' do
|
|
|
|
before do
|
|
|
|
project.team << [user, :developer]
|
|
|
|
|
2016-11-16 09:55:20 -05:00
|
|
|
allow_any_instance_of(Gitlab::ReferenceExtractor).to receive(:issues).and_return([issue])
|
|
|
|
|
2017-01-25 05:55:11 -05:00
|
|
|
3.times do |count|
|
|
|
|
Timecop.freeze(Time.now + count.days) do
|
|
|
|
create_cycle
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-24 10:49:25 -04:00
|
|
|
deploy_master
|
|
|
|
|
2016-10-24 10:24:56 -04:00
|
|
|
login_as(user)
|
|
|
|
end
|
|
|
|
|
2016-11-04 12:14:35 -04:00
|
|
|
it 'lists the issue events' do
|
2016-10-24 10:49:25 -04:00
|
|
|
get namespace_project_cycle_analytics_issue_path(project.namespace, project, format: :json)
|
|
|
|
|
2017-01-16 14:39:38 -05:00
|
|
|
first_issue_iid = project.issues.sort(:created_desc).pluck(:iid).first.to_s
|
2016-11-02 11:21:49 -04:00
|
|
|
|
2017-01-16 14:39:38 -05:00
|
|
|
expect(json_response['events']).not_to be_empty
|
2016-11-09 05:44:29 -05:00
|
|
|
expect(json_response['events'].first['iid']).to eq(first_issue_iid)
|
2016-10-24 10:49:25 -04:00
|
|
|
end
|
|
|
|
|
2016-11-04 12:14:35 -04:00
|
|
|
it 'lists the plan events' do
|
2016-10-24 10:49:25 -04:00
|
|
|
get namespace_project_cycle_analytics_plan_path(project.namespace, project, format: :json)
|
|
|
|
|
2017-01-16 14:39:38 -05:00
|
|
|
first_mr_short_sha = project.merge_requests.sort(:created_asc).first.commits.first.short_id
|
2016-11-02 11:21:49 -04:00
|
|
|
|
2017-01-16 14:39:38 -05:00
|
|
|
expect(json_response['events']).not_to be_empty
|
|
|
|
expect(json_response['events'].first['short_sha']).to eq(first_mr_short_sha)
|
2016-10-24 10:49:25 -04:00
|
|
|
end
|
|
|
|
|
2016-11-04 12:14:35 -04:00
|
|
|
it 'lists the code events' do
|
2016-10-24 10:49:25 -04:00
|
|
|
get namespace_project_cycle_analytics_code_path(project.namespace, project, format: :json)
|
|
|
|
|
2016-11-09 05:44:29 -05:00
|
|
|
expect(json_response['events']).not_to be_empty
|
2016-11-02 11:21:49 -04:00
|
|
|
|
2017-01-16 14:39:38 -05:00
|
|
|
first_mr_iid = project.merge_requests.sort(:created_desc).pluck(:iid).first.to_s
|
2016-11-02 11:21:49 -04:00
|
|
|
|
2016-11-09 05:44:29 -05:00
|
|
|
expect(json_response['events'].first['iid']).to eq(first_mr_iid)
|
2016-10-24 10:49:25 -04:00
|
|
|
end
|
|
|
|
|
2016-11-04 12:14:35 -04:00
|
|
|
it 'lists the test events' do
|
2016-10-24 10:49:25 -04:00
|
|
|
get namespace_project_cycle_analytics_test_path(project.namespace, project, format: :json)
|
|
|
|
|
2016-11-09 05:44:29 -05:00
|
|
|
expect(json_response['events']).not_to be_empty
|
|
|
|
expect(json_response['events'].first['date']).not_to be_empty
|
2016-10-24 10:49:25 -04:00
|
|
|
end
|
|
|
|
|
2016-11-04 12:14:35 -04:00
|
|
|
it 'lists the review events' do
|
2016-10-24 10:49:25 -04:00
|
|
|
get namespace_project_cycle_analytics_review_path(project.namespace, project, format: :json)
|
|
|
|
|
2017-01-16 14:39:38 -05:00
|
|
|
first_mr_iid = project.merge_requests.sort(:created_desc).pluck(:iid).first.to_s
|
2016-11-02 11:21:49 -04:00
|
|
|
|
2017-01-16 14:39:38 -05:00
|
|
|
expect(json_response['events']).not_to be_empty
|
2016-11-09 05:44:29 -05:00
|
|
|
expect(json_response['events'].first['iid']).to eq(first_mr_iid)
|
2016-10-24 10:49:25 -04:00
|
|
|
end
|
|
|
|
|
2016-11-04 12:14:35 -04:00
|
|
|
it 'lists the staging events' do
|
2016-10-24 10:49:25 -04:00
|
|
|
get namespace_project_cycle_analytics_staging_path(project.namespace, project, format: :json)
|
|
|
|
|
2016-11-09 05:44:29 -05:00
|
|
|
expect(json_response['events']).not_to be_empty
|
|
|
|
expect(json_response['events'].first['date']).not_to be_empty
|
2016-10-24 10:49:25 -04:00
|
|
|
end
|
|
|
|
|
2016-11-04 12:14:35 -04:00
|
|
|
it 'lists the production events' do
|
2016-10-24 10:49:25 -04:00
|
|
|
get namespace_project_cycle_analytics_production_path(project.namespace, project, format: :json)
|
2016-10-24 10:24:56 -04:00
|
|
|
|
2017-01-16 14:39:38 -05:00
|
|
|
first_issue_iid = project.issues.sort(:created_desc).pluck(:iid).first.to_s
|
2016-11-02 11:21:49 -04:00
|
|
|
|
2017-01-16 14:39:38 -05:00
|
|
|
expect(json_response['events']).not_to be_empty
|
2016-11-09 05:44:29 -05:00
|
|
|
expect(json_response['events'].first['iid']).to eq(first_issue_iid)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'specific branch' do
|
|
|
|
it 'lists the test events' do
|
2017-01-16 14:39:38 -05:00
|
|
|
branch = project.merge_requests.first.source_branch
|
2016-11-09 05:44:29 -05:00
|
|
|
|
|
|
|
get namespace_project_cycle_analytics_test_path(project.namespace, project, format: :json, branch: branch)
|
|
|
|
|
|
|
|
expect(json_response['events']).not_to be_empty
|
|
|
|
expect(json_response['events'].first['date']).not_to be_empty
|
|
|
|
end
|
2016-10-24 10:24:56 -04:00
|
|
|
end
|
2016-11-15 10:25:37 -05:00
|
|
|
|
|
|
|
context 'with private project and builds' do
|
|
|
|
before do
|
2017-01-16 14:39:38 -05:00
|
|
|
project.members.first.update(access_level: Gitlab::Access::GUEST)
|
2016-11-15 10:25:37 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not list the test events' do
|
|
|
|
get namespace_project_cycle_analytics_test_path(project.namespace, project, format: :json)
|
|
|
|
|
|
|
|
expect(response).to have_http_status(:not_found)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not list the staging events' do
|
|
|
|
get namespace_project_cycle_analytics_staging_path(project.namespace, project, format: :json)
|
|
|
|
|
|
|
|
expect(response).to have_http_status(:not_found)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'lists the issue events' do
|
|
|
|
get namespace_project_cycle_analytics_issue_path(project.namespace, project, format: :json)
|
|
|
|
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
end
|
|
|
|
end
|
2016-10-24 10:24:56 -04:00
|
|
|
end
|
|
|
|
|
2016-11-02 11:21:49 -04:00
|
|
|
def create_cycle
|
|
|
|
milestone = create(:milestone, project: project)
|
|
|
|
issue.update(milestone: milestone)
|
2016-11-03 06:28:14 -04:00
|
|
|
mr = create_merge_request_closing_issue(issue)
|
|
|
|
|
|
|
|
pipeline = create(:ci_empty_pipeline, status: 'created', project: project, ref: mr.source_branch, sha: mr.source_branch_sha)
|
|
|
|
pipeline.run
|
2016-11-02 11:21:49 -04:00
|
|
|
|
2016-11-04 12:14:35 -04:00
|
|
|
create(:ci_build, pipeline: pipeline, status: :success, author: user)
|
|
|
|
create(:ci_build, pipeline: pipeline, status: :success, author: user)
|
|
|
|
|
2016-11-02 11:21:49 -04:00
|
|
|
merge_merge_requests_closing_issue(issue)
|
2016-11-16 03:58:23 -05:00
|
|
|
|
2016-11-24 09:07:44 -05:00
|
|
|
ProcessCommitWorker.new.perform(project.id, user.id, mr.commits.last.to_hash)
|
2016-11-02 11:21:49 -04:00
|
|
|
end
|
2016-10-24 10:24:56 -04:00
|
|
|
end
|