Commit a6a84a12 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '244489-remove-all-existing-gitlab-tracking-mocks' into 'master'

Replace some Gitlab::Tracking mocks with snowplow test helper [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!45208
parents 3ac9a973 deff21af
......@@ -186,31 +186,21 @@ RSpec/ExpectChange:
# Offense count: 47
RSpec/ExpectGitlabTracking:
Exclude:
- 'ee/spec/controllers/groups/analytics/coverage_reports_controller_spec.rb'
- 'ee/spec/controllers/projects/settings/operations_controller_spec.rb'
- 'ee/spec/controllers/registrations_controller_spec.rb'
- 'ee/spec/requests/api/visual_review_discussions_spec.rb'
- 'ee/spec/services/epics/issue_promote_service_spec.rb'
- 'spec/controllers/groups/registry/repositories_controller_spec.rb'
- 'spec/controllers/groups_controller_spec.rb'
- 'spec/controllers/projects/registry/repositories_controller_spec.rb'
- 'spec/controllers/projects/registry/tags_controller_spec.rb'
- 'spec/controllers/projects/settings/operations_controller_spec.rb'
- 'spec/controllers/registrations_controller_spec.rb'
- 'spec/lib/api/helpers_spec.rb'
- 'spec/lib/gitlab/experimentation_spec.rb'
- 'spec/mailers/notify_spec.rb'
- 'spec/models/project_services/prometheus_service_spec.rb'
- 'spec/requests/api/project_container_repositories_spec.rb'
- 'spec/services/clusters/applications/check_installation_progress_service_spec.rb'
- 'spec/services/issues/zoom_link_service_spec.rb'
- 'spec/support/helpers/snowplow_helpers.rb'
- 'spec/support/shared_examples/controllers/trackable_shared_examples.rb'
- 'spec/support/shared_examples/requests/api/container_repositories_shared_examples.rb'
- 'spec/support/shared_examples/requests/api/discussions_shared_examples.rb'
- 'spec/support/shared_examples/requests/api/packages_shared_examples.rb'
- 'spec/support/shared_examples/requests/api/tracking_shared_examples.rb'
- 'spec/support/snowplow.rb'
# Offense count: 751
RSpec/ExpectInHook:
......
......@@ -59,16 +59,16 @@ RSpec.describe Groups::Analytics::CoverageReportsController do
stub_licensed_features(group_coverage_reports: true)
end
it 'responds 200 with CSV coverage data' do
expect(Gitlab::Tracking).to receive(:event).with(
described_class.name,
'download_code_coverage_csv',
it 'responds 200 with CSV coverage data', :snowplow do
get :index, params: valid_request_params
expect_snowplow_event(
category: described_class.name,
action: 'download_code_coverage_csv',
label: 'group_id',
value: group.id
)
get :index, params: valid_request_params
expect(response).to have_gitlab_http_status(:ok)
expect(csv_response).to eq([
%w[date group_name project_name coverage],
......
......@@ -148,15 +148,15 @@ RSpec.describe RegistrationsController do
update_registration
end
it 'tracks a signed_up event' do
expect(Gitlab::Tracking).to receive(:event).with(
'Growth::Conversion::Experiment::OnboardingIssues',
'signed_up',
it 'tracks a signed_up event', :snowplow do
update_registration
expect_snowplow_event(
category: 'Growth::Conversion::Experiment::OnboardingIssues',
action: 'signed_up',
label: anything,
property: "#{group_type}_group"
)
update_registration
end
end
end
......@@ -176,10 +176,10 @@ RSpec.describe RegistrationsController do
update_registration
end
it 'does not track a signed_up event' do
expect(Gitlab::Tracking).not_to receive(:event)
it 'does not track a signed_up event', :snowplow do
update_registration
expect_no_snowplow_event
end
end
end
......@@ -196,10 +196,10 @@ RSpec.describe RegistrationsController do
update_registration
end
it 'does not track a signed_up event' do
expect(Gitlab::Tracking).not_to receive(:event)
it 'does not track a signed_up event', :snowplow do
update_registration
expect_no_snowplow_event
end
end
end
......
......@@ -58,9 +58,10 @@ RSpec.describe API::VisualReviewDiscussions do
stub_feature_flags(notes_create_service_tracking: false)
end
it 'does not track any events' do
expect(Gitlab::Tracking).not_to receive(:event)
it 'does not track any events', :snowplow do
request
expect_no_snowplow_event
end
end
......
......@@ -319,10 +319,10 @@ RSpec.describe GroupsController, factory_default: :keep do
stub_experiment(onboarding_issues: false)
end
it 'does not track anything' do
expect(Gitlab::Tracking).not_to receive(:event)
it 'does not track anything', :snowplow do
create_namespace
expect_no_snowplow_event
end
end
......@@ -336,15 +336,15 @@ RSpec.describe GroupsController, factory_default: :keep do
stub_experiment_for_user(onboarding_issues: false)
end
it 'tracks the event with the "created_namespace" action with the "control_group" property' do
expect(Gitlab::Tracking).to receive(:event).with(
'Growth::Conversion::Experiment::OnboardingIssues',
'created_namespace',
it 'tracks the event with the "created_namespace" action with the "control_group" property', :snowplow do
create_namespace
expect_snowplow_event(
category: 'Growth::Conversion::Experiment::OnboardingIssues',
action: 'created_namespace',
label: anything,
property: 'control_group'
)
create_namespace
end
end
......@@ -353,15 +353,15 @@ RSpec.describe GroupsController, factory_default: :keep do
stub_experiment_for_user(onboarding_issues: true)
end
it 'tracks the event with the "created_namespace" action with the "experimental_group" property' do
expect(Gitlab::Tracking).to receive(:event).with(
'Growth::Conversion::Experiment::OnboardingIssues',
'created_namespace',
it 'tracks the event with the "created_namespace" action with the "experimental_group" property', :snowplow do
create_namespace
expect_snowplow_event(
category: 'Growth::Conversion::Experiment::OnboardingIssues',
action: 'created_namespace',
label: anything,
property: 'experimental_group'
)
create_namespace
end
end
end
......
......@@ -161,10 +161,10 @@ RSpec.describe Clusters::Applications::CheckInstallationProgressService, '#execu
expect(application.status_reason).to be_nil
end
it 'tracks application install' do
expect(Gitlab::Tracking).to receive(:event).with('cluster:applications', "cluster_application_helm_installed")
it 'tracks application install', :snowplow do
service.execute
expect_snowplow_event(category: 'cluster:applications', action: 'cluster_application_helm_installed')
end
end
......
......@@ -46,10 +46,15 @@ RSpec.describe Issues::ZoomLinkService do
expect(ZoomMeeting.canonical_meeting_url(issue)).to eq(zoom_link)
end
it 'tracks the add event' do
expect(Gitlab::Tracking).to receive(:event)
.with('IncidentManagement::ZoomIntegration', 'add_zoom_meeting', label: 'Issue ID', value: issue.id)
it 'tracks the add event', :snowplow do
result
expect_snowplow_event(
category: 'IncidentManagement::ZoomIntegration',
action: 'add_zoom_meeting',
label: 'Issue ID',
value: issue.id
)
end
it 'creates a zoom_link_added notification' do
......@@ -180,10 +185,15 @@ RSpec.describe Issues::ZoomLinkService do
expect(ZoomMeeting.canonical_meeting_url(issue)).to eq(nil)
end
it 'tracks the remove event' do
expect(Gitlab::Tracking).to receive(:event)
.with('IncidentManagement::ZoomIntegration', 'remove_zoom_meeting', label: 'Issue ID', value: issue.id)
it 'tracks the remove event', :snowplow do
result
expect_snowplow_event(
category: 'IncidentManagement::ZoomIntegration',
action: 'remove_zoom_meeting',
label: 'Issue ID',
value: issue.id
)
end
end
......
......@@ -36,10 +36,10 @@ module SnowplowHelpers
# would not pass any arguments when using **kwargs.
# https://gitlab.com/gitlab-org/gitlab/-/issues/263430
if kwargs.present?
expect(Gitlab::Tracking).to have_received(:event)
expect(Gitlab::Tracking).to have_received(:event) # rubocop:disable RSpec/ExpectGitlabTracking
.with(category, action, **kwargs).at_least(:once)
else
expect(Gitlab::Tracking).to have_received(:event)
expect(Gitlab::Tracking).to have_received(:event) # rubocop:disable RSpec/ExpectGitlabTracking
.with(category, action).at_least(:once)
end
end
......@@ -56,6 +56,6 @@ module SnowplowHelpers
# end
# end
def expect_no_snowplow_event
expect(Gitlab::Tracking).not_to have_received(:event)
expect(Gitlab::Tracking).not_to have_received(:event) # rubocop:disable RSpec/ExpectGitlabTracking
end
end
......@@ -13,7 +13,7 @@ RSpec.configure do |config|
stub_application_setting(snowplow_enabled: true)
allow(Gitlab::Tracking).to receive(:event).and_call_original
allow(Gitlab::Tracking).to receive(:event).and_call_original # rubocop:disable RSpec/ExpectGitlabTracking
end
config.after(:each, :snowplow) do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment