diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /spec/lib/gitlab/tracking | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/lib/gitlab/tracking')
-rw-r--r-- | spec/lib/gitlab/tracking/destinations/product_analytics_spec.rb | 84 | ||||
-rw-r--r-- | spec/lib/gitlab/tracking/destinations/snowplow_spec.rb | 4 |
2 files changed, 86 insertions, 2 deletions
diff --git a/spec/lib/gitlab/tracking/destinations/product_analytics_spec.rb b/spec/lib/gitlab/tracking/destinations/product_analytics_spec.rb new file mode 100644 index 00000000000..63e2e930acd --- /dev/null +++ b/spec/lib/gitlab/tracking/destinations/product_analytics_spec.rb @@ -0,0 +1,84 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Tracking::Destinations::ProductAnalytics do + let(:emitter) { SnowplowTracker::Emitter.new('localhost', buffer_size: 1) } + let(:tracker) { SnowplowTracker::Tracker.new(emitter, SnowplowTracker::Subject.new, 'namespace', 'app_id') } + + describe '#event' do + shared_examples 'does not send an event' do + it 'does not send an event' do + expect_any_instance_of(SnowplowTracker::Tracker).not_to receive(:track_struct_event) + + subject.event(allowed_category, allowed_action) + end + end + + let(:allowed_category) { 'epics' } + let(:allowed_action) { 'promote' } + let(:self_monitoring_project) { create(:project) } + + before do + stub_feature_flags(product_analytics_tracking: true) + stub_application_setting(self_monitoring_project_id: self_monitoring_project.id) + stub_application_setting(usage_ping_enabled: true) + end + + context 'with allowed event' do + it 'sends an event to Product Analytics snowplow collector' do + expect(SnowplowTracker::AsyncEmitter) + .to receive(:new) + .with(ProductAnalytics::Tracker::COLLECTOR_URL, protocol: Gitlab.config.gitlab.protocol) + .and_return(emitter) + + expect(SnowplowTracker::Tracker) + .to receive(:new) + .with(emitter, an_instance_of(SnowplowTracker::Subject), Gitlab::Tracking::SNOWPLOW_NAMESPACE, self_monitoring_project.id.to_s) + .and_return(tracker) + + freeze_time do + expect(tracker) + .to receive(:track_struct_event) + .with(allowed_category, allowed_action, 'label', 'property', 1.5, nil, (Time.now.to_f * 1000).to_i) + + subject.event(allowed_category, allowed_action, label: 'label', property: 'property', value: 1.5) + end + end + end + + context 'with non-allowed event' do + it 'does not send an event' do + expect_any_instance_of(SnowplowTracker::Tracker).not_to receive(:track_struct_event) + + subject.event('category', 'action') + subject.event(allowed_category, 'action') + subject.event('category', allowed_action) + end + end + + context 'when self-monitoring project does not exist' do + before do + stub_application_setting(self_monitoring_project_id: nil) + end + + include_examples 'does not send an event' + end + + context 'when product_analytics_tracking FF is disabled' do + before do + stub_feature_flags(product_analytics_tracking: false) + end + + include_examples 'does not send an event' + end + + context 'when usage ping is disabled' do + before do + stub_application_setting(usage_ping_enabled: false) + end + + include_examples 'does not send an event' + end + end +end diff --git a/spec/lib/gitlab/tracking/destinations/snowplow_spec.rb b/spec/lib/gitlab/tracking/destinations/snowplow_spec.rb index ee63eb6de04..0e8647ad78a 100644 --- a/spec/lib/gitlab/tracking/destinations/snowplow_spec.rb +++ b/spec/lib/gitlab/tracking/destinations/snowplow_spec.rb @@ -46,7 +46,7 @@ RSpec.describe Gitlab::Tracking::Destinations::Snowplow do it 'sends event to tracker' do allow(tracker).to receive(:track_self_describing_event).and_call_original - subject.self_describing_event('iglu:com.gitlab/foo/jsonschema/1-0-0', foo: 'bar') + subject.self_describing_event('iglu:com.gitlab/foo/jsonschema/1-0-0', data: { foo: 'bar' }) expect(tracker).to have_received(:track_self_describing_event) do |event, context, timestamp| expect(event.to_json[:schema]).to eq('iglu:com.gitlab/foo/jsonschema/1-0-0') @@ -71,7 +71,7 @@ RSpec.describe Gitlab::Tracking::Destinations::Snowplow do it 'does not send event to tracker' do expect_any_instance_of(SnowplowTracker::Tracker).not_to receive(:track_self_describing_event) - subject.self_describing_event('iglu:com.gitlab/foo/jsonschema/1-0-0', foo: 'bar') + subject.self_describing_event('iglu:com.gitlab/foo/jsonschema/1-0-0', data: { foo: 'bar' }) end end end |