diff options
Diffstat (limited to 'spec/lib/gitlab/gon_helper_spec.rb')
-rw-r--r-- | spec/lib/gitlab/gon_helper_spec.rb | 88 |
1 files changed, 75 insertions, 13 deletions
diff --git a/spec/lib/gitlab/gon_helper_spec.rb b/spec/lib/gitlab/gon_helper_spec.rb index 1135cfc22ac..fc722402917 100644 --- a/spec/lib/gitlab/gon_helper_spec.rb +++ b/spec/lib/gitlab/gon_helper_spec.rb @@ -58,6 +58,7 @@ RSpec.describe Gitlab::GonHelper do context 'when sentry is configured' do let(:clientside_dsn) { 'https://xxx@sentry.example.com/1' } let(:environment) { 'staging' } + let(:sentry_clientside_traces_sample_rate) { 0.5 } context 'with legacy sentry configuration' do before do @@ -77,6 +78,15 @@ RSpec.describe Gitlab::GonHelper do stub_application_setting(sentry_enabled: true) stub_application_setting(sentry_clientside_dsn: clientside_dsn) stub_application_setting(sentry_environment: environment) + stub_application_setting(sentry_clientside_traces_sample_rate: sentry_clientside_traces_sample_rate) + end + + it 'sets sentry dsn and environment from config' do + expect(gon).to receive(:sentry_dsn=).with(clientside_dsn) + expect(gon).to receive(:sentry_environment=).with(environment) + expect(gon).to receive(:sentry_clientside_traces_sample_rate=).with(sentry_clientside_traces_sample_rate) + + helper.add_gon_variables end context 'when enable_new_sentry_clientside_integration is disabled' do @@ -87,19 +97,8 @@ RSpec.describe Gitlab::GonHelper do it 'does not set sentry dsn and environment from config' do expect(gon).not_to receive(:sentry_dsn=).with(clientside_dsn) expect(gon).not_to receive(:sentry_environment=).with(environment) - - helper.add_gon_variables - end - end - - context 'when enable_new_sentry_clientside_integration is enabled' do - before do - stub_feature_flags(enable_new_sentry_clientside_integration: true) - end - - it 'sets sentry dsn and environment from config' do - expect(gon).to receive(:sentry_dsn=).with(clientside_dsn) - expect(gon).to receive(:sentry_environment=).with(environment) + expect(gon).not_to receive(:sentry_clientside_traces_sample_rate=) + .with(sentry_clientside_traces_sample_rate) helper.add_gon_variables end @@ -169,4 +168,67 @@ RSpec.describe Gitlab::GonHelper do expect(url).to match(/no_avatar.*png$/) end end + + describe '#add_browsersdk_tracking' do + let(:gon) { double('gon').as_null_object } + let(:analytics_url) { 'https://analytics.gitlab.com' } + let(:is_gitlab_com) { true } + + before do + allow(helper).to receive(:gon).and_return(gon) + allow(Gitlab).to receive(:com?).and_return(is_gitlab_com) + end + + context 'when environment variables are set' do + before do + stub_env('GITLAB_ANALYTICS_URL', analytics_url) + stub_env('GITLAB_ANALYTICS_ID', 'analytics-id') + end + + it 'sets the analytics_url and analytics_id' do + expect(gon).to receive(:analytics_url=).with(analytics_url) + expect(gon).to receive(:analytics_id=).with('analytics-id') + + helper.add_browsersdk_tracking + end + + context 'when Gitlab.com? is false' do + let(:is_gitlab_com) { false } + + it "doesn't set the analytics_url and analytics_id" do + expect(gon).not_to receive(:analytics_url=) + expect(gon).not_to receive(:analytics_id=) + + helper.add_browsersdk_tracking + end + end + + context 'when feature flag is false' do + before do + stub_feature_flags(browsersdk_tracking: false) + end + + it "doesn't set the analytics_url and analytics_id" do + expect(gon).not_to receive(:analytics_url=) + expect(gon).not_to receive(:analytics_id=) + + helper.add_browsersdk_tracking + end + end + end + + context 'when environment variables are not set' do + before do + stub_env('GITLAB_ANALYTICS_URL', nil) + stub_env('GITLAB_ANALYTICS_ID', nil) + end + + it "doesn't set the analytics_url and analytics_id" do + expect(gon).not_to receive(:analytics_url=) + expect(gon).not_to receive(:analytics_id=) + + helper.add_browsersdk_tracking + end + end + end end |