Commit a6ac52d3 authored by minahilnichols's avatar minahilnichols

Add create logic to company controller instead of trials

parent 5f0b3edf
...@@ -66,7 +66,7 @@ Rails.application.routes.draw do ...@@ -66,7 +66,7 @@ Rails.application.routes.draw do
end end
Gitlab.ee do Gitlab.ee do
resources :company, only: [:new] resource :company, only: [:new, :create], controller: 'company'
resources :groups, only: [:new, :create] resources :groups, only: [:new, :create]
resources :projects, only: [:new, :create] resources :projects, only: [:new, :create]
resources :groups_projects, only: [:new, :create] do resources :groups_projects, only: [:new, :create] do
......
...@@ -33,7 +33,7 @@ export default { ...@@ -33,7 +33,7 @@ export default {
trial: { trial: {
type: Boolean, type: Boolean,
required: false, required: false,
default: true, default: false,
}, },
}, },
data() { data() {
......
...@@ -5,9 +5,42 @@ module Registrations ...@@ -5,9 +5,42 @@ module Registrations
layout 'minimal' layout 'minimal'
before_action :check_if_gl_com_or_dev before_action :check_if_gl_com_or_dev
before_action :authenticate_user!
feature_category :onboarding feature_category :onboarding
def new def new
end end
def create
if Gitlab::Utils.to_boolean(params[:trial])
result = GitlabSubscriptions::CreateLeadService.new.execute({ trial_user: company_params })
redirect_to(new_users_sign_up_groups_project_path(trial_onboarding_flow: true)) && return if result[:success]
else
result = GitlabSubscriptions::CreateHandRaiseLeadService.new.execute(company_params)
redirect_to(new_users_sign_up_groups_project_path(skip_trial: true)) && return if result[:success]
end
render :new
end
private
def company_params
params.permit(:first_name, :last_name, :company_name, :company_size, :phone_number, :country,
:state, :website_url, :namespace_id, :glm_content, :glm_source)
.merge(extra_params)
end
def extra_params
{
work_email: current_user.email,
uid: current_user.id,
provider: 'gitlab',
setup_for_company: current_user.setup_for_company,
skip_email_confirmation: true,
gitlab_com_trial: true,
newsletter_segment: current_user.email_opted_in
}
end
end end
end end
...@@ -27,16 +27,12 @@ class TrialsController < ApplicationController ...@@ -27,16 +27,12 @@ class TrialsController < ApplicationController
end end
def create_lead def create_lead
if params.has_key?(:trial)
return create_hand_raise_lead unless Gitlab::Utils.to_boolean(params[:trial])
end
url_params = { glm_source: params[:glm_source], glm_content: params[:glm_content] } url_params = { glm_source: params[:glm_source], glm_content: params[:glm_content] }
@result = GitlabSubscriptions::CreateLeadService.new.execute({ trial_user: company_params }) @result = GitlabSubscriptions::CreateLeadService.new.execute({ trial_user: company_params })
render(:new) && return unless @result[:success] render(:new) && return unless @result[:success]
if params[:onboarding] == 'true' || params[:trial] == 'true' if params[:onboarding]
redirect_to(new_users_sign_up_groups_project_path(url_params.merge(trial_onboarding_flow: true))) redirect_to(new_users_sign_up_groups_project_path(url_params.merge(trial_onboarding_flow: true)))
elsif @namespace = helpers.only_trialable_group_namespace elsif @namespace = helpers.only_trialable_group_namespace
params[:namespace_id] = @namespace.id params[:namespace_id] = @namespace.id
...@@ -50,7 +46,6 @@ class TrialsController < ApplicationController ...@@ -50,7 +46,6 @@ class TrialsController < ApplicationController
result = GitlabSubscriptions::CreateHandRaiseLeadService.new.execute(hand_raise_lead_params) result = GitlabSubscriptions::CreateHandRaiseLeadService.new.execute(hand_raise_lead_params)
if result.success? if result.success?
redirect_to new_users_sign_up_groups_project_path(skip_trial: true) if params.has_key?(:trial)
head 200 head 200
else else
render_403 render_403
...@@ -137,7 +132,7 @@ class TrialsController < ApplicationController ...@@ -137,7 +132,7 @@ class TrialsController < ApplicationController
def company_params def company_params
params.permit(:company_name, :company_size, :first_name, :last_name, :phone_number, params.permit(:company_name, :company_size, :first_name, :last_name, :phone_number,
:country, :state, :website_url, :glm_content, :glm_source).merge(extra_params) :country, :state, :glm_content, :glm_source).merge(extra_params)
end end
def extra_params def extra_params
......
...@@ -27,7 +27,7 @@ module EE ...@@ -27,7 +27,7 @@ module EE
def create_company_form_data def create_company_form_data
{ {
submit_path: create_lead_trials_path(glm_params), submit_path: users_sign_up_company_path(glm_params),
trial: params[:trial], trial: params[:trial],
first_name: current_user.first_name, first_name: current_user.first_name,
last_name: current_user.last_name, last_name: current_user.last_name,
......
...@@ -216,24 +216,6 @@ RSpec.describe TrialsController, :saas do ...@@ -216,24 +216,6 @@ RSpec.describe TrialsController, :saas do
post_create_lead post_create_lead
end end
end end
context 'when posting new company information' do
where(trial: [true, false])
with_them do
let(:post_params) { { trial: trial } }
let(:post_service) { trial ? GitlabSubscriptions::CreateLeadService : GitlabSubscriptions::CreateHandRaiseLeadService }
it 'calls the correct service' do
expect_next_instance_of(post_service) do |service|
expect(service).to receive(:execute).and_return(ServiceResponse.success)
end
post :create_lead, params: post_params
expect(response).to have_gitlab_http_status(:ok)
end
end
end
end end
describe '#create_hand_raise_lead' do describe '#create_hand_raise_lead' do
......
...@@ -34,10 +34,10 @@ RSpec.describe 'Company Information', :js do ...@@ -34,10 +34,10 @@ RSpec.describe 'Company Information', :js do
"newsletter_segment" => user.email_opted_in, "newsletter_segment" => user.email_opted_in,
"website_url" => 'gitlab.com' "website_url" => 'gitlab.com'
} }
end
lead_params = { let(:params) { ActionController::Parameters.new(trial_user_params).permit! }
trial_user: ActionController::Parameters.new(trial_user_params).permit! let(:trial_params) { { trial_user: params } }
}
fill_in 'company_name', with: 'GitLab' fill_in 'company_name', with: 'GitLab'
select '1 - 99', from: 'company_size' select '1 - 99', from: 'company_size'
...@@ -46,11 +46,25 @@ RSpec.describe 'Company Information', :js do ...@@ -46,11 +46,25 @@ RSpec.describe 'Company Information', :js do
fill_in 'website_url', with: 'gitlab.com' fill_in 'website_url', with: 'gitlab.com'
fill_in 'phone_number', with: '+1 23 456-78-90' fill_in 'phone_number', with: '+1 23 456-78-90'
expect_next_instance_of(GitlabSubscriptions::CreateLeadService) do |service| with_them do
expect(service).to receive(:execute).with(lead_params).and_return({ success: true }) it 'proceeds to next step' do
end fill_in 'company_name', with: 'GitLab'
select '1 - 99', from: 'company_size'
select 'United States of America', from: 'country'
select 'California', from: 'state'
fill_in 'website_url', with: 'gitlab.com'
fill_in 'phone_number', with: '+1 23 456-78-90'
click_button 'Continue' # defaults to trial off, click to turn on
click_button class: 'gl-toggle' if trial
expect_next_instance_of(post_service) do |service|
expect(service).to receive(:execute).with(post_params).and_return({ success: true })
end
click_button 'Continue'
expect(page).to have_current_path(new_users_sign_up_groups_project_path, ignore_query: true)
end
end 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