Commit f08d2da0 authored by Jay Swain's avatar Jay Swain

Add 14 day grace period for expired subscriptions

Show the "you've been downgraded" expiration message 14 days
after a .com subscription ends.

part of:
https://gitlab.com/gitlab-org/growth/product/-/issues/1606
parent 6ac803ea
# frozen_string_literal: true
class SubscriptionPresenter < Gitlab::View::Presenter::Delegated
GRACE_PERIOD_EXTENSION_DAYS = 14.days
presents :subscription
def block_changes?
expired?
will_block_changes? && (block_changes_at < Date.today)
end
def plan
......@@ -22,7 +24,12 @@ class SubscriptionPresenter < Gitlab::View::Presenter::Delegated
def expires_at
end_date
end
alias_method :block_changes_at, :expires_at
def block_changes_at
return unless end_date
end_date + GRACE_PERIOD_EXTENSION_DAYS
end
def remaining_days
return unless end_date
......@@ -33,6 +40,6 @@ class SubscriptionPresenter < Gitlab::View::Presenter::Delegated
end
def will_block_changes?
true
end_date.present?
end
end
---
title: Subscription Banner has 14 day grace period
merge_request: 37378
author:
type: changed
......@@ -47,27 +47,79 @@ RSpec.describe SubscriptionPresenter do
describe '#block_changes_at' do
subject { presenter.block_changes_at }
it { is_expected.to eq(subscription.end_date) }
it { is_expected.to eq(subscription.end_date + 14.days) }
context 'when end_date is nil' do
it 'is nil' do
allow(subscription).to receive(:end_date).and_return(nil)
expect(subject).to be nil
end
end
end
describe '#block_changes?' do
subject { presenter.block_changes? }
it { is_expected.to be false }
let(:today) { Time.utc(2020, 3, 7, 10) }
before do
allow(subscription).to receive(:end_date).and_return(end_date)
end
context 'end_date is nil' do
let(:end_date) { nil }
it { is_expected.to be false }
end
context 'is not expired' do
let(:end_date) { today + 1.day }
it 'is false' do
Timecop.freeze(today) do
expect(subject).to be false
end
end
end
context 'is expired' do
before do
allow(subscription).to receive(:expired?).and_return(true)
context 'is not past grace period' do
let(:end_date) { today - 13.days }
it 'is false' do
Timecop.freeze(today) do
expect(subject).to be false
end
end
end
it { is_expected.to be true }
context 'is past grace period' do
let(:end_date) { today - 15.days }
it 'is true' do
Timecop.freeze(today) do
expect(subject).to be true
end
end
end
end
end
describe '#will_block_changes?' do
subject { presenter.will_block_changes? }
it { is_expected.to be true }
context 'when end_date exists' do
it { is_expected.to be true }
end
context 'when end_date does not exist' do
it 'is false' do
allow(subscription).to receive(:end_date).and_return(nil)
expect(subject).to be false
end
end
end
describe '#remaining_days' do
......
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