2019-12-04 20:38:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::Tracking do
|
2019-12-04 20:38:33 +05:30
|
|
|
before do
|
|
|
|
stub_application_setting(snowplow_enabled: true)
|
|
|
|
stub_application_setting(snowplow_collector_hostname: 'gitfoo.com')
|
|
|
|
stub_application_setting(snowplow_cookie_domain: '.gitfoo.com')
|
2019-12-26 22:10:19 +05:30
|
|
|
stub_application_setting(snowplow_app_id: '_abc123_')
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
described_class.instance_variable_set("@snowplow", nil)
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe '.snowplow_options' do
|
|
|
|
it 'returns useful client options' do
|
2019-12-26 22:10:19 +05:30
|
|
|
expected_fields = {
|
2019-12-04 20:38:33 +05:30
|
|
|
namespace: 'gl',
|
|
|
|
hostname: 'gitfoo.com',
|
|
|
|
cookieDomain: '.gitfoo.com',
|
|
|
|
appId: '_abc123_',
|
|
|
|
formTracking: true,
|
2020-11-24 15:15:51 +05:30
|
|
|
linkClickTracking: true
|
2019-12-26 22:10:19 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
expect(subject.snowplow_options(nil)).to match(expected_fields)
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
it 'when feature flag is disabled' do
|
|
|
|
stub_feature_flags(additional_snowplow_tracking: false)
|
|
|
|
|
|
|
|
expect(subject.snowplow_options(nil)).to include(
|
2019-12-04 20:38:33 +05:30
|
|
|
formTracking: false,
|
|
|
|
linkClickTracking: false
|
2020-06-23 00:09:42 +05:30
|
|
|
)
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
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)
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
described_class.event('category', 'action', label: 'label', property: 'property', value: 1.5)
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
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)
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
described_class.self_describing_event('iglu:com.gitlab/foo/jsonschema/1-0-0', foo: 'bar')
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|