Commit ef96ae67 authored by Tetiana Chupryna's avatar Tetiana Chupryna

Merge branch 'skip-in-product-marketing-emails-when-on-trial' into 'master'

Skip in-product marketing emails when on trial

See merge request gitlab-org/gitlab!66269
parents 327ce013 e43b7f20
......@@ -45,6 +45,12 @@ module EE
.where(gitlab_subscriptions: { trial: true, trial_ends_on: Date.today.. })
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
left_joins(gitlab_subscription: :hosted_plan)
.where(plans: { name: [nil, *::Plan.default_plans] })
......
......@@ -9,7 +9,7 @@ module EE
override :subscription_scope
def subscription_scope
::Namespace.in_default_plan
::Namespace.not_in_active_trial.in_default_plan
end
end
end
......
......@@ -214,6 +214,24 @@ RSpec.describe Namespace do
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
subject { described_class.in_default_plan.ids }
......
......@@ -33,8 +33,8 @@ RSpec.describe Namespaces::InProductMarketingEmailsService, '#execute' do
context 'on a trial' do
let(:group) { create(:group_with_plan, trial_ends_on: frozen_time + 10.days) }
it 'sends an email' do
expect(Notify).to have_received(:in_product_marketing_email)
it 'does not send an email' do
expect(Notify).not_to have_received(:in_product_marketing_email)
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