Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cycle_analytics_events_spec.rb « projects « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f8fa9459467068160fbea5549786ed9e423791e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'value stream analytics events' do
  let(:user) { create(:user) }
  let(:project) { create(:project, :repository, public_builds: false) }
  let(:issue) { create(:issue, project: project, created_at: 2.days.ago) }

  shared_examples 'value stream analytics events examples' do
    describe 'GET /:namespace/:project/value_stream_analytics/events/issues' do
      before do
        project.add_developer(user)

        3.times do |count|
          travel_to(Time.now + count.days) do
            create_cycle
          end
        end

        deploy_master(user, project)

        login_as(user)
      end

      it 'lists the issue events' do
        get project_cycle_analytics_issue_path(project, format: :json)

        first_issue_iid = project.issues.sort_by_attribute(:created_desc).pluck(:iid).first.to_s

        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
        get project_cycle_analytics_plan_path(project, format: :json)

        first_issue_iid = project.issues.sort_by_attribute(:created_desc).pluck(:iid).first.to_s

        expect(json_response['events']).not_to be_empty
        expect(json_response['events'].first['iid']).to eq(first_issue_iid)
      end

      it 'lists the code events' do
        get project_cycle_analytics_code_path(project, format: :json)

        expect(json_response['events']).not_to be_empty

        first_mr_iid = project.merge_requests.sort_by_attribute(:created_desc).pluck(:iid).first.to_s

        expect(json_response['events'].first['iid']).to eq(first_mr_iid)
      end

      it 'lists the test events', :sidekiq_inline do
        get project_cycle_analytics_test_path(project, format: :json)

        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
        get project_cycle_analytics_review_path(project, format: :json)

        first_mr_iid = project.merge_requests.sort_by_attribute(:created_desc).pluck(:iid).first.to_s

        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', :sidekiq_inline do
        get project_cycle_analytics_staging_path(project, format: :json)

        expect(json_response['events']).not_to be_empty
        expect(json_response['events'].first['date']).not_to be_empty
      end

      context 'with private project and builds' do
        before do
          project.members.last.update(access_level: Gitlab::Access::GUEST)
        end

        it 'does not list the test events' do
          get project_cycle_analytics_test_path(project, format: :json)

          expect(response).to have_gitlab_http_status(:not_found)
        end

        it 'does not list the staging events' do
          get project_cycle_analytics_staging_path(project, format: :json)

          expect(response).to have_gitlab_http_status(:not_found)
        end

        it 'lists the issue events' do
          get project_cycle_analytics_issue_path(project, format: :json)

          expect(response).to have_gitlab_http_status(:ok)
        end
      end
    end
  end

  describe 'when new_project_level_vsa_backend feature flag is off' do
    before do
      stub_feature_flags(new_project_level_vsa_backend: false, thing: project)
    end

    it_behaves_like 'value stream analytics events examples'
  end

  describe 'when new_project_level_vsa_backend feature flag is on' do
    before do
      stub_feature_flags(new_project_level_vsa_backend: true, thing: project)
    end

    it_behaves_like 'value stream analytics events examples'
  end

  def create_cycle
    milestone = create(:milestone, project: project)
    issue.update(milestone: milestone)
    mr = create_merge_request_closing_issue(user, project, issue, commit_message: "References #{issue.to_reference}")

    pipeline = create(:ci_empty_pipeline, status: 'created', project: project, ref: mr.source_branch, sha: mr.source_branch_sha, head_pipeline_of: mr)
    pipeline.run

    create(:ci_build, pipeline: pipeline, status: :success, author: user)
    create(:ci_build, pipeline: pipeline, status: :success, author: user)

    merge_merge_requests_closing_issue(user, project, issue)

    ProcessCommitWorker.new.perform(project.id, user.id, mr.commits.last.to_hash)

    mr.metrics.update!(latest_build_started_at: 1.hour.ago, latest_build_finished_at: Time.now)
  end
end