2019-10-28 20:06:10 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-24 10:24:56 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe 'value stream analytics events' do
|
2022-08-02 17:09:18 -04:00
|
|
|
include CycleAnalyticsHelpers
|
|
|
|
|
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) }
|
2019-01-16 07:09:29 -05:00
|
|
|
let(:issue) { create(:issue, project: project, created_at: 2.days.ago) }
|
2016-10-24 10:24:56 -04:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
describe 'GET /:namespace/:project/value_stream_analytics/events/issues' do
|
2022-08-04 05:10:47 -04:00
|
|
|
let(:first_issue_iid) { project.issues.sort_by_attribute(:created_desc).pick(:iid).to_s }
|
|
|
|
let(:first_mr_iid) { project.merge_requests.sort_by_attribute(:created_desc).pick(:iid).to_s }
|
2021-08-18 02:11:01 -04:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
2016-10-24 10:24:56 -04:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
3.times do |count|
|
|
|
|
travel_to(Time.now + count.days) do
|
|
|
|
create_cycle
|
2017-01-25 05:55:11 -05:00
|
|
|
end
|
2020-12-11 07:09:43 -05:00
|
|
|
end
|
2016-10-24 10:49:25 -04:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
deploy_master(user, project)
|
2016-10-24 10:49:25 -04:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
login_as(user)
|
|
|
|
end
|
2016-11-02 11:21:49 -04:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
it 'lists the issue events' do
|
|
|
|
get project_cycle_analytics_issue_path(project, format: :json)
|
2016-10-24 10:49:25 -04:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
expect(json_response['events']).not_to be_empty
|
|
|
|
expect(json_response['events'].first['iid']).to eq(first_issue_iid)
|
|
|
|
end
|
2016-11-02 11:21:49 -04:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
it 'lists the plan events' do
|
|
|
|
get project_cycle_analytics_plan_path(project, format: :json)
|
2016-11-02 11:21:49 -04:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
expect(json_response['events']).not_to be_empty
|
|
|
|
expect(json_response['events'].first['iid']).to eq(first_issue_iid)
|
|
|
|
end
|
2016-10-24 10:49:25 -04:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
it 'lists the code events' do
|
|
|
|
get project_cycle_analytics_code_path(project, format: :json)
|
2016-10-24 10:49:25 -04:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
expect(json_response['events']).not_to be_empty
|
2016-10-24 10:49:25 -04:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
expect(json_response['events'].first['iid']).to eq(first_mr_iid)
|
|
|
|
end
|
2016-10-24 10:49:25 -04:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
it 'lists the test events', :sidekiq_inline do
|
|
|
|
get project_cycle_analytics_test_path(project, format: :json)
|
2016-10-24 10:49:25 -04:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
expect(json_response['events']).not_to be_empty
|
2021-08-18 02:11:01 -04:00
|
|
|
|
|
|
|
expect(json_response['events'].first['iid']).to eq(first_mr_iid)
|
2021-01-11 01:10:29 -05:00
|
|
|
end
|
2016-10-24 10:49:25 -04:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
it 'lists the review events' do
|
|
|
|
get project_cycle_analytics_review_path(project, format: :json)
|
2016-11-09 05:44:29 -05:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
expect(json_response['events']).not_to be_empty
|
2021-08-18 02:11:01 -04:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
expect(json_response['events'].first['iid']).to eq(first_mr_iid)
|
|
|
|
end
|
2016-11-15 10:25:37 -05:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
it 'lists the staging events', :sidekiq_inline do
|
|
|
|
get project_cycle_analytics_staging_path(project, format: :json)
|
2016-11-15 10:25:37 -05:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
expect(json_response['events']).not_to be_empty
|
2021-08-18 02:11:01 -04:00
|
|
|
|
|
|
|
expect(json_response['events'].first['iid']).to eq(first_issue_iid)
|
2021-01-11 01:10:29 -05:00
|
|
|
end
|
2016-11-15 10:25:37 -05:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
context 'with private project and builds' do
|
|
|
|
before do
|
2021-04-03 02:09:31 -04:00
|
|
|
project.members.last.update!(access_level: Gitlab::Access::GUEST)
|
2021-01-11 01:10:29 -05:00
|
|
|
end
|
2016-11-15 10:25:37 -05:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
it 'does not list the test events' do
|
|
|
|
get project_cycle_analytics_test_path(project, format: :json)
|
2016-11-15 10:25:37 -05:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
end
|
2016-11-15 10:25:37 -05:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
it 'does not list the staging events' do
|
|
|
|
get project_cycle_analytics_staging_path(project, format: :json)
|
2016-11-15 10:25:37 -05:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2016-11-15 10:25:37 -05:00
|
|
|
end
|
2016-10-24 10:24:56 -04:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
it 'lists the issue events' do
|
|
|
|
get project_cycle_analytics_issue_path(project, format: :json)
|
2020-12-11 07:09:43 -05:00
|
|
|
|
2021-01-11 01:10:29 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
end
|
2020-12-11 07:09:43 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-02 11:21:49 -04:00
|
|
|
def create_cycle
|
|
|
|
milestone = create(:milestone, project: project)
|
2021-04-03 02:09:31 -04:00
|
|
|
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)
|
2020-12-11 07:09:43 -05:00
|
|
|
|
|
|
|
mr.metrics.update!(latest_build_started_at: 1.hour.ago, latest_build_finished_at: Time.now)
|
2016-11-02 11:21:49 -04:00
|
|
|
end
|
2016-10-24 10:24:56 -04:00
|
|
|
end
|