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

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

# Requires a context containing:
# - subject
# - event
# - user
# Optionally, the context can contain:
# - project
# - namespace

RSpec.shared_examples 'internal event tracking' do
  let(:fake_tracker) { instance_spy(Gitlab::Tracking::Destinations::Snowplow) }

  before do
    allow(Gitlab::Tracking).to receive(:tracker).and_return(fake_tracker)

    allow(Gitlab::Tracking::StandardContext).to receive(:new).and_call_original
    allow(Gitlab::Tracking::ServicePingContext).to receive(:new).and_call_original
  end

  it 'logs to Snowplow', :aggregate_failures do
    subject

    project = try(:project)
    user = try(:user)
    namespace = try(:namespace)

    expect(Gitlab::Tracking::StandardContext)
      .to have_received(:new)
        .with(
          project_id: project&.id,
          user_id: user&.id,
          namespace_id: namespace&.id,
          plan_name: namespace&.actual_plan_name
        ).at_least(:once)

    expect(Gitlab::Tracking::ServicePingContext)
      .to have_received(:new)
        .with(data_source: :redis_hll, event: event)
        .at_least(:once)

    expect(fake_tracker).to have_received(:event)
      .with(
        'InternalEventTracking',
        event,
        context: [
          an_instance_of(SnowplowTracker::SelfDescribingJson),
          an_instance_of(SnowplowTracker::SelfDescribingJson)
        ]
      )
  end
end