Commit 826423aa authored by Nicolas Dular's avatar Nicolas Dular

Enable in-product emails only for free instances

This enables in-product-marketing emails only for free instances
parent ebb5e2d7
......@@ -9,10 +9,27 @@ module Namespaces
urgency :low
def perform
return unless Gitlab::CurrentSettings.in_product_marketing_emails_enabled
return if Gitlab.com? && !Gitlab::Experimentation.active?(:in_product_marketing_emails)
return if paid_self_managed_instance?
return if setting_disabled?
return if experiment_inactive?
Namespaces::InProductMarketingEmailsService.send_for_all_tracks_and_intervals
end
private
def paid_self_managed_instance?
false
end
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
Namespaces::InProductMarketingEmailsWorker.prepend_if_ee('EE::Namespaces::InProductMarketingEmailsWorker')
---
title: Enable in-product emails only for free instances
merge_request: 59290
author:
type: changed
# frozen_string_literal: true
module EE
module Namespaces
module InProductMarketingEmailsWorker # rubocop:disable Scalability/IdempotentWorker
extend ::Gitlab::Utils::Override
private
override :paid_self_managed_instance?
def paid_self_managed_instance?
!::Gitlab.com? && License.current&.paid?
end
end
end
end
# frozen_string_literal: true
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) }
where(:in_product_marketing_emails_enabled, :experiment_active, :executes_service) do
true | true | 1
true | false | 1
false | false | 0
false | true | 0
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 }
include_examples 'in-product marketing email'
end
context 'free' do
let(:is_paid) { false }
include_examples 'in-product marketing email'
end
end
context 'without a license' do
before do
allow(License).to receive(:current).and_return(nil)
end
include_examples '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
include_examples 'in-product marketing email'
end
end
end
# 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
......@@ -5,32 +5,22 @@ require 'spec_helper'
RSpec.describe Namespaces::InProductMarketingEmailsWorker, '#perform' do
using RSpec::Parameterized::TableSyntax
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
context 'not on gitlab.com' 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
end
with_them do
include_examples 'in-product marketing email'
# Running these tests in EE would call the overriden method, which we can't test in CE.
# EE is covered in a separate EE spec.
unless Gitlab.ee?
context 'not on gitlab.com' 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
end
with_them do
include_examples 'in-product marketing email'
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