Commit 3d17057f authored by James Lopez's avatar James Lopez

Merge branch 'store-seats_currently_in_use-2' into 'master'

Rename seat calculation methods

See merge request gitlab-org/gitlab!40571
parents 44a5a19f 3752f6d0
...@@ -42,7 +42,7 @@ class GitlabSubscription < ApplicationRecord ...@@ -42,7 +42,7 @@ class GitlabSubscription < ApplicationRecord
end end
end end
def seats_in_use def calculate_seats_in_use
namespace.billable_members_count namespace.billable_members_count
end end
...@@ -50,7 +50,7 @@ class GitlabSubscription < ApplicationRecord ...@@ -50,7 +50,7 @@ class GitlabSubscription < ApplicationRecord
# with the historical max. We want to know how many extra users the customer # with the historical max. We want to know how many extra users the customer
# has added to their group (users above the number purchased on their subscription). # has added to their group (users above the number purchased on their subscription).
# Then, on the next month we're going to automatically charge the customers for those extra users. # Then, on the next month we're going to automatically charge the customers for those extra users.
def seats_owed def calculate_seats_owed
return 0 unless has_a_paid_hosted_plan? return 0 unless has_a_paid_hosted_plan?
[0, max_seats_used - seats].max [0, max_seats_used - seats].max
......
...@@ -16,7 +16,7 @@ class UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker # rubocop:disable Scalab ...@@ -16,7 +16,7 @@ class UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker # rubocop:disable Scalab
tuples = [] tuples = []
subscriptions.each do |subscription| subscriptions.each do |subscription|
seats_in_use = subscription.seats_in_use seats_in_use = subscription.calculate_seats_in_use
next if subscription.max_seats_used >= seats_in_use next if subscription.max_seats_used >= seats_in_use
......
...@@ -14,9 +14,9 @@ module EE ...@@ -14,9 +14,9 @@ module EE
expose :usage do expose :usage do
expose :seats, as: :seats_in_subscription expose :seats, as: :seats_in_subscription
expose :seats_in_use expose :calculate_seats_in_use, as: :seats_in_use
expose :max_seats_used expose :max_seats_used
expose :seats_owed expose :calculate_seats_owed, as: :seats_owed
end end
expose :billing do expose :billing do
......
...@@ -53,7 +53,7 @@ RSpec.describe GitlabSubscription do ...@@ -53,7 +53,7 @@ RSpec.describe GitlabSubscription do
end end
end end
describe '#seats_in_use' do describe '#calculate_seats_in_use' do
let!(:user_1) { create(:user) } let!(:user_1) { create(:user) }
let!(:user_2) { create(:user) } let!(:user_2) { create(:user) }
let!(:blocked_user) { create(:user, :blocked) } let!(:blocked_user) { create(:user, :blocked) }
...@@ -68,14 +68,14 @@ RSpec.describe GitlabSubscription do ...@@ -68,14 +68,14 @@ RSpec.describe GitlabSubscription do
it 'returns count of members' do it 'returns count of members' do
group.add_developer(user_1) group.add_developer(user_1)
expect(gitlab_subscription.seats_in_use).to eq(1) expect(gitlab_subscription.calculate_seats_in_use).to eq(1)
end end
it 'also counts users from subgroups' do it 'also counts users from subgroups' do
group.add_developer(user_1) group.add_developer(user_1)
subgroup_1.add_developer(user_2) subgroup_1.add_developer(user_2)
expect(gitlab_subscription.seats_in_use).to eq(2) expect(gitlab_subscription.calculate_seats_in_use).to eq(2)
end end
it 'does not count duplicated members' do it 'does not count duplicated members' do
...@@ -83,7 +83,7 @@ RSpec.describe GitlabSubscription do ...@@ -83,7 +83,7 @@ RSpec.describe GitlabSubscription do
subgroup_1.add_developer(user_2) subgroup_1.add_developer(user_2)
subgroup_2.add_developer(user_2) subgroup_2.add_developer(user_2)
expect(gitlab_subscription.seats_in_use).to eq(2) expect(gitlab_subscription.calculate_seats_in_use).to eq(2)
end end
it 'does not count blocked members' do it 'does not count blocked members' do
...@@ -91,7 +91,7 @@ RSpec.describe GitlabSubscription do ...@@ -91,7 +91,7 @@ RSpec.describe GitlabSubscription do
group.add_developer(blocked_user) group.add_developer(blocked_user)
expect(group.member_count).to eq(2) expect(group.member_count).to eq(2)
expect(gitlab_subscription.seats_in_use).to eq(1) expect(gitlab_subscription.calculate_seats_in_use).to eq(1)
end end
context 'with guest members' do context 'with guest members' do
...@@ -103,7 +103,7 @@ RSpec.describe GitlabSubscription do ...@@ -103,7 +103,7 @@ RSpec.describe GitlabSubscription do
it 'excludes these members' do it 'excludes these members' do
gitlab_subscription.update!(plan_code: 'gold') gitlab_subscription.update!(plan_code: 'gold')
expect(gitlab_subscription.seats_in_use).to eq(0) expect(gitlab_subscription.calculate_seats_in_use).to eq(0)
end end
end end
...@@ -112,7 +112,7 @@ RSpec.describe GitlabSubscription do ...@@ -112,7 +112,7 @@ RSpec.describe GitlabSubscription do
it 'excludes these members' do it 'excludes these members' do
gitlab_subscription.update!(plan_code: plan) gitlab_subscription.update!(plan_code: plan)
expect(gitlab_subscription.seats_in_use).to eq(1) expect(gitlab_subscription.calculate_seats_in_use).to eq(1)
end end
end end
end end
...@@ -130,13 +130,13 @@ RSpec.describe GitlabSubscription do ...@@ -130,13 +130,13 @@ RSpec.describe GitlabSubscription do
[bronze_plan, silver_plan, gold_plan].each do |plan| [bronze_plan, silver_plan, gold_plan].each do |plan|
gitlab_subscription.update!(hosted_plan: plan) gitlab_subscription.update!(hosted_plan: plan)
expect(gitlab_subscription.seats_in_use).to eq(1) expect(gitlab_subscription.calculate_seats_in_use).to eq(1)
end end
end end
end end
end end
describe '#seats_owed' do describe '#calculate_seats_owed' do
let!(:gitlab_subscription) { create(:gitlab_subscription, subscription_attrs) } let!(:gitlab_subscription) { create(:gitlab_subscription, subscription_attrs) }
before do before do
...@@ -145,7 +145,7 @@ RSpec.describe GitlabSubscription do ...@@ -145,7 +145,7 @@ RSpec.describe GitlabSubscription do
shared_examples 'always returns a total of 0' do shared_examples 'always returns a total of 0' do
it 'does not update max_seats_used' do it 'does not update max_seats_used' do
expect(gitlab_subscription.seats_owed).to eq(0) expect(gitlab_subscription.calculate_seats_owed).to eq(0)
end end
end end
...@@ -171,7 +171,7 @@ RSpec.describe GitlabSubscription do ...@@ -171,7 +171,7 @@ RSpec.describe GitlabSubscription do
let(:subscription_attrs) { { hosted_plan: bronze_plan } } let(:subscription_attrs) { { hosted_plan: bronze_plan } }
it 'calculates the number of owed seats' do it 'calculates the number of owed seats' do
expect(gitlab_subscription.reload.seats_owed).to eq(5) expect(gitlab_subscription.reload.calculate_seats_owed).to eq(5)
end end
end end
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