debian-mirror-gitlab/spec/lib/gitlab/tracking_spec.rb

92 lines
3.3 KiB
Ruby
Raw Normal View History

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
2021-02-22 17:27:13 +05:30
before do
allow_any_instance_of(Gitlab::Tracking::Destinations::Snowplow).to receive(:event)
allow_any_instance_of(Gitlab::Tracking::Destinations::ProductAnalytics).to receive(:event)
end
2021-03-08 18:12:59 +05:30
shared_examples 'delegates to destination' do |klass|
context 'with standard context' do
it "delegates to #{klass} destination" do
expect_any_instance_of(klass).to receive(:event) do |_, category, action, args|
expect(category).to eq('category')
expect(action).to eq('action')
expect(args[:label]).to eq('label')
expect(args[:property]).to eq('property')
expect(args[:value]).to eq(1.5)
expect(args[:context].length).to eq(1)
expect(args[:context].first.to_json[:schema]).to eq(Gitlab::Tracking::StandardContext::GITLAB_STANDARD_SCHEMA_URL)
expect(args[:context].first.to_json[:data]).to include(foo: 'bar')
end
2019-12-04 20:38:33 +05:30
2021-03-08 18:12:59 +05:30
described_class.event('category', 'action', label: 'label', property: 'property', value: 1.5,
standard_context: Gitlab::Tracking::StandardContext.new(foo: 'bar'))
end
end
2021-02-22 17:27:13 +05:30
2021-03-08 18:12:59 +05:30
context 'without standard context' do
it "delegates to #{klass} destination" do
expect_any_instance_of(klass).to receive(:event) do |_, category, action, args|
expect(category).to eq('category')
expect(action).to eq('action')
expect(args[:label]).to eq('label')
expect(args[:property]).to eq('property')
expect(args[:value]).to eq(1.5)
end
2021-02-22 17:27:13 +05:30
2021-03-08 18:12:59 +05:30
described_class.event('category', 'action', label: 'label', property: 'property', value: 1.5)
end
end
2021-02-22 17:27:13 +05:30
end
2021-03-08 18:12:59 +05:30
include_examples 'delegates to destination', Gitlab::Tracking::Destinations::Snowplow
include_examples 'delegates to destination', Gitlab::Tracking::Destinations::ProductAnalytics
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)
2021-02-22 17:27:13 +05:30
.with('iglu:com.gitlab/foo/jsonschema/1-0-0', data: { foo: 'bar' }, context: nil)
2019-12-04 20:38:33 +05:30
2021-02-22 17:27:13 +05:30
described_class.self_describing_event('iglu:com.gitlab/foo/jsonschema/1-0-0', data: { foo: 'bar' })
2019-12-04 20:38:33 +05:30
end
end
end