Commit 1982e4e6 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'remove-in_product_marketing_emails-experiment' into 'master'

Add in-product marketing emails [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!64109
parents e89ff8c5 bf1b79e9
......@@ -2,8 +2,6 @@
module Namespaces
class InProductMarketingEmailsService
include Gitlab::Experimentation::GroupTypes
TRACKS = {
create: {
interval_days: [1, 5, 10],
......@@ -61,12 +59,6 @@ module Namespaces
attr_reader :track, :interval, :in_product_marketing_email_records
def send_email_for_group(group)
if Gitlab.com?
experiment_enabled_for_group = experiment_enabled_for_group?(group)
experiment_add_group(group, experiment_enabled_for_group)
return unless experiment_enabled_for_group
end
users_for_group(group).each do |user|
if can_perform_action?(user, group)
send_email(user, group)
......@@ -77,15 +69,6 @@ module Namespaces
save_tracked_emails!
end
def experiment_enabled_for_group?(group)
Gitlab::Experimentation.in_experiment_group?(:in_product_marketing_emails, subject: group)
end
def experiment_add_group(group, experiment_enabled_for_group)
variant = experiment_enabled_for_group ? GROUP_EXPERIMENTAL : GROUP_CONTROL
Experiment.add_group(:in_product_marketing_emails, variant: variant, group: group)
end
def groups_for_track
onboarding_progress_scope = OnboardingProgress
.completed_actions_with_latest_in_range(completed_actions, range)
......
......@@ -14,7 +14,6 @@ module Namespaces
def perform
return if paid_self_managed_instance?
return if setting_disabled?
return if experiment_inactive?
Namespaces::InProductMarketingEmailsService.send_for_all_tracks_and_intervals
end
......@@ -28,10 +27,6 @@ module Namespaces
def setting_disabled?
!Gitlab::CurrentSettings.in_product_marketing_emails_enabled
end
def experiment_inactive?
Gitlab.com? && !Gitlab::Experimentation.active?(:in_product_marketing_emails)
end
end
end
......
---
name: in_product_marketing_emails_experiment_percentage
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/50679
rollout_issue_url: https://gitlab.com/gitlab-org/growth/team-tasks/-/issues/303
milestone: "13.9"
type: experiment
group: group::activation
default_enabled: false
......@@ -13,7 +13,6 @@ RSpec.describe Namespaces::InProductMarketingEmailsService, '#execute' do
create(:onboarding_progress, namespace: group, created_at: frozen_time - 2.days, git_write_at: nil)
group.add_developer(user)
stub_experiment_for_subject(in_product_marketing_emails: true)
allow(Ability).to receive(:allowed?).with(user, anything, anything).and_return(true)
allow(Notify).to receive(:in_product_marketing_email).and_return(double(deliver_later: nil))
end
......
......@@ -5,60 +5,35 @@ require 'spec_helper'
RSpec.describe Namespaces::InProductMarketingEmailsWorker, '#perform' do
using RSpec::Parameterized::TableSyntax
context 'not on gitlab.com' do
let(:is_gitlab_com) { false }
let(:license) { build(:license) }
let(:license) { build(:license) }
where(:in_product_marketing_emails_enabled, :on_gitlab_dot_com, :paid_license, :executes_service) do
true | true | true | true
true | true | false | true
true | false | true | false
true | false | false | true
false | true | true | false
false | true | false | false
false | false | true | false
false | false | false | false
end
where(:in_product_marketing_emails_enabled, :experiment_active, :executes_service) do
true | true | 1
true | false | 1
false | false | 0
false | true | 0
with_them do
before do
stub_application_setting(in_product_marketing_emails_enabled: in_product_marketing_emails_enabled)
allow(::Gitlab).to receive(:com?).and_return(on_gitlab_dot_com)
allow(License).to receive(:current).and_return(license)
allow(license).to receive(:paid?).and_return(paid_license)
end
with_them do
context 'with a license' do
before do
allow(license).to receive(:paid?).and_return(is_paid)
allow(License).to receive(:current).and_return(license)
end
context 'paid' do
let(:is_paid) { true }
let(:executes_service) { 0 }
it_behaves_like 'in-product marketing email'
end
context 'free' do
let(:is_paid) { false }
it_behaves_like 'in-product marketing email'
end
it 'executes the email service' do
if executes_service
expect(Namespaces::InProductMarketingEmailsService).to receive(:send_for_all_tracks_and_intervals)
else
expect(Namespaces::InProductMarketingEmailsService).not_to receive(:send_for_all_tracks_and_intervals)
end
context 'without a license' do
before do
allow(License).to receive(:current).and_return(nil)
end
it_behaves_like 'in-product marketing email'
end
end
end
context 'on gitlab.com' do
let(:is_gitlab_com) { true }
where(:in_product_marketing_emails_enabled, :experiment_active, :executes_service) do
true | true | 1
true | false | 0
false | false | 0
false | true | 0
end
with_them do
it_behaves_like 'in-product marketing email'
subject.perform
end
end
end
......@@ -62,9 +62,6 @@ module Gitlab
learn_gitlab_b: {
tracking_category: 'Growth::Activation::Experiment::LearnGitLabB',
rollout_strategy: :user
},
in_product_marketing_emails: {
tracking_category: 'Growth::Activation::Experiment::InProductMarketingEmails'
}
}.freeze
......
......@@ -11,7 +11,6 @@ RSpec.describe Namespaces::InProductMarketingEmailsService, '#execute' do
let(:frozen_time) { Time.zone.parse('23 Mar 2021 10:14:40 UTC') }
let(:previous_action_completed_at) { frozen_time - 2.days }
let(:current_action_completed_at) { nil }
let(:experiment_enabled) { true }
let(:user_can_perform_current_track_action) { true }
let(:actions_completed) { { created_at: previous_action_completed_at, git_write_at: current_action_completed_at } }
......@@ -22,7 +21,6 @@ RSpec.describe Namespaces::InProductMarketingEmailsService, '#execute' do
travel_to(frozen_time)
create(:onboarding_progress, namespace: group, **actions_completed)
group.add_developer(user)
stub_experiment_for_subject(in_product_marketing_emails: experiment_enabled)
allow(Ability).to receive(:allowed?).with(user, anything, anything).and_return(user_can_perform_current_track_action)
allow(Notify).to receive(:in_product_marketing_email).and_return(double(deliver_later: nil))
end
......@@ -85,50 +83,6 @@ RSpec.describe Namespaces::InProductMarketingEmailsService, '#execute' do
end
end
describe 'experimentation' do
context 'when on dotcom' do
before do
allow(::Gitlab).to receive(:com?).and_return(true)
end
context 'when the experiment is enabled' do
it 'adds the group as an experiment subject in the experimental group' do
expect(Experiment).to receive(:add_group)
.with(:in_product_marketing_emails, variant: :experimental, group: group)
execute_service
end
end
context 'when the experiment is disabled' do
let(:experiment_enabled) { false }
it 'adds the group as an experiment subject in the control group' do
expect(Experiment).to receive(:add_group)
.with(:in_product_marketing_emails, variant: :control, group: group)
execute_service
end
it { is_expected.not_to send_in_product_marketing_email }
end
context 'when not on dotcom' do
before do
allow(::Gitlab).to receive(:com?).and_return(false)
end
it 'does not add the group as an experiment subject' do
expect(Experiment).not_to receive(:add_group)
execute_service
end
it { is_expected.to send_in_product_marketing_email(user.id, group.id, :create, 0) }
end
end
end
context 'when the previous track action is not yet completed' do
let(:previous_action_completed_at) { nil }
......
# frozen_string_literal: true
RSpec.shared_examples 'in-product marketing email' do
before do
stub_application_setting(in_product_marketing_emails_enabled: in_product_marketing_emails_enabled)
stub_experiment(in_product_marketing_emails: experiment_active)
allow(::Gitlab).to receive(:com?).and_return(is_gitlab_com)
end
it 'executes the email service service' do
expect(Namespaces::InProductMarketingEmailsService).to receive(:send_for_all_tracks_and_intervals).exactly(executes_service).times
subject.perform
end
end
......@@ -2,38 +2,31 @@
require 'spec_helper'
RSpec.describe Namespaces::InProductMarketingEmailsWorker, '#perform' do
using RSpec::Parameterized::TableSyntax
RSpec.describe Namespaces::InProductMarketingEmailsWorker, '#perform', unless: Gitlab.ee? do
# Running this in EE would call the overridden method, which can't be tested in CE.
# The EE code is covered in a separate EE spec.
context 'not on gitlab.com', unless: Gitlab.ee? do
let(:is_gitlab_com) { false }
where(:in_product_marketing_emails_enabled, :experiment_active, :executes_service) do
true | true | 1
true | false | 1
false | false | 0
false | true | 0
context 'when the in_product_marketing_emails_enabled setting is disabled' do
before do
stub_application_setting(in_product_marketing_emails_enabled: false)
end
with_them do
it_behaves_like 'in-product marketing email'
it 'does not execute the email service' do
expect(Namespaces::InProductMarketingEmailsService).not_to receive(:send_for_all_tracks_and_intervals)
subject.perform
end
end
context 'on gitlab.com' do
let(:is_gitlab_com) { true }
where(:in_product_marketing_emails_enabled, :experiment_active, :executes_service) do
true | true | 1
true | false | 0
false | false | 0
false | true | 0
context 'when the in_product_marketing_emails_enabled setting is enabled' do
before do
stub_application_setting(in_product_marketing_emails_enabled: true)
end
with_them do
it_behaves_like 'in-product marketing email'
it 'executes the email service' do
expect(Namespaces::InProductMarketingEmailsService).to receive(:send_for_all_tracks_and_intervals)
subject.perform
end
end
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