diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /spec/lib/product_analytics | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) | |
download | gitlab-ce-85dc423f7090da0a52c73eb66faf22ddb20efff9.tar.gz |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'spec/lib/product_analytics')
-rw-r--r-- | spec/lib/product_analytics/tracker_spec.rb | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/spec/lib/product_analytics/tracker_spec.rb b/spec/lib/product_analytics/tracker_spec.rb index d5e85e6e1cd..0d0660235f1 100644 --- a/spec/lib/product_analytics/tracker_spec.rb +++ b/spec/lib/product_analytics/tracker_spec.rb @@ -1,8 +1,57 @@ # frozen_string_literal: true -require "spec_helper" +require 'spec_helper' RSpec.describe ProductAnalytics::Tracker do it { expect(described_class::URL).to eq('http://localhost/-/sp.js') } it { expect(described_class::COLLECTOR_URL).to eq('localhost/-/collector') } + + describe '.event' do + after do + described_class.clear_memoization(:snowplow) + end + + context 'when usage ping is enabled' do + let(:tracker) { double } + let(:project_id) { 1 } + + before do + stub_application_setting(usage_ping_enabled: true, self_monitoring_project_id: project_id) + end + + it 'sends an event to Product Analytics snowplow collector' do + expect(SnowplowTracker::AsyncEmitter) + .to receive(:new) + .with(described_class::COLLECTOR_URL, { protocol: 'http' }) + .and_return('_emitter_') + + expect(SnowplowTracker::Tracker) + .to receive(:new) + .with('_emitter_', an_instance_of(SnowplowTracker::Subject), 'gl', project_id.to_s) + .and_return(tracker) + + freeze_time do + expect(tracker) + .to receive(:track_struct_event) + .with('category', 'action', '_label_', '_property_', '_value_', nil, (Time.current.to_f * 1000).to_i) + + described_class.event('category', 'action', label: '_label_', property: '_property_', + value: '_value_', context: nil) + end + end + end + + context 'when usage ping is disabled' do + before do + stub_application_setting(usage_ping_enabled: false) + end + + it 'does not send an event' do + expect(SnowplowTracker::Tracker).not_to receive(:new) + + described_class.event('category', 'action', label: '_label_', property: '_property_', + value: '_value_', context: nil) + end + end + end end |