Commit e43b7f20 authored by Alex Buijs's avatar Alex Buijs

Skip in-product marketing emails when on trial

Do not send in-product marketing emails when
users of a namespace are on a trial license.

Changelog: changed
EE: true
parent 6636de40
...@@ -45,6 +45,12 @@ module EE ...@@ -45,6 +45,12 @@ module EE
.where(gitlab_subscriptions: { trial: true, trial_ends_on: Date.today.. }) .where(gitlab_subscriptions: { trial: true, trial_ends_on: Date.today.. })
end end
scope :not_in_active_trial, -> do
left_joins(gitlab_subscription: :hosted_plan)
.where(gitlab_subscriptions: { trial: [nil, false] })
.or(GitlabSubscription.where(trial_ends_on: ..Date.yesterday))
end
scope :in_default_plan, -> do scope :in_default_plan, -> do
left_joins(gitlab_subscription: :hosted_plan) left_joins(gitlab_subscription: :hosted_plan)
.where(plans: { name: [nil, *::Plan.default_plans] }) .where(plans: { name: [nil, *::Plan.default_plans] })
......
...@@ -9,7 +9,7 @@ module EE ...@@ -9,7 +9,7 @@ module EE
override :subscription_scope override :subscription_scope
def subscription_scope def subscription_scope
::Namespace.in_default_plan ::Namespace.not_in_active_trial.in_default_plan
end end
end end
end end
......
...@@ -199,9 +199,9 @@ RSpec.describe Namespace do ...@@ -199,9 +199,9 @@ RSpec.describe Namespace do
describe '.in_active_trial' do describe '.in_active_trial' do
let_it_be(:namespaces) do let_it_be(:namespaces) do
[ [
create(:namespace), create(:namespace),
create(:namespace_with_plan), create(:namespace_with_plan),
create(:namespace_with_plan, trial_ends_on: Date.tomorrow) create(:namespace_with_plan, trial_ends_on: Date.tomorrow)
] ]
end end
...@@ -214,6 +214,24 @@ RSpec.describe Namespace do ...@@ -214,6 +214,24 @@ RSpec.describe Namespace do
end end
end end
describe '.not_in_active_trial' do
let_it_be(:namespaces) do
[
create(:namespace),
create(:namespace_with_plan),
create(:namespace_with_plan, trial_ends_on: Date.yesterday)
]
end
it 'is consistent with !trial_active? method' do
namespaces.each do |ns|
consistent = described_class.not_in_active_trial.include?(ns) == !ns.trial_active?
expect(consistent).to be true
end
end
end
describe '.in_default_plan' do describe '.in_default_plan' do
subject { described_class.in_default_plan.ids } subject { described_class.in_default_plan.ids }
......
...@@ -33,8 +33,8 @@ RSpec.describe Namespaces::InProductMarketingEmailsService, '#execute' do ...@@ -33,8 +33,8 @@ RSpec.describe Namespaces::InProductMarketingEmailsService, '#execute' do
context 'on a trial' do context 'on a trial' do
let(:group) { create(:group_with_plan, trial_ends_on: frozen_time + 10.days) } let(:group) { create(:group_with_plan, trial_ends_on: frozen_time + 10.days) }
it 'sends an email' do it 'does not send an email' do
expect(Notify).to have_received(:in_product_marketing_email) expect(Notify).not_to have_received(:in_product_marketing_email)
end 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