Commit 48f1696c authored by Vitaly Slobodin's avatar Vitaly Slobodin

Merge branch 'prevent-early-renewal' into 'master'

Hide Renew button if more than 15 days for term end date

See merge request gitlab-org/gitlab!65070
parents b50fef91 2fbdc5f2
...@@ -6,3 +6,5 @@ export const TABLE_TYPE_TRIAL = 'trial'; ...@@ -6,3 +6,5 @@ export const TABLE_TYPE_TRIAL = 'trial';
export const HEADER_TOTAL_ENTRIES = 'x-total'; export const HEADER_TOTAL_ENTRIES = 'x-total';
export const HEADER_PAGE_NUMBER = 'x-page'; export const HEADER_PAGE_NUMBER = 'x-page';
export const HEADER_ITEMS_PER_PAGE = 'x-per-page'; export const HEADER_ITEMS_PER_PAGE = 'x-per-page';
export const DAYS_FOR_RENEWAL = 15;
...@@ -2,7 +2,13 @@ ...@@ -2,7 +2,13 @@
import { GlButton, GlLoadingIcon } from '@gitlab/ui'; import { GlButton, GlLoadingIcon } from '@gitlab/ui';
import { escape } from 'lodash'; import { escape } from 'lodash';
import { mapActions, mapState, mapGetters } from 'vuex'; import { mapActions, mapState, mapGetters } from 'vuex';
import { TABLE_TYPE_DEFAULT, TABLE_TYPE_FREE, TABLE_TYPE_TRIAL } from 'ee/billings/constants'; import {
TABLE_TYPE_DEFAULT,
TABLE_TYPE_FREE,
TABLE_TYPE_TRIAL,
DAYS_FOR_RENEWAL,
} from 'ee/billings/constants';
import { getDayDifference } from '~/lib/utils/datetime/date_calculation_utility';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import SubscriptionTableRow from './subscription_table_row.vue'; import SubscriptionTableRow from './subscription_table_row.vue';
...@@ -42,7 +48,14 @@ export default { ...@@ -42,7 +48,14 @@ export default {
}, },
}, },
computed: { computed: {
...mapState(['isLoadingSubscription', 'hasErrorSubscription', 'plan', 'tables', 'endpoint']), ...mapState([
'isLoadingSubscription',
'hasErrorSubscription',
'plan',
'billing',
'tables',
'endpoint',
]),
...mapGetters(['isFreePlan']), ...mapGetters(['isFreePlan']),
isSubscription() { isSubscription() {
return !this.isFreePlan; return !this.isFreePlan;
...@@ -54,7 +67,13 @@ export default { ...@@ -54,7 +67,13 @@ export default {
return `${this.namespaceName}: ${planName} ${suffix}`; return `${this.namespaceName}: ${planName} ${suffix}`;
}, },
canRenew() { canRenew() {
return this.isSubscription && !this.plan.trial; const subscriptionEndDate = new Date(this.billing.subscriptionEndDate);
const todayDate = new Date();
return (
this.isSubscription &&
!this.plan.trial &&
DAYS_FOR_RENEWAL >= getDayDifference(todayDate, subscriptionEndDate)
);
}, },
canUpgrade() { canUpgrade() {
return !this.freePersonalNamespace && (this.isFreePlan || this.plan.upgradable); return !this.freePersonalNamespace && (this.isFreePlan || this.plan.upgradable);
......
...@@ -19,6 +19,7 @@ export default { ...@@ -19,6 +19,7 @@ export default {
let tableKey = TABLE_TYPE_DEFAULT; let tableKey = TABLE_TYPE_DEFAULT;
state.plan = plan; state.plan = plan;
state.billing = billing;
if (state.plan.code === null) { if (state.plan.code === null) {
tableKey = TABLE_TYPE_FREE; tableKey = TABLE_TYPE_FREE;
......
...@@ -10,6 +10,10 @@ export default () => ({ ...@@ -10,6 +10,10 @@ export default () => ({
trial: false, trial: false,
upgradable: false, upgradable: false,
}, },
billing: {
subscriptionStartDate: null,
subscriptionEndDate: null,
},
tables: { tables: {
free: { free: {
rows: [ rows: [
......
...@@ -68,7 +68,7 @@ RSpec.describe 'Groups > Billing', :js do ...@@ -68,7 +68,7 @@ RSpec.describe 'Groups > Billing', :js do
let(:plan) { 'bronze' } let(:plan) { 'bronze' }
let_it_be(:subscription) do let_it_be(:subscription) do
create(:gitlab_subscription, namespace: group, hosted_plan: bronze_plan, seats: 15) create(:gitlab_subscription, end_date: Date.today + 14.days, namespace: group, hosted_plan: bronze_plan, seats: 15)
end end
it_behaves_like 'hides search settings' it_behaves_like 'hides search settings'
...@@ -91,6 +91,22 @@ RSpec.describe 'Groups > Billing', :js do ...@@ -91,6 +91,22 @@ RSpec.describe 'Groups > Billing', :js do
expect(page).to have_link("See usage", href: group_seat_usage_path(group)) expect(page).to have_link("See usage", href: group_seat_usage_path(group))
end end
end end
context 'when gitlab subscription has end date more than 15 days' do
before do
subscription.update!(end_date: Date.tomorrow + 15.days)
end
it 'does not display renew button' do
renew_url = "#{EE::SUBSCRIPTIONS_URL}/gitlab/namespaces/#{group.id}/renew"
visit group_billings_path(group)
within subscription_table do
expect(page).not_to have_link("Renew", href: renew_url)
end
end
end
end end
context 'with a legacy paid plan' do context 'with a legacy paid plan' do
......
...@@ -76,7 +76,7 @@ describe('SubscriptionTable component', () => { ...@@ -76,7 +76,7 @@ describe('SubscriptionTable component', () => {
beforeEach(() => { beforeEach(() => {
createComponentWithStore(); createComponentWithStore();
store.state.isLoadingSubscription = false; store.state.isLoadingSubscription = false;
store.commit(`${types.RECEIVE_SUBSCRIPTION_SUCCESS}`, mockDataSubscription.gold); store.commit(types.RECEIVE_SUBSCRIPTION_SUCCESS, mockDataSubscription.gold);
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
}); });
...@@ -149,6 +149,9 @@ describe('SubscriptionTable component', () => { ...@@ -149,6 +149,9 @@ describe('SubscriptionTable component', () => {
code: planCode, code: planCode,
trial, trial,
}, },
billing: {
subscriptionEndDate: new Date(),
},
}, },
}); });
}); });
...@@ -158,6 +161,30 @@ describe('SubscriptionTable component', () => { ...@@ -158,6 +161,30 @@ describe('SubscriptionTable component', () => {
}); });
}, },
); );
describe('when subscriptionEndDate is more than 15 days', () => {
beforeEach(() => {
const today = new Date();
const subscriptionEndDate = today.setDate(today.getDate() + 16);
createComponentWithStore({
state: {
isLoadingSubscription: false,
plan: {
code: mockDataSubscription.planCode,
trial: false,
},
billing: {
subscriptionEndDate,
},
},
});
});
it('does not display the renew button', () => {
expect(findRenewButton().exists()).toBe(false);
});
});
}); });
describe('Add seats button', () => { describe('Add seats button', () => {
......
...@@ -71,6 +71,12 @@ describe('EE billings subscription module mutations', () => { ...@@ -71,6 +71,12 @@ describe('EE billings subscription module mutations', () => {
expect(state.plan).toEqual(plan); expect(state.plan).toEqual(plan);
}); });
it('sets billing information', () => {
const { billing } = convertObjectPropsToCamelCase(subscription, { deep: true });
expect(state.billing).toEqual(billing);
});
it(`it updates table ${tableKey} with subscription plan`, () => { it(`it updates table ${tableKey} with subscription plan`, () => {
expect(getStateTableValues(tableKey)).toMatchSnapshot(); expect(getStateTableValues(tableKey)).toMatchSnapshot();
}); });
......
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