Commit 2df5a273 authored by Kerri Miller's avatar Kerri Miller

Merge branch 'nicolasdular/trial-started-onboarding-action' into 'master'

Record action when namespace trial starts

See merge request gitlab-org/gitlab!49351
parents b71733d0 9a511e83
......@@ -6,6 +6,9 @@ module GitlabSubscriptions
response = client.generate_trial(apply_trial_params)
if response[:success]
namespace_id = apply_trial_params.dig(:trial_user, :namespace_id)
record_onboarding_progress(namespace_id) if namespace_id
{ success: true }
else
{ success: false, errors: response.dig(:data, :errors) }
......@@ -17,5 +20,12 @@ module GitlabSubscriptions
def client
Gitlab::SubscriptionPortal::Client
end
def record_onboarding_progress(namespace_id)
namespace = Namespace.find_by(id: namespace_id) # rubocop: disable CodeReuse/ActiveRecord
return unless namespace
OnboardingProgressService.new(namespace).execute(action: :trial_started)
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe GitlabSubscriptions::ApplyTrialService do
subject(:execute) { described_class.new.execute(apply_trial_params) }
let_it_be(:namespace) { create(:namespace) }
let(:apply_trial_params) do
{
trial_user: {
namespace_id: namespace.id
}
}
end
describe '#execute' do
before do
allow(Gitlab::SubscriptionPortal::Client).to receive(:generate_trial).and_return(response)
end
context 'trial applied successfully' do
let(:response) { { success: true }}
it 'returns success: true' do
expect(execute).to eq({ success: true })
end
it 'records a namespace onboarding progress action' do
expect_next_instance_of(OnboardingProgressService) do |service|
expect(service).to receive(:execute).with(action: :trial_started)
end
execute
end
end
context 'error while applying the trial' do
let(:response) { { success: false, data: { errors: ['some error'] } }}
it 'returns success: false with errors' do
expected_response = {
success: false,
errors: ['some error']
}
expect(execute).to eq(expected_response)
end
it 'does not record a namespace onboarding progress action' do
expect(OnboardingProgressService).not_to receive(:new)
execute
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