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: d57e034254407d8c8f0349030ab86ef3819ed1b2 (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
require 'spec_helper'

describe 'cycle analytics events' do
  let(:user) { create(:user) }
  let(:project) { create(:project) }

  describe 'GET /:namespace/:project/cycle_analytics/events/issues' do
    before do
      project.team << [user, :developer]

      3.times { create_cycle }
      deploy_master

      login_as(user)
    end

    it 'lists the issue events' do
      get namespace_project_cycle_analytics_issue_path(project.namespace, project, format: :json)

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

      first_issue_iid = Issue.order(created_at: :desc).pluck(:iid).first.to_s

      expect(json_response['items'].first['iid']).to eq(first_issue_iid)
    end

    it 'lists the plan events' do
      get namespace_project_cycle_analytics_plan_path(project.namespace, project, format: :json)

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

      commits = []

      MergeRequest.all.each do |mr|
        mr.merge_request_diff.st_commits.each do |commit|
          commits << { date: commit[:authored_date], sha: commit[:id] }
        end
      end

      newest_sha = commits.sort_by { |k| k['date'] }.first[:sha][0...8]

      expect(json_response['items'].first['sha']).to eq(newest_sha)
    end

    it 'lists the code events' do
      get namespace_project_cycle_analytics_code_path(project.namespace, project, format: :json)

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

      first_mr_iid = Issue.order(created_at: :desc).pluck(:iid).first.to_s

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

    it 'lists the test events' do
      get namespace_project_cycle_analytics_test_path(project.namespace, project, format: :json)

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

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

    it 'lists the review events' do
      get namespace_project_cycle_analytics_review_path(project.namespace, project, format: :json)

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

      first_mr_iid = Issue.order(created_at: :desc).pluck(:iid).first.to_s

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

    it 'lists the staging events' do
      get namespace_project_cycle_analytics_staging_path(project.namespace, project, format: :json)

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

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

    it 'lists the production events' do
      get namespace_project_cycle_analytics_production_path(project.namespace, project, format: :json)

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

      first_issue_iid = Issue.order(created_at: :desc).pluck(:iid).first.to_s

      expect(json_response['items'].first['iid']).to eq(first_issue_iid)
    end
  end

  def json_response
    JSON.parse(response.body)
  end

  def create_cycle
    issue = create(:issue, project: project, created_at: 2.days.ago)
    milestone = create(:milestone, project: project)
    issue.update(milestone: milestone)
    mr = create_merge_request_closing_issue(issue)

    pipeline = create(:ci_empty_pipeline, status: 'created', project: project, ref: mr.source_branch, sha: mr.source_branch_sha)
    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(issue)
  end
end