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
end
Gitlab.ee do
resources :company, only: [:new]
resource :company, only: [:new, :create], controller: 'company'
resources :groups, only: [:new, :create]
resources :projects, only: [:new, :create]
resources :groups_projects, only: [:new, :create] do
......
......@@ -33,7 +33,7 @@ export default {
trial: {
type: Boolean,
required: false,
default: true,
default: false,
},
},
data() {
......
......@@ -5,9 +5,42 @@ module Registrations
layout 'minimal'
before_action :check_if_gl_com_or_dev
before_action :authenticate_user!
feature_category :onboarding
def new
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
......@@ -27,16 +27,12 @@ class TrialsController < ApplicationController
end
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] }
@result = GitlabSubscriptions::CreateLeadService.new.execute({ trial_user: company_params })
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)))
elsif @namespace = helpers.only_trialable_group_namespace
params[:namespace_id] = @namespace.id
......@@ -50,7 +46,6 @@ class TrialsController < ApplicationController
result = GitlabSubscriptions::CreateHandRaiseLeadService.new.execute(hand_raise_lead_params)
if result.success?
redirect_to new_users_sign_up_groups_project_path(skip_trial: true) if params.has_key?(:trial)
head 200
else
render_403
......@@ -137,7 +132,7 @@ class TrialsController < ApplicationController
def company_params
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
def extra_params
......
......@@ -27,7 +27,7 @@ module EE
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],
first_name: current_user.first_name,
last_name: current_user.last_name,
......
......@@ -216,24 +216,6 @@ RSpec.describe TrialsController, :saas do
post_create_lead
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
describe '#create_hand_raise_lead' do
......
......@@ -34,10 +34,10 @@ RSpec.describe 'Company Information', :js do
"newsletter_segment" => user.email_opted_in,
"website_url" => 'gitlab.com'
}
end
lead_params = {
trial_user: ActionController::Parameters.new(trial_user_params).permit!
}
let(:params) { ActionController::Parameters.new(trial_user_params).permit! }
let(:trial_params) { { trial_user: params } }
fill_in 'company_name', with: 'GitLab'
select '1 - 99', from: 'company_size'
......@@ -46,11 +46,25 @@ RSpec.describe 'Company Information', :js do
fill_in 'website_url', with: 'gitlab.com'
fill_in 'phone_number', with: '+1 23 456-78-90'
expect_next_instance_of(GitlabSubscriptions::CreateLeadService) do |service|
expect(service).to receive(:execute).with(lead_params).and_return({ success: true })
with_them do
it 'proceeds to next step' do
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'
# 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
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