Commit 9eb8d8ae authored by Sincheol (David) Kim's avatar Sincheol (David) Kim

Merge branch 'verify-before-create-group-instrumentation' into 'master'

Event tracking for require_verification_for_group_creation experiment

See merge request gitlab-org/gitlab!78167
parents 882a426e c8e5276f
......@@ -31,6 +31,8 @@ module EE
if group.persisted? && create_event
::Groups::CreateEventWorker.perform_async(group.id, current_user.id, :created)
end
track_verification_experiment_conversion
end
override :remove_unallowed_params
......@@ -63,6 +65,13 @@ module EE
group.update(push_rule: push_rule)
end
end
def track_verification_experiment_conversion
return unless group.persisted?
return unless group.root?
experiment(:require_verification_for_group_creation, user: current_user).track(:converted, namespace: group)
end
end
end
end
......@@ -163,6 +163,49 @@ RSpec.describe Groups::CreateService, '#execute' do
end
end
describe 'require_verification_for_group_creation experiment conversion tracking', :experiment do
subject(:execute) { create_group(user, group_params) }
before do
stub_experiments(require_verification_for_group_creation: :control)
end
it 'tracks a "converted" event with the correct context and payload' do
expect(experiment(:require_verification_for_group_creation)).to track(
:converted,
namespace: an_instance_of(Group)
).on_next_instance.with_context(user: user)
execute
end
shared_examples 'does not track' do
it 'does not track a "converted" event' do
expect(experiment(:require_verification_for_group_creation)).not_to track(:converted)
execute
end
end
context 'when group has not been persisted' do
subject(:execute) { create_group(user, group_params.merge(name: '<script>alert("Attack!")</script>')) }
include_examples 'does not track'
end
context 'when created group is a sub-group' do
let(:parent_group) { create :group }
subject(:execute) { create_group(user, group_params.merge(parent_id: parent_group.id)) }
before do
parent_group.add_owner(user)
end
include_examples 'does not track'
end
end
def create_group(user, opts)
described_class.new(user, opts).execute
end
......
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