Commit 2ec0d5e3 authored by Vladlena Shumilo's avatar Vladlena Shumilo Committed by Thong Kuah

Allow empty future subscriptions on seat link sync

Update the SyncSeatLinkRequestWorker logic to clear
future_subscriptions setting if the response in
future subscriptions is empty

Changelog: fixed
EE: true
parent dda57adf
...@@ -84,9 +84,9 @@ class SyncSeatLinkRequestWorker ...@@ -84,9 +84,9 @@ class SyncSeatLinkRequestWorker
end end
def save_future_subscriptions(response) def save_future_subscriptions(response)
return if response['future_subscriptions'].blank? future_subscriptions = response['future_subscriptions'].presence || []
Gitlab::CurrentSettings.current_application_settings.update!(future_subscriptions: response['future_subscriptions']) Gitlab::CurrentSettings.current_application_settings.update!(future_subscriptions: future_subscriptions)
rescue StandardError => err rescue StandardError => err
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(err) Gitlab::ErrorTracking.track_and_raise_for_dev_exception(err)
end end
......
...@@ -12,6 +12,7 @@ RSpec.describe SyncSeatLinkRequestWorker, type: :worker do ...@@ -12,6 +12,7 @@ RSpec.describe SyncSeatLinkRequestWorker, type: :worker do
it 'makes an HTTP POST request with passed params' do it 'makes an HTTP POST request with passed params' do
stub_request(:post, seat_link_url).to_return(status: 200) stub_request(:post, seat_link_url).to_return(status: 200)
allow(Gitlab::CurrentSettings).to receive(:uuid).and_return('one-two-three')
sync_seat_link sync_seat_link
...@@ -24,7 +25,7 @@ RSpec.describe SyncSeatLinkRequestWorker, type: :worker do ...@@ -24,7 +25,7 @@ RSpec.describe SyncSeatLinkRequestWorker, type: :worker do
max_historical_user_count: 5, max_historical_user_count: 5,
billable_users_count: 4, billable_users_count: 4,
hostname: Gitlab.config.gitlab.host, hostname: Gitlab.config.gitlab.host,
instance_id: Gitlab::CurrentSettings.uuid, instance_id: 'one-two-three',
license_md5: ::License.current.md5 license_md5: ::License.current.md5
}.to_json }.to_json
) )
...@@ -171,19 +172,41 @@ RSpec.describe SyncSeatLinkRequestWorker, type: :worker do ...@@ -171,19 +172,41 @@ RSpec.describe SyncSeatLinkRequestWorker, type: :worker do
) )
end end
it 'persists future subscription information' do context 'when future subscription information is present in the response' do
expect { sync_seat_link }.to change { Gitlab::CurrentSettings.current_application_settings.future_subscriptions }.from([]).to(future_subscriptions) context 'and no future subscriptions are saved in the current settings' do
it 'persists future subscription information' do
expect { sync_seat_link }.to change { Gitlab::CurrentSettings.current_application_settings.future_subscriptions }.from([]).to(future_subscriptions)
end
end
context 'and future subscriptions are saved in the current settings' do
before do
Gitlab::CurrentSettings.current_application_settings.update!(future_subscriptions: [{}])
end
it 'replaces future subscription information' do
expect { sync_seat_link }.to change { Gitlab::CurrentSettings.current_application_settings.future_subscriptions }.from([{}]).to(future_subscriptions)
end
end
end end
context 'when future subscription is empty' do context 'when future subscription information is not present in the response' do
let(:future_subscriptions) { [] } let(:future_subscriptions) { [] }
before do context 'and no future subscriptions are saved in the current settings' do
Gitlab::CurrentSettings.current_application_settings.update!(future_subscriptions: [{}]) it 'does not change the settings' do
expect { sync_seat_link }.not_to change { Gitlab::CurrentSettings.current_application_settings.future_subscriptions }.from(future_subscriptions)
end
end end
it 'does nothing' do context 'and future subscription are saved in the current settings' do
expect { sync_seat_link }.not_to change { Gitlab::CurrentSettings.current_application_settings.future_subscriptions }.from([{}]) before do
Gitlab::CurrentSettings.current_application_settings.update!(future_subscriptions: [{}])
end
it 'clears future subscription information' do
expect { sync_seat_link }.to change { Gitlab::CurrentSettings.current_application_settings.future_subscriptions }.from([{}]).to(future_subscriptions)
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