Commit da8c4a76 authored by Alper Akgun's avatar Alper Akgun

Merge branch '334211-create-hand-raise-lead-service' into 'master'

Create hand raise lead service

See merge request gitlab-org/gitlab!71629
parents ce5d5767 e4e577a4
# frozen_string_literal: true
module GitlabSubscriptions
class CreateHandRaiseLeadService
def execute(params)
response = client.generate_hand_raise_lead(params)
if response[:success]
ServiceResponse.success
else
ServiceResponse.error(message: response.dig(:data, :errors))
end
end
private
def client
Gitlab::SubscriptionPortal::Client
end
end
end
......@@ -13,6 +13,10 @@ module Gitlab
http_post("trials", admin_headers, params)
end
def generate_hand_raise_lead(params)
http_post("trials/create_hand_raise_lead", admin_headers, params)
end
def extend_reactivate_trial(params)
http_put("trials/extend_reactivate_trial", admin_headers, params)
end
......
......@@ -64,6 +64,17 @@ RSpec.describe Gitlab::SubscriptionPortal::Clients::Rest do
it_behaves_like 'when http call raises an exception'
end
describe '#generate_hand_raise_lead' do
subject do
client.generate_hand_raise_lead({})
end
it_behaves_like 'when response is successful'
it_behaves_like 'when response code is 422'
it_behaves_like 'when response code is 500'
it_behaves_like 'when http call raises an exception'
end
describe '#extend_reactivate_trial' do
let(:http_method) { :put }
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe GitlabSubscriptions::CreateHandRaiseLeadService do
subject(:execute) { described_class.new.execute(params) }
let(:params) { {} }
describe '#execute' do
before do
allow(Gitlab::SubscriptionPortal::Client).to receive(:generate_hand_raise_lead).with(params).and_return(response)
end
context 'hand raise lead call is made successfully' do
let(:response) { { success: true } }
it 'returns success: true' do
result = execute
expect(result.is_a?(ServiceResponse)).to be true
expect(result.success?).to be true
end
end
context 'error while creating hand raise lead call is made successful' do
let(:response) { { success: false, data: { errors: ['some error'] } } }
it 'returns success: false with errors' do
result = execute
expect(result.is_a?(ServiceResponse)).to be true
expect(result.success?).to be false
expect(result.message).to match_array(['some error'])
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