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

issuable_activity_shared_examples.rb « usage_data_counters « gitlab « lib « shared_examples « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9dc185553402a0f7ebc14ffd57421eba7c44917a (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
# frozen_string_literal: true

RSpec.shared_examples 'tracked issuable events' do
  before do
    stub_application_setting(usage_ping_enabled: true)
  end

  def count_unique(date_from: Date.today.beginning_of_week, date_to: 1.week.from_now)
    Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(event_names: action, start_date: date_from, end_date: date_to)
  end

  specify do
    aggregate_failures do
      expect(track_action({ author: user1 }.merge(track_params))).to be_truthy
      expect(track_action({ author: user1 }.merge(track_params))).to be_truthy
      expect(track_action({ author: user2 }.merge(track_params))).to be_truthy
      expect(count_unique).to eq(2)
    end
  end

  it 'does not track edit actions if author is not present' do
    expect(track_action({ author: nil }.merge(track_params))).to be_nil
  end
end

RSpec.shared_examples 'tracked issuable snowplow and service ping events for given event params' do
  it_behaves_like 'tracked issuable events'

  it 'emits snowplow event' do
    track_action({ author: user1 }.merge(track_params))

    expect_snowplow_event(**{ category: category, action: event_action, user: user1 }.merge(event_params))
  end
end

RSpec.shared_examples 'tracked issuable internal event for given event params' do
  it_behaves_like 'tracked issuable events'

  it_behaves_like 'internal event tracking' do
    subject(:track_event) { track_action({ author: user1 }.merge(track_params)) }

    let(:user) { user1 }
    let(:namespace) { project&.namespace }
  end
end

RSpec.shared_examples 'tracked issuable internal event with project' do
  it_behaves_like 'tracked issuable internal event for given event params' do
    let(:track_params) { original_params || { project: project } }
  end
end

RSpec.shared_examples 'tracked issuable snowplow and service ping events with project' do
  it_behaves_like 'tracked issuable snowplow and service ping events for given event params' do
    let(:context) do
      Gitlab::Tracking::ServicePingContext
        .new(data_source: :redis_hll, event: event_property)
        .to_h
    end

    let(:track_params) { original_params || { project: project } }
    let(:event_params) { { project: project }.merge(label: event_label, property: event_property, namespace: project.namespace, context: [context]) }
  end
end

RSpec.shared_examples 'tracked issuable snowplow and service ping events with namespace' do
  it_behaves_like 'tracked issuable snowplow and service ping events for given event params' do
    let(:context) do
      Gitlab::Tracking::ServicePingContext
        .new(data_source: :redis_hll, event: event_property)
        .to_h
    end

    let(:track_params) { { namespace: namespace } }
    let(:event_params) { track_params.merge(label: event_label, property: event_property, context: [context]) }
  end
end

RSpec.shared_examples 'does not track with namespace when feature flag is disabled' do |feature_flag|
  context "when feature flag #{feature_flag} is disabled" do
    it 'does not track action' do
      stub_feature_flags(feature_flag => false)

      expect(track_action(author: user1, namespace: namespace)).to be_nil
    end
  end
end