2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe 'cycle analytics events' do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project, :repository, public_builds: false) }
|
|
|
|
let(:issue) { create(:issue, project: project, created_at: 2.days.ago) }
|
|
|
|
|
|
|
|
describe 'GET /:namespace/:project/cycle_analytics/events/issues' do
|
|
|
|
before do
|
2018-03-17 18:26:18 +05:30
|
|
|
project.add_developer(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
3.times do |count|
|
|
|
|
Timecop.freeze(Time.now + count.days) do
|
|
|
|
create_cycle
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
deploy_master(user, project)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
login_as(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'lists the issue events' do
|
2017-09-10 17:25:29 +05:30
|
|
|
get project_cycle_analytics_issue_path(project, format: :json)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
first_issue_iid = project.issues.sort_by_attribute(:created_desc).pluck(:iid).first.to_s
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(json_response['events']).not_to be_empty
|
|
|
|
expect(json_response['events'].first['iid']).to eq(first_issue_iid)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'lists the plan events' do
|
2017-09-10 17:25:29 +05:30
|
|
|
get project_cycle_analytics_plan_path(project, format: :json)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
first_mr_short_sha = project.merge_requests.sort_by_attribute(:created_asc).first.commits.first.short_id
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(json_response['events']).not_to be_empty
|
|
|
|
expect(json_response['events'].first['short_sha']).to eq(first_mr_short_sha)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'lists the code events' do
|
2017-09-10 17:25:29 +05:30
|
|
|
get project_cycle_analytics_code_path(project, format: :json)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(json_response['events']).not_to be_empty
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
first_mr_iid = project.merge_requests.sort_by_attribute(:created_desc).pluck(:iid).first.to_s
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(json_response['events'].first['iid']).to eq(first_mr_iid)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'lists the test events' do
|
2017-09-10 17:25:29 +05:30
|
|
|
get project_cycle_analytics_test_path(project, format: :json)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(json_response['events']).not_to be_empty
|
|
|
|
expect(json_response['events'].first['date']).not_to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'lists the review events' do
|
2017-09-10 17:25:29 +05:30
|
|
|
get project_cycle_analytics_review_path(project, format: :json)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
first_mr_iid = project.merge_requests.sort_by_attribute(:created_desc).pluck(:iid).first.to_s
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(json_response['events']).not_to be_empty
|
|
|
|
expect(json_response['events'].first['iid']).to eq(first_mr_iid)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'lists the staging events' do
|
2017-09-10 17:25:29 +05:30
|
|
|
get project_cycle_analytics_staging_path(project, format: :json)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(json_response['events']).not_to be_empty
|
|
|
|
expect(json_response['events'].first['date']).not_to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'lists the production events' do
|
2017-09-10 17:25:29 +05:30
|
|
|
get project_cycle_analytics_production_path(project, format: :json)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
first_issue_iid = project.issues.sort_by_attribute(:created_desc).pluck(:iid).first.to_s
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(json_response['events']).not_to be_empty
|
|
|
|
expect(json_response['events'].first['iid']).to eq(first_issue_iid)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'specific branch' do
|
|
|
|
it 'lists the test events' do
|
|
|
|
branch = project.merge_requests.first.source_branch
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
get project_cycle_analytics_test_path(project, format: :json, branch: branch)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(json_response['events']).not_to be_empty
|
|
|
|
expect(json_response['events'].first['date']).not_to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with private project and builds' do
|
|
|
|
before do
|
2018-03-17 18:26:18 +05:30
|
|
|
project.members.last.update(access_level: Gitlab::Access::GUEST)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not list the test events' do
|
2017-09-10 17:25:29 +05:30
|
|
|
get project_cycle_analytics_test_path(project, format: :json)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not list the staging events' do
|
2017-09-10 17:25:29 +05:30
|
|
|
get project_cycle_analytics_staging_path(project, format: :json)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'lists the issue events' do
|
2017-09-10 17:25:29 +05:30
|
|
|
get project_cycle_analytics_issue_path(project, format: :json)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_cycle
|
|
|
|
milestone = create(:milestone, project: project)
|
|
|
|
issue.update(milestone: milestone)
|
2018-03-27 19:54:05 +05:30
|
|
|
mr = create_merge_request_closing_issue(user, project, issue, commit_message: "References #{issue.to_reference}")
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
pipeline = create(:ci_empty_pipeline, status: 'created', project: project, ref: mr.source_branch, sha: mr.source_branch_sha, head_pipeline_of: mr)
|
2017-08-17 22:00:37 +05:30
|
|
|
pipeline.run
|
|
|
|
|
|
|
|
create(:ci_build, pipeline: pipeline, status: :success, author: user)
|
|
|
|
create(:ci_build, pipeline: pipeline, status: :success, author: user)
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
merge_merge_requests_closing_issue(user, project, issue)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
ProcessCommitWorker.new.perform(project.id, user.id, mr.commits.last.to_hash)
|
|
|
|
end
|
|
|
|
end
|