summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/usage_data_counters/issue_activity_unique_counter_spec.rb
blob: f8f6494b92ef5467fd1b5a3a8ea7192435e100d3 (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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_gitlab_redis_shared_state do
  let(:user1) { build(:user, id: 1) }
  let(:user2) { build(:user, id: 2) }
  let(:user3) { build(:user, id: 3) }
  let(:time) { Time.zone.now }

  context 'for Issue title edit actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_TITLE_CHANGED }

      def track_action(params)
        described_class.track_issue_title_changed_action(**params)
      end
    end
  end

  context 'for Issue description edit actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_DESCRIPTION_CHANGED }

      def track_action(params)
        described_class.track_issue_description_changed_action(**params)
      end
    end
  end

  context 'for Issue assignee edit actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_ASSIGNEE_CHANGED }

      def track_action(params)
        described_class.track_issue_assignee_changed_action(**params)
      end
    end
  end

  context 'for Issue make confidential actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_MADE_CONFIDENTIAL }

      def track_action(params)
        described_class.track_issue_made_confidential_action(**params)
      end
    end
  end

  context 'for Issue make visible actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_MADE_VISIBLE }

      def track_action(params)
        described_class.track_issue_made_visible_action(**params)
      end
    end
  end

  context 'for Issue created actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_CREATED }

      def track_action(params)
        described_class.track_issue_created_action(**params)
      end
    end
  end

  context 'for Issue closed actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_CLOSED }

      def track_action(params)
        described_class.track_issue_closed_action(**params)
      end
    end
  end

  context 'for Issue reopened actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_REOPENED }

      def track_action(params)
        described_class.track_issue_reopened_action(**params)
      end
    end
  end

  context 'for Issue label changed actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_LABEL_CHANGED }

      def track_action(params)
        described_class.track_issue_label_changed_action(**params)
      end
    end
  end

  context 'for Issue cross-referenced actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_CROSS_REFERENCED }

      def track_action(params)
        described_class.track_issue_cross_referenced_action(**params)
      end
    end
  end

  context 'for Issue moved actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_MOVED }

      def track_action(params)
        described_class.track_issue_moved_action(**params)
      end
    end
  end

  context 'for Issue cloned actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_CLONED }

      def track_action(params)
        described_class.track_issue_cloned_action(**params)
      end
    end
  end

  context 'for Issue relate actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_RELATED }

      def track_action(params)
        described_class.track_issue_related_action(**params)
      end
    end
  end

  context 'for Issue unrelate actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_UNRELATED }

      def track_action(params)
        described_class.track_issue_unrelated_action(**params)
      end
    end
  end

  context 'for Issue marked as duplicate actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_MARKED_AS_DUPLICATE }

      def track_action(params)
        described_class.track_issue_marked_as_duplicate_action(**params)
      end
    end
  end

  context 'for Issue locked actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_LOCKED }

      def track_action(params)
        described_class.track_issue_locked_action(**params)
      end
    end
  end

  context 'for Issue unlocked actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_UNLOCKED }

      def track_action(params)
        described_class.track_issue_unlocked_action(**params)
      end
    end
  end

  context 'for Issue designs added actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_DESIGNS_ADDED }

      def track_action(params)
        described_class.track_issue_designs_added_action(**params)
      end
    end
  end

  context 'for Issue designs modified actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_DESIGNS_MODIFIED }

      def track_action(params)
        described_class.track_issue_designs_modified_action(**params)
      end
    end
  end

  context 'for Issue designs removed actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_DESIGNS_REMOVED }

      def track_action(params)
        described_class.track_issue_designs_removed_action(**params)
      end
    end
  end

  context 'for Issue due date changed actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_DUE_DATE_CHANGED }

      def track_action(params)
        described_class.track_issue_due_date_changed_action(**params)
      end
    end
  end

  context 'for Issue time estimate changed actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_TIME_ESTIMATE_CHANGED }

      def track_action(params)
        described_class.track_issue_time_estimate_changed_action(**params)
      end
    end
  end

  context 'for Issue time spent changed actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_TIME_SPENT_CHANGED }

      def track_action(params)
        described_class.track_issue_time_spent_changed_action(**params)
      end
    end
  end

  context 'for Issue comment added actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_COMMENT_ADDED }

      def track_action(params)
        described_class.track_issue_comment_added_action(**params)
      end
    end
  end

  context 'for Issue comment edited actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_COMMENT_EDITED }

      def track_action(params)
        described_class.track_issue_comment_edited_action(**params)
      end
    end
  end

  context 'for Issue comment removed actions' do
    it_behaves_like 'a daily tracked issuable event' do
      let(:action) { described_class::ISSUE_COMMENT_REMOVED }

      def track_action(params)
        described_class.track_issue_comment_removed_action(**params)
      end
    end
  end

  it 'can return the count of actions per user deduplicated', :aggregate_failures do
    described_class.track_issue_title_changed_action(author: user1)
    described_class.track_issue_description_changed_action(author: user1)
    described_class.track_issue_assignee_changed_action(author: user1)
    described_class.track_issue_title_changed_action(author: user2, time: time - 2.days)
    described_class.track_issue_title_changed_action(author: user3, time: time - 3.days)
    described_class.track_issue_description_changed_action(author: user3, time: time - 3.days)
    described_class.track_issue_assignee_changed_action(author: user3, time: time - 3.days)

    events = Gitlab::UsageDataCounters::HLLRedisCounter.events_for_category(described_class::ISSUE_CATEGORY)
    today_count = Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(event_names: events, start_date: time, end_date: time)
    week_count = Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(event_names: events, start_date: time - 5.days, end_date: 1.day.since(time))

    expect(today_count).to eq(1)
    expect(week_count).to eq(3)
  end
end