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

quick_action_activity_unique_counter_spec.rb « usage_data_counters « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d4c423f57fe6253237f09cd5b42edc3adabddfeb (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::UsageDataCounters::QuickActionActivityUniqueCounter, :clean_gitlab_redis_shared_state do
  let(:user) { build(:user, id: 1) }
  let(:note) { build(:note, author: user) }
  let(:args) { nil }

  shared_examples_for 'a tracked quick action unique event' do
    specify do
      expect { 3.times { subject } }
        .to change {
          Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(
            event_names: action,
            start_date: 2.weeks.ago,
            end_date: 2.weeks.from_now
          )
        }
        .by(1)
    end
  end

  subject { described_class.track_unique_action(quickaction_name, args: args, user: user) }

  describe '.track_unique_action' do
    let(:quickaction_name) { 'approve' }

    it_behaves_like 'a tracked quick action unique event' do
      let(:action) { 'i_quickactions_approve' }
    end
  end

  context 'tracking assigns' do
    let(:quickaction_name) { 'assign' }

    context 'single assignee' do
      let(:args) { '@one' }

      it_behaves_like 'a tracked quick action unique event' do
        let(:action) { 'i_quickactions_assign_single' }
      end
    end

    context 'multiple assignees' do
      let(:args) { '@one @two' }

      it_behaves_like 'a tracked quick action unique event' do
        let(:action) { 'i_quickactions_assign_multiple' }
      end
    end

    context 'assigning "me"' do
      let(:args) { 'me' }

      it_behaves_like 'a tracked quick action unique event' do
        let(:action) { 'i_quickactions_assign_self' }
      end
    end

    context 'assigning a reviewer' do
      let(:quickaction_name) { 'assign_reviewer' }

      it_behaves_like 'a tracked quick action unique event' do
        let(:action) { 'i_quickactions_assign_reviewer' }
      end
    end

    context 'assigning a reviewer with request review alias' do
      let(:quickaction_name) { 'request_review' }

      it_behaves_like 'a tracked quick action unique event' do
        let(:action) { 'i_quickactions_assign_reviewer' }
      end
    end
  end

  context 'tracking copy_metadata' do
    let(:quickaction_name) { 'copy_metadata' }

    context 'for issues' do
      let(:args) { '#123' }

      it_behaves_like 'a tracked quick action unique event' do
        let(:action) { 'i_quickactions_copy_metadata_issue' }
      end
    end

    context 'for merge requests' do
      let(:args) { '!123' }

      it_behaves_like 'a tracked quick action unique event' do
        let(:action) { 'i_quickactions_copy_metadata_merge_request' }
      end
    end
  end

  context 'tracking spend' do
    let(:quickaction_name) { 'spend' }

    context 'adding time' do
      let(:args) { '1d' }

      it_behaves_like 'a tracked quick action unique event' do
        let(:action) { 'i_quickactions_spend_add' }
      end
    end

    context 'removing time' do
      let(:args) { '-1d' }

      it_behaves_like 'a tracked quick action unique event' do
        let(:action) { 'i_quickactions_spend_subtract' }
      end
    end
  end

  context 'tracking unassign' do
    let(:quickaction_name) { 'unassign' }

    context 'unassigning everyone' do
      it_behaves_like 'a tracked quick action unique event' do
        let(:action) { 'i_quickactions_unassign_all' }
      end
    end

    context 'unassigning specific users' do
      let(:args) { '@hello' }

      it_behaves_like 'a tracked quick action unique event' do
        let(:action) { 'i_quickactions_unassign_specific' }
      end
    end
  end

  context 'tracking unlabel' do
    context 'called as unlabel' do
      let(:quickaction_name) { 'unlabel' }

      context 'removing all labels' do
        it_behaves_like 'a tracked quick action unique event' do
          let(:action) { 'i_quickactions_unlabel_all' }
        end
      end

      context 'removing specific labels' do
        let(:args) { '~wow' }

        it_behaves_like 'a tracked quick action unique event' do
          let(:action) { 'i_quickactions_unlabel_specific' }
        end
      end
    end

    context 'called as remove_label' do
      let(:quickaction_name) { 'remove_label' }

      it_behaves_like 'a tracked quick action unique event' do
        let(:action) { 'i_quickactions_unlabel_all' }
      end
    end
  end
end