Commit 7fd25956 authored by Jay Swain's avatar Jay Swain

Add spec to ensure banner will disappear

While working on an issue I realized that the functionality was already
baked in, though I added a spec here to make sure it was working
correct.

part of:
https://gitlab.com/gitlab-org/growth/engineering/-/issues/5405
parent ddd56f64
...@@ -28,6 +28,12 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -28,6 +28,12 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
allow_any_instance_of(Gitlab::ExpiringSubscriptionMessage).to receive(:grace_period_effective_from).and_return(grace_period_effective_from) allow_any_instance_of(Gitlab::ExpiringSubscriptionMessage).to receive(:grace_period_effective_from).and_return(grace_period_effective_from)
end end
around do |example|
Timecop.freeze(today) do
example.run
end
end
context 'subscribable installed' do context 'subscribable installed' do
let(:auto_renew) { false } let(:auto_renew) { false }
...@@ -80,52 +86,40 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -80,52 +86,40 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
let(:plan_name) { ::Plan::SILVER } let(:plan_name) { ::Plan::SILVER }
it "shows the expiring message" do it "shows the expiring message" do
Timecop.freeze(today) do
expect(subject).to include('Your subscription expired! No worries, you can still use all the Silver features for now. You have 0 days to renew your subscription.') expect(subject).to include('Your subscription expired! No worries, you can still use all the Silver features for now. You have 0 days to renew your subscription.')
end end
end end
end
it 'has a nice subject' do it 'has a nice subject' do
Timecop.freeze(today) do
expect(subject).to include('Your subscription has been downgraded.') expect(subject).to include('Your subscription has been downgraded.')
end end
end
context 'no namespace' do context 'no namespace' do
it 'has an expiration blocking message' do it 'has an expiration blocking message' do
Timecop.freeze(today) do
expect(subject).to include("You didn't renew your subscription so it was downgraded to the GitLab Core Plan") expect(subject).to include("You didn't renew your subscription so it was downgraded to the GitLab Core Plan")
end end
end end
end
context 'with namespace' do context 'with namespace' do
let(:namespace) { double(:namespace, name: 'No Limit Records') } let(:namespace) { double(:namespace, name: 'No Limit Records') }
it 'has an expiration blocking message' do it 'has an expiration blocking message' do
Timecop.freeze(today) do
expect(subject).to include("You didn't renew your subscription for No Limit Records so it was downgraded to the free plan") expect(subject).to include("You didn't renew your subscription for No Limit Records so it was downgraded to the free plan")
end end
end
context 'is auto_renew' do context 'is auto_renew' do
let(:auto_renew) { true } let(:auto_renew) { true }
it 'has a nice subject' do it 'has a nice subject' do
Timecop.freeze(today) do
expect(subject).to include('Something went wrong with your automatic subscription renewal') expect(subject).to include('Something went wrong with your automatic subscription renewal')
end end
end
it 'has an expiration blocking message' do it 'has an expiration blocking message' do
Timecop.freeze(today) do
expect(subject).to include("We tried to automatically renew your subscription for No Limit Records on 2020-03-01 but something went wrong so your subscription was downgraded to the free plan. Don't worry, your data is safe. We suggest you check your payment method and get in touch with our support team (support@gitlab.com). They'll gladly help with your subscription renewal.") expect(subject).to include("We tried to automatically renew your subscription for No Limit Records on 2020-03-01 but something went wrong so your subscription was downgraded to the free plan. Don't worry, your data is safe. We suggest you check your payment method and get in touch with our support team (support@gitlab.com). They'll gladly help with your subscription renewal.")
end end
end end
end end
end end
end
context 'when it is not currently blocking changes' do context 'when it is not currently blocking changes' do
let(:plan_name) { ::Plan::GOLD } let(:plan_name) { ::Plan::GOLD }
...@@ -138,22 +132,18 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -138,22 +132,18 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
it 'has a nice subject' do it 'has a nice subject' do
allow(subscribable).to receive(:will_block_changes?).and_return(false) allow(subscribable).to receive(:will_block_changes?).and_return(false)
Timecop.freeze(today) do
expect(subject).to include('Your subscription expired!') expect(subject).to include('Your subscription expired!')
end end
end
it 'has an expiration blocking message' do it 'has an expiration blocking message' do
allow(subscribable).to receive(:block_changes_at).and_return(Time.utc(2020, 3, 9, 10).to_date) allow(subscribable).to receive(:block_changes_at).and_return(Time.utc(2020, 3, 9, 10).to_date)
allow(subscribable).to receive(:is_a?).with(::License).and_return(true) allow(subscribable).to receive(:is_a?).with(::License).and_return(true)
Timecop.freeze(today) do
expect(subject).to include('No worries, you can still use all the Gold features for now. You have 2 days to renew your subscription.') expect(subject).to include('No worries, you can still use all the Gold features for now. You have 2 days to renew your subscription.')
end end
end end
end end
end end
end
context 'subscribable is expiring soon' do context 'subscribable is expiring soon' do
before do before do
...@@ -163,18 +153,14 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -163,18 +153,14 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
end end
it 'has a nice subject' do it 'has a nice subject' do
Timecop.freeze(today) do
expect(subject).to include('Your subscription will expire in 2 days') expect(subject).to include('Your subscription will expire in 2 days')
end end
end
context 'without namespace' do context 'without namespace' do
it 'has an expiration blocking message' do it 'has an expiration blocking message' do
Timecop.freeze(today) do
expect(subject).to include('Your Gold subscription will expire on 2020-03-09. After that, you will not to be able to create issues or merge requests as well as many other features.') expect(subject).to include('Your Gold subscription will expire on 2020-03-09. After that, you will not to be able to create issues or merge requests as well as many other features.')
end end
end end
end
context 'with namespace' do context 'with namespace' do
let(:namespace) { double(:namespace, name: 'No Limit Records') } let(:namespace) { double(:namespace, name: 'No Limit Records') }
...@@ -182,26 +168,20 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -182,26 +168,20 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
it 'has gold plan specific messaging' do it 'has gold plan specific messaging' do
allow(subscribable).to receive(:plan).and_return('gold') allow(subscribable).to receive(:plan).and_return('gold')
Timecop.freeze(today) do
expect(subject).to include('Your Gold subscription for No Limit Records will expire on 2020-03-09. After that, you will not to be able to use merge approvals or epics as well as many security features.') expect(subject).to include('Your Gold subscription for No Limit Records will expire on 2020-03-09. After that, you will not to be able to use merge approvals or epics as well as many security features.')
end end
end
it 'has silver plan specific messaging' do it 'has silver plan specific messaging' do
allow(subscribable).to receive(:plan).and_return('silver') allow(subscribable).to receive(:plan).and_return('silver')
Timecop.freeze(today) do
expect(subject).to include('Your Silver subscription for No Limit Records will expire on 2020-03-09. After that, you will not to be able to use merge approvals or epics as well as many other features.') expect(subject).to include('Your Silver subscription for No Limit Records will expire on 2020-03-09. After that, you will not to be able to use merge approvals or epics as well as many other features.')
end end
end
it 'has bronze plan specific messaging' do it 'has bronze plan specific messaging' do
allow(subscribable).to receive(:plan).and_return('bronze') allow(subscribable).to receive(:plan).and_return('bronze')
Timecop.freeze(today) do
expect(subject).to include('Your Bronze subscription for No Limit Records will expire on 2020-03-09. After that, you will not to be able to use merge approvals or code quality as well as many other features.') expect(subject).to include('Your Bronze subscription for No Limit Records will expire on 2020-03-09. After that, you will not to be able to use merge approvals or code quality as well as many other features.')
end end
end
context 'is auto_renew nil' do context 'is auto_renew nil' do
let(:auto_renew) { nil } let(:auto_renew) { nil }
...@@ -238,15 +218,20 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -238,15 +218,20 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
let(:grace_period_effective_from) { today.to_date - 40.days } let(:grace_period_effective_from) { today.to_date - 40.days }
it 'has a nice subject' do it 'has a nice subject' do
Timecop.freeze(today) do
expect(subject).to include('Your subscription has been downgraded') expect(subject).to include('Your subscription has been downgraded')
end end
end end
context 'and is 30 days past the cutoff date' do
let(:grace_period_effective_from) { today.to_date - 60.days }
it 'stops displaying' do
expect(subject).to be nil
end
end end
context 'and not past the cutoff date' do context 'and not past the cutoff date' do
it 'has a nice subject' do it 'has a nice subject' do
Timecop.freeze(today) do
expect(subject).to include('Your subscription will expire in 5 days') expect(subject).to include('Your subscription will expire in 5 days')
end end
end end
...@@ -254,7 +239,6 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do ...@@ -254,7 +239,6 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
end end
end end
end end
end
context 'no subscribable installed' do context 'no subscribable installed' do
let(:subscribable) { nil } let(:subscribable) { nil }
......
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