blob: 05068cd60afb9886313ba2aefe218e5731c93b5d (
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
# - action
# - 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: action)
.at_least(:once)
expect(fake_tracker).to have_received(:event)
.with(
'InternalEventTracking',
action,
context: [
an_instance_of(SnowplowTracker::SelfDescribingJson),
an_instance_of(SnowplowTracker::SelfDescribingJson)
]
)
end
end
|