Commit c8e5276f authored by Eugie Limpin's avatar Eugie Limpin Committed by Sincheol (David) Kim

Event tracking for require_verification_for_group_creation experiment

parent a2aa897b
......@@ -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