Commit 112b08b6 authored by Vijay Hawoldar's avatar Vijay Hawoldar

Fix a bug when checking future renewals for a subgroup

Previously, when checking if a future renewal for a subscription was
present, the service would assume that the namespace being passed to it
was the one with the gitlab subscription. This is not always the case,
so now it will check the root ancestor of the given namespace
parent e8fd52b4
......@@ -10,11 +10,12 @@
module GitlabSubscriptions
class CheckFutureRenewalService
def initialize(namespace:)
@namespace = namespace
@namespace = namespace.root_ancestor
end
def execute
return false unless Feature.enabled?(:gitlab_subscription_future_renewal, default_enabled: :yaml)
return false unless namespace.gitlab_subscription.present?
future_renewal
end
......
......@@ -45,6 +45,23 @@ RSpec.describe GitlabSubscriptions::CheckFutureRenewalService, :use_clean_rails_
end
end
context 'when called with a sub-group' do
let(:root_namespace) { create(:group_with_plan) }
let(:namespace) { build(:group, parent: root_namespace) }
it 'uses the root ancestor namespace' do
expect(Gitlab::SubscriptionPortal::Client).to receive(:subscription_last_term).with(root_namespace.id).and_return({})
execute_service
end
end
context 'when the namespace has no plan' do
let(:namespace) { build(:group) }
it { is_expected.to be false }
end
context 'when the `gitlab_subscription_future_renewal` feature flag is disabled' do
before do
stub_feature_flags(gitlab_subscription_future_renewal: false)
......
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