2016-10-24 10:24:56 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe 'cycle analytics events' do
|
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
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2016-10-24 10:24:56 -04:00
|
|
|
|
2017-01-25 05:55:11 -05:00
|
|
|
3.times do |count|
|
|
|
|
Timecop.freeze(Time.now + count.days) do
|
|
|
|
create_cycle
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-21 07:13:56 -05:00
|
|
|
deploy_master(user, project)
|
2016-10-24 10:49:25 -04:00
|
|
|
|
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
|
2017-06-29 13:06:35 -04:00
|
|
|
get project_cycle_analytics_issue_path(project, format: :json)
|
2016-10-24 10:49:25 -04:00
|
|
|
|
2018-04-04 05:19:47 -04:00
|
|
|
first_issue_iid = project.issues.sort_by_attribute(: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
|
2017-06-29 13:06:35 -04:00
|
|
|
get project_cycle_analytics_plan_path(project, format: :json)
|
2016-10-24 10:49:25 -04:00
|
|
|
|
2018-04-04 05:19:47 -04:00
|
|
|
first_mr_short_sha = project.merge_requests.sort_by_attribute(: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
|
2017-06-29 13:06:35 -04:00
|
|
|
get project_cycle_analytics_code_path(project, format: :json)
|
2016-10-24 10:49:25 -04:00
|
|
|
|
2016-11-09 05:44:29 -05:00
|
|
|
expect(json_response['events']).not_to be_empty
|
2016-11-02 11:21:49 -04:00
|
|
|
|
2018-04-04 05:19:47 -04:00
|
|
|
first_mr_iid = project.merge_requests.sort_by_attribute(: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
|
2017-06-29 13:06:35 -04:00
|
|
|
get project_cycle_analytics_test_path(project, format: :json)
|
2016-10-24 10:49:25 -04:00
|
|
|
|
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
|
2017-06-29 13:06:35 -04:00
|
|
|
get project_cycle_analytics_review_path(project, format: :json)
|
2016-10-24 10:49:25 -04:00
|
|
|
|
2018-04-04 05:19:47 -04:00
|
|
|
first_mr_iid = project.merge_requests.sort_by_attribute(: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
|
2017-06-29 13:06:35 -04:00
|
|
|
get project_cycle_analytics_staging_path(project, format: :json)
|
2016-10-24 10:49:25 -04:00
|
|
|
|
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
|
2017-06-29 13:06:35 -04:00
|
|
|
get project_cycle_analytics_production_path(project, format: :json)
|
2016-10-24 10:24:56 -04:00
|
|
|
|
2018-04-04 05:19:47 -04:00
|
|
|
first_issue_iid = project.issues.sort_by_attribute(: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
|
|
|
|
2017-06-29 13:06:35 -04:00
|
|
|
get project_cycle_analytics_test_path(project, format: :json, branch: branch)
|
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
|
|
|
|
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-08-15 06:27:37 -04:00
|
|
|
project.members.last.update(access_level: Gitlab::Access::GUEST)
|
2016-11-15 10:25:37 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not list the test events' do
|
2017-06-29 13:06:35 -04:00
|
|
|
get project_cycle_analytics_test_path(project, format: :json)
|
2016-11-15 10:25:37 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2016-11-15 10:25:37 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not list the staging events' do
|
2017-06-29 13:06:35 -04:00
|
|
|
get project_cycle_analytics_staging_path(project, format: :json)
|
2016-11-15 10:25:37 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2016-11-15 10:25:37 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'lists the issue events' do
|
2017-06-29 13:06:35 -04:00
|
|
|
get project_cycle_analytics_issue_path(project, format: :json)
|
2016-11-15 10:25:37 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-11-15 10:25:37 -05:00
|
|
|
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)
|
2018-02-21 07:13:56 -05:00
|
|
|
mr = create_merge_request_closing_issue(user, project, issue, commit_message: "References #{issue.to_reference}")
|
2016-11-03 06:28:14 -04:00
|
|
|
|
2017-05-19 16:51:07 -04:00
|
|
|
pipeline = create(:ci_empty_pipeline, status: 'created', project: project, ref: mr.source_branch, sha: mr.source_branch_sha, head_pipeline_of: mr)
|
2016-11-03 06:28:14 -04:00
|
|
|
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)
|
|
|
|
|
2018-02-21 07:13:56 -05:00
|
|
|
merge_merge_requests_closing_issue(user, project, 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
|