summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/lib/gitlab/usage_data_counters/incident_management_activity_shared_examples.rb
blob: 788c35dd5bf0944663e3d38487e125cc28f16815 (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
# frozen_string_literal: true

RSpec.shared_examples 'an incident management tracked event' do |event|
  describe ".track_event", :clean_gitlab_redis_shared_state do
    let(:counter) { Gitlab::UsageDataCounters::HLLRedisCounter }
    let(:start_time) { 1.week.ago }
    let(:end_time) { 1.week.from_now }

    it "tracks the event using redis" do
      # Allow other subsequent calls
      allow(Gitlab::UsageDataCounters::HLLRedisCounter)
        .to receive(:track_event)

      expect(Gitlab::UsageDataCounters::HLLRedisCounter)
        .to receive(:track_event)
        .with(current_user.id, event.to_s)
        .and_call_original

      expect { subject }
        .to change { counter.unique_events(event_names: event.to_s, start_date: start_time, end_date: end_time) }
        .by 1
    end
  end
end

RSpec.shared_examples 'does not track incident management event' do |event|
  it 'does not track the event', :clean_gitlab_redis_shared_state do
    expect(Gitlab::UsageDataCounters::HLLRedisCounter)
      .not_to receive(:track_event)
      .with(anything, event.to_s)
  end
end