Commit a6db6314 authored by Dmitry Gruzd's avatar Dmitry Gruzd

Merge branch '273033-sync' into 'master'

Persist license returned from seat link

See merge request gitlab-org/gitlab!58619
parents 4aa39fc5 dd1c0046
......@@ -23,11 +23,21 @@ class SyncSeatLinkRequestWorker
body: request_body(timestamp, license_key, max_historical_user_count, active_users)
)
raise RequestError, request_error_message(response) unless response.success?
if response.success?
create_license(response['license']) if response['license']
else
raise RequestError, request_error_message(response)
end
end
private
def create_license(license_data)
License.create!(data: license_data, cloud: true)
rescue => e
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e)
end
def request_body(timestamp, license_key, max_historical_user_count, active_users)
Gitlab::SeatLinkData.new(
timestamp: Time.zone.parse(timestamp),
......
......@@ -27,6 +27,37 @@ RSpec.describe SyncSeatLinkRequestWorker, type: :worker do
)
end
context 'when response contains a license' do
let(:license_key) { build(:gitlab_license).export }
let(:body) { { success: true, license: license_key }.to_json }
before do
stub_request(:post, seat_link_url).to_return(
status: 200,
body: body,
headers: { content_type: 'application/json' }
)
end
it 'persists returned license' do
expect { subject }.to change(License, :count).by(1)
expect(License.last).to have_attributes(
data: license_key,
cloud: true
)
end
context 'when persisting fails' do
let(:license_key) { 'invalid-key' }
it 'logs error' do
expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception).and_call_original
expect { subject }.to raise_error
end
end
end
context 'with old date format string' do
subject do
described_class.new.perform('2020-01-01', '123', 5, 4)
......
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