Commit 79a30c82 authored by Vijay Hawoldar's avatar Vijay Hawoldar

Change future renewal service cache key

To ensure the cache is expired when the
subscription is updated
parent 671982d6
......@@ -9,8 +9,8 @@
# returns true, false
module GitlabSubscriptions
class CheckFutureRenewalService
def initialize(namespace_id:)
@namespace_id = namespace_id
def initialize(namespace:)
@namespace = namespace
end
def execute
......@@ -21,14 +21,14 @@ module GitlabSubscriptions
private
attr_reader :namespace_id
attr_reader :namespace
def client
Gitlab::SubscriptionPortal::Client
end
def last_term_request
response = client.subscription_last_term(namespace_id)
response = client.subscription_last_term(namespace.id)
if response[:success]
response[:last_term] == false
......@@ -42,7 +42,7 @@ module GitlabSubscriptions
end
def cache_key
"subscription:future_renewal:namespace:#{namespace_id}"
"subscription:future_renewal:namespace:#{namespace.gitlab_subscription.cache_key}"
end
def future_renewal
......
......@@ -123,6 +123,7 @@ module EE
subscription_params = declared_params(include_missing: false)
subscription_params[:trial_starts_on] ||= subscription_params[:start_date] if subscription_params[:trial]
subscription_params[:updated_at] = Time.current
if subscription.update(subscription_params)
present subscription, with: ::EE::API::Entities::GitlabSubscription
......
......@@ -122,7 +122,7 @@ module Gitlab
def subscription_future_renewal?
return if self_managed? || namespace.nil?
::GitlabSubscriptions::CheckFutureRenewalService.new(namespace_id: namespace.id).execute
::GitlabSubscriptions::CheckFutureRenewalService.new(namespace: namespace).execute
end
def require_notification?
......
......@@ -115,7 +115,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
let_it_be(:namespace) { create(:group, name: 'No Limit Records') }
before do
allow_next_instance_of(GitlabSubscriptions::CheckFutureRenewalService, namespace_id: namespace.id) do |service|
allow_next_instance_of(GitlabSubscriptions::CheckFutureRenewalService, namespace: namespace) do |service|
allow(service).to receive(:execute).and_return(has_future_renewal)
end
end
......@@ -203,7 +203,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
let_it_be(:namespace) { create(:group, name: 'No Limit Records') }
before do
allow_next_instance_of(GitlabSubscriptions::CheckFutureRenewalService, namespace_id: namespace.id) do |service|
allow_next_instance_of(GitlabSubscriptions::CheckFutureRenewalService, namespace: namespace) do |service|
allow(service).to receive(:execute).and_return(has_future_renewal)
end
end
......
......@@ -532,6 +532,12 @@ RSpec.describe API::Namespaces do
max_seats_used: 42
)
end
it 'updates the timestamp when the attributes are the same' do
expect do
do_put(namespace.id, admin, gitlab_subscription.attributes)
end.to change { gitlab_subscription.reload.updated_at }
end
end
end
......
......@@ -6,11 +6,11 @@ RSpec.describe GitlabSubscriptions::CheckFutureRenewalService, :use_clean_rails_
using RSpec::Parameterized::TableSyntax
describe '#execute' do
let(:namespace) { create(:namespace) }
let(:namespace_id) { namespace.id }
let(:cache_key) { "subscription:future_renewal:namespace:#{namespace_id}" }
let_it_be(:namespace) { create(:namespace_with_plan) }
subject(:execute_service) { described_class.new(namespace_id: namespace_id).execute }
let(:cache_key) { "subscription:future_renewal:namespace:#{namespace.gitlab_subscription.cache_key}" }
subject(:execute_service) { described_class.new(namespace: namespace).execute }
where(:in_last_term, :expected_response) do
true | 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