debian-mirror-gitlab/spec/requests/projects/cycle_analytics_events_spec.rb

137 lines
4.6 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
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) }
2019-03-02 22:35:43 +05:30
let(:issue) { create(:issue, project: project, created_at: 2.days.ago) }
2017-08-17 22:00:37 +05:30
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
2019-09-04 21:01:54 +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
2019-09-04 21:01:54 +05:30
expect(json_response['events'].first['iid']).to eq(first_issue_iid)
2017-08-17 22:00:37 +05:30
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
2019-12-26 22:10:19 +05:30
it 'lists the test events', :sidekiq_might_not_need_inline 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
2019-12-26 22:10:19 +05:30
it 'lists the staging events', :sidekiq_might_not_need_inline 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
2019-12-26 22:10:19 +05:30
it 'lists the production events', :sidekiq_might_not_need_inline 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
2019-12-26 22:10:19 +05:30
it 'lists the test events', :sidekiq_might_not_need_inline do
2017-08-17 22:00:37 +05:30
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