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

117 lines
3.7 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'
2020-07-28 23:09:34 +05:30
RSpec.describe 'value stream 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
2021-03-08 18:12:59 +05:30
describe 'GET /:namespace/:project/value_stream_analytics/events/issues' do
2021-10-27 15:23:28 +05:30
let(:first_issue_iid) { project.issues.sort_by_attribute(:created_desc).pluck(:iid).first.to_s }
let(:first_mr_iid) { project.merge_requests.sort_by_attribute(:created_desc).pluck(:iid).first.to_s }
2021-03-08 18:12:59 +05:30
before do
project.add_developer(user)
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
3.times do |count|
travel_to(Time.now + count.days) do
create_cycle
2017-08-17 22:00:37 +05:30
end
2021-02-22 17:27:13 +05:30
end
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
deploy_master(user, project)
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
login_as(user)
end
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
it 'lists the issue events' do
get project_cycle_analytics_issue_path(project, format: :json)
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
expect(json_response['events']).not_to be_empty
expect(json_response['events'].first['iid']).to eq(first_issue_iid)
end
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
it 'lists the plan events' do
get project_cycle_analytics_plan_path(project, format: :json)
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
expect(json_response['events']).not_to be_empty
expect(json_response['events'].first['iid']).to eq(first_issue_iid)
end
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
it 'lists the code events' do
get project_cycle_analytics_code_path(project, format: :json)
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
expect(json_response['events']).not_to be_empty
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
expect(json_response['events'].first['iid']).to eq(first_mr_iid)
end
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
it 'lists the test events', :sidekiq_inline do
get project_cycle_analytics_test_path(project, format: :json)
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
expect(json_response['events']).not_to be_empty
2021-10-27 15:23:28 +05:30
expect(json_response['events'].first['iid']).to eq(first_mr_iid)
2021-03-08 18:12:59 +05:30
end
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
it 'lists the review events' do
get project_cycle_analytics_review_path(project, format: :json)
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
expect(json_response['events']).not_to be_empty
2021-10-27 15:23:28 +05:30
2021-03-08 18:12:59 +05:30
expect(json_response['events'].first['iid']).to eq(first_mr_iid)
end
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
it 'lists the staging events', :sidekiq_inline do
get project_cycle_analytics_staging_path(project, format: :json)
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
expect(json_response['events']).not_to be_empty
2021-10-27 15:23:28 +05:30
expect(json_response['events'].first['iid']).to eq(first_issue_iid)
2021-03-08 18:12:59 +05:30
end
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
context 'with private project and builds' do
before do
2021-04-29 21:17:54 +05:30
project.members.last.update!(access_level: Gitlab::Access::GUEST)
2021-03-08 18:12:59 +05:30
end
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
it 'does not list the test events' do
get project_cycle_analytics_test_path(project, format: :json)
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
expect(response).to have_gitlab_http_status(:not_found)
end
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
it 'does not list the staging events' do
get project_cycle_analytics_staging_path(project, format: :json)
2017-08-17 22:00:37 +05:30
2021-03-08 18:12:59 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2017-08-17 22:00:37 +05:30
end
2021-03-08 18:12:59 +05:30
it 'lists the issue events' do
get project_cycle_analytics_issue_path(project, format: :json)
2021-02-22 17:27:13 +05:30
2021-03-08 18:12:59 +05:30
expect(response).to have_gitlab_http_status(:ok)
end
2021-02-22 17:27:13 +05:30
end
end
2017-08-17 22:00:37 +05:30
def create_cycle
milestone = create(:milestone, project: project)
2021-04-29 21:17:54 +05:30
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)
2021-02-22 17:27:13 +05:30
mr.metrics.update!(latest_build_started_at: 1.hour.ago, latest_build_finished_at: Time.now)
2017-08-17 22:00:37 +05:30
end
end