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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/tracking_spec.rb')
-rw-r--r--spec/lib/gitlab/tracking_spec.rb89
1 files changed, 75 insertions, 14 deletions
diff --git a/spec/lib/gitlab/tracking_spec.rb b/spec/lib/gitlab/tracking_spec.rb
index dacaae55676..61b2c89ffa1 100644
--- a/spec/lib/gitlab/tracking_spec.rb
+++ b/spec/lib/gitlab/tracking_spec.rb
@@ -2,6 +2,8 @@
require 'spec_helper'
RSpec.describe Gitlab::Tracking do
+ include StubENV
+
before do
stub_application_setting(snowplow_enabled: true)
stub_application_setting(snowplow_collector_hostname: 'gitfoo.com')
@@ -12,17 +14,62 @@ RSpec.describe Gitlab::Tracking do
end
describe '.options' do
- it 'returns useful client options' do
- expected_fields = {
- namespace: 'gl',
- hostname: 'gitfoo.com',
- cookieDomain: '.gitfoo.com',
- appId: '_abc123_',
- formTracking: true,
- linkClickTracking: true
- }
-
- expect(subject.options(nil)).to match(expected_fields)
+ shared_examples 'delegates to destination' do |klass|
+ before do
+ allow_next_instance_of(klass) do |instance|
+ allow(instance).to receive(:options).and_call_original
+ end
+ end
+
+ it "delegates to #{klass} destination" do
+ expect_next_instance_of(klass) do |instance|
+ expect(instance).to receive(:options)
+ end
+
+ subject.options(nil)
+ end
+ end
+
+ context 'when destination is Snowplow' do
+ it_behaves_like 'delegates to destination', Gitlab::Tracking::Destinations::Snowplow
+
+ it 'returns useful client options' do
+ expected_fields = {
+ namespace: 'gl',
+ hostname: 'gitfoo.com',
+ cookieDomain: '.gitfoo.com',
+ appId: '_abc123_',
+ formTracking: true,
+ linkClickTracking: true
+ }
+
+ expect(subject.options(nil)).to match(expected_fields)
+ end
+ end
+
+ context 'when destination is SnowplowMicro' do
+ before do
+ stub_env('SNOWPLOW_MICRO_ENABLE', '1')
+ allow(Rails.env).to receive(:development?).and_return(true)
+ end
+
+ it_behaves_like 'delegates to destination', Gitlab::Tracking::Destinations::SnowplowMicro
+
+ it 'returns useful client options' do
+ expected_fields = {
+ namespace: 'gl',
+ hostname: 'localhost:9090',
+ cookieDomain: '.gitlab.com',
+ appId: '_abc123_',
+ protocol: 'http',
+ port: 9090,
+ force_secure_tracker: false,
+ formTracking: true,
+ linkClickTracking: true
+ }
+
+ expect(subject.options(nil)).to match(expected_fields)
+ end
end
it 'when feature flag is disabled' do
@@ -41,7 +88,6 @@ RSpec.describe Gitlab::Tracking do
shared_examples 'delegates to destination' do |klass|
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
it "delegates to #{klass} destination" do
@@ -72,8 +118,23 @@ RSpec.describe Gitlab::Tracking do
end
end
- it_behaves_like 'delegates to destination', Gitlab::Tracking::Destinations::Snowplow
- it_behaves_like 'delegates to destination', Gitlab::Tracking::Destinations::ProductAnalytics
+ context 'when destination is Snowplow' do
+ before do
+ stub_env('SNOWPLOW_MICRO_ENABLE', '0')
+ allow(Rails.env).to receive(:development?).and_return(true)
+ end
+
+ it_behaves_like 'delegates to destination', Gitlab::Tracking::Destinations::Snowplow
+ end
+
+ context 'when destination is SnowplowMicro' do
+ before do
+ stub_env('SNOWPLOW_MICRO_ENABLE', '1')
+ allow(Rails.env).to receive(:development?).and_return(true)
+ end
+
+ it_behaves_like 'delegates to destination', Gitlab::Tracking::Destinations::SnowplowMicro
+ end
it 'tracks errors' do
expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception).with(