summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/tracking_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/tracking_spec.rb')
-rw-r--r--spec/lib/gitlab/tracking_spec.rb106
1 files changed, 15 insertions, 91 deletions
diff --git a/spec/lib/gitlab/tracking_spec.rb b/spec/lib/gitlab/tracking_spec.rb
index 6ddeaf98370..805bd92fd43 100644
--- a/spec/lib/gitlab/tracking_spec.rb
+++ b/spec/lib/gitlab/tracking_spec.rb
@@ -2,13 +2,13 @@
require 'spec_helper'
RSpec.describe Gitlab::Tracking do
- let(:timestamp) { Time.utc(2017, 3, 22) }
-
before do
stub_application_setting(snowplow_enabled: true)
stub_application_setting(snowplow_collector_hostname: 'gitfoo.com')
stub_application_setting(snowplow_cookie_domain: '.gitfoo.com')
stub_application_setting(snowplow_app_id: '_abc123_')
+
+ described_class.instance_variable_set("@snowplow", nil)
end
describe '.snowplow_options' do
@@ -35,99 +35,23 @@ RSpec.describe Gitlab::Tracking do
end
end
- describe 'tracking events' do
- shared_examples 'events not tracked' do
- it 'does not track events' do
- stub_application_setting(snowplow_enabled: false)
- expect(SnowplowTracker::AsyncEmitter).not_to receive(:new)
- expect(SnowplowTracker::Tracker).not_to receive(:new)
-
- track_event
- end
- end
-
- around do |example|
- travel_to(timestamp) { example.run }
- end
-
- before do
- described_class.instance_variable_set("@snowplow", nil)
- end
-
- let(:tracker) { double }
-
- def receive_events
- expect(SnowplowTracker::AsyncEmitter).to receive(:new).with(
- 'gitfoo.com', { protocol: 'https' }
- ).and_return('_emitter_')
+ describe '.event' do
+ it 'delegates to snowplow destination' do
+ expect_any_instance_of(Gitlab::Tracking::Destinations::Snowplow)
+ .to receive(:event)
+ .with('category', 'action', label: 'label', property: 'property', value: 1.5, context: nil)
- expect(SnowplowTracker::Tracker).to receive(:new).with(
- '_emitter_',
- an_instance_of(SnowplowTracker::Subject),
- 'gl',
- '_abc123_'
- ).and_return(tracker)
+ described_class.event('category', 'action', label: 'label', property: 'property', value: 1.5)
end
+ end
- describe '.event' do
- let(:track_event) do
- described_class.event('category', 'action',
- label: '_label_',
- property: '_property_',
- value: '_value_',
- context: nil
- )
- end
-
- it_behaves_like 'events not tracked'
-
- it 'can track events' do
- receive_events
- expect(tracker).to receive(:track_struct_event).with(
- 'category',
- 'action',
- '_label_',
- '_property_',
- '_value_',
- nil,
- (timestamp.to_f * 1000).to_i
- )
-
- track_event
- end
- end
-
- describe '.self_describing_event' do
- let(:track_event) do
- described_class.self_describing_event('iglu:com.gitlab/example/jsonschema/1-0-2',
- {
- foo: 'bar',
- foo_count: 42
- },
- context: nil
- )
- end
-
- it_behaves_like 'events not tracked'
-
- it 'can track self describing events' do
- receive_events
- expect(SnowplowTracker::SelfDescribingJson).to receive(:new).with(
- 'iglu:com.gitlab/example/jsonschema/1-0-2',
- {
- foo: 'bar',
- foo_count: 42
- }
- ).and_return('_event_json_')
-
- expect(tracker).to receive(:track_self_describing_event).with(
- '_event_json_',
- nil,
- (timestamp.to_f * 1000).to_i
- )
+ describe '.self_describing_event' do
+ it 'delegates to snowplow destination' do
+ expect_any_instance_of(Gitlab::Tracking::Destinations::Snowplow)
+ .to receive(:self_describing_event)
+ .with('iglu:com.gitlab/foo/jsonschema/1-0-0', { foo: 'bar' }, context: nil)
- track_event
- end
+ described_class.self_describing_event('iglu:com.gitlab/foo/jsonschema/1-0-0', foo: 'bar')
end
end
end