Commit 9c155210 authored by Rubén Dávila's avatar Rubén Dávila

Return currently used seats for free or trial subscriptions

We need to show the current number of billable seats for free or trial
hosted subscriptions in order to improve the access to this information
for our customers.
parent 6d2c6d34
......@@ -90,6 +90,14 @@ class GitlabSubscription < ApplicationRecord
self.hosted_plan = Plan.find_by(name: code)
end
# We need to show seats in use for free or trial subscriptions
# in order to make it easy for customers to get this information.
def seats_in_use
return super if has_a_paid_hosted_plan? || !hosted?
calculate_seats_in_use
end
private
def log_previous_state_for_update
......
---
title: Return seats in use for free or trial subscriptions
merge_request: 44973
author:
type: changed
......@@ -107,6 +107,18 @@ RSpec.describe 'Billing plan pages', :feature do
end
end
shared_examples 'currently used seats' do
before do
visit page_path
end
it 'displays the number of seats', :js do
page.within('.js-subscription-table') do
expect(page).to have_selector('p.property-value.gl-mt-2.gl-mb-0.number', text: '1')
end
end
end
context 'users profile billing page' do
let(:page_path) { profile_billings_path }
......@@ -343,6 +355,13 @@ RSpec.describe 'Billing plan pages', :feature do
it_behaves_like 'can contact sales'
end
context 'on free' do
let(:plan) { free_plan }
let!(:subscription) { create(:gitlab_subscription, namespace: namespace, hosted_plan: plan) }
it_behaves_like 'currently used seats'
end
end
end
......@@ -388,6 +407,7 @@ RSpec.describe 'Billing plan pages', :feature do
it_behaves_like 'downgradable plan'
it_behaves_like 'non-upgradable plan'
it_behaves_like 'currently used seats'
end
end
end
......
......@@ -200,6 +200,53 @@ RSpec.describe GitlabSubscription do
end
end
describe '#seats_in_use' do
let(:group) { create(:group) }
let!(:group_member) { create(:group_member, :developer, user: create(:user), group: group) }
let(:hosted_plan) { nil }
let(:trial) { false }
let(:gitlab_subscription) do
create(:gitlab_subscription, namespace: group, trial: trial, hosted_plan: hosted_plan, seats_in_use: 5)
end
subject { gitlab_subscription.seats_in_use }
context 'with a paid plan' do
let(:hosted_plan) { gold_plan }
it 'returns the previously calculated seats in use' do
expect(subject).to eq(5)
end
end
context 'with a trial plan' do
let(:hosted_plan) { gold_plan }
let(:trial) { true }
it 'returns the currently seats in use' do
expect(subject).to eq(1)
end
end
context 'with a free plan' do
let(:hosted_plan) { free_plan }
it 'returns the currently seats in use' do
expect(subject).to eq(1)
end
end
context 'with a self hosted plan' do
let(:group) { nil }
let(:group_member) { nil }
it 'returns the previously calculated seats in use' do
expect(subject).to eq(5)
end
end
end
describe '#expired?' do
let(:gitlab_subscription) { create(:gitlab_subscription, end_date: end_date) }
......
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