Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
40c2cb59
Commit
40c2cb59
authored
Apr 13, 2022
by
minahilnichols
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move creation of trial or lead to a separate service
parent
48582035
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
160 additions
and
131 deletions
+160
-131
ee/app/assets/javascripts/registrations/company/new/index.js
ee/app/assets/javascripts/registrations/company/new/index.js
+1
-3
ee/app/assets/javascripts/registrations/components/company_form.vue
...ets/javascripts/registrations/components/company_form.vue
+5
-2
ee/app/controllers/registrations/company_controller.rb
ee/app/controllers/registrations/company_controller.rb
+28
-21
ee/app/helpers/ee/trial_helper.rb
ee/app/helpers/ee/trial_helper.rb
+1
-3
ee/app/services/gitlab_subscriptions/create_trial_or_lead_service.rb
...ices/gitlab_subscriptions/create_trial_or_lead_service.rb
+46
-0
ee/spec/controllers/registrations/company_controller_spec.rb
ee/spec/controllers/registrations/company_controller_spec.rb
+26
-41
ee/spec/features/trial_registrations/company_information_spec.rb
.../features/trial_registrations/company_information_spec.rb
+19
-27
ee/spec/frontend/registrations/company/new/components/company_form_spec.js
...registrations/company/new/components/company_form_spec.js
+0
-4
ee/spec/helpers/ee/trial_helper_spec.rb
ee/spec/helpers/ee/trial_helper_spec.rb
+1
-30
ee/spec/services/gitlab_subscriptions/create_trial_or_lead_service_spec.rb
...gitlab_subscriptions/create_trial_or_lead_service_spec.rb
+33
-0
No files found.
ee/app/assets/javascripts/registrations/company/new/index.js
View file @
40c2cb59
...
@@ -5,15 +5,13 @@ import RegistrationForm from 'ee/registrations/components/company_form.vue';
...
@@ -5,15 +5,13 @@ import RegistrationForm from 'ee/registrations/components/company_form.vue';
export
default
()
=>
{
export
default
()
=>
{
const
el
=
document
.
querySelector
(
'
#js-company-registration-form
'
);
const
el
=
document
.
querySelector
(
'
#js-company-registration-form
'
);
const
{
submitPath
,
trial
,
firstName
,
lastName
,
role
,
jtbd
,
comment
}
=
el
.
dataset
;
const
{
submitPath
,
trial
,
role
,
jtbd
,
comment
}
=
el
.
dataset
;
return
new
Vue
({
return
new
Vue
({
el
,
el
,
apolloProvider
,
apolloProvider
,
provide
:
{
provide
:
{
submitPath
,
submitPath
,
firstName
,
lastName
,
role
,
role
,
jtbd
,
jtbd
,
comment
,
comment
,
...
...
ee/app/assets/javascripts/registrations/components/company_form.vue
View file @
40c2cb59
...
@@ -28,7 +28,7 @@ export default {
...
@@ -28,7 +28,7 @@ export default {
CountryOrRegionSelector
,
CountryOrRegionSelector
,
RegistrationTrialToggle
,
RegistrationTrialToggle
,
},
},
inject
:
[
'
submitPath
'
,
'
firstName
'
,
'
lastName
'
,
'
role
'
,
'
jtbd
'
,
'
comment
'
],
inject
:
[
'
submitPath
'
,
'
role
'
,
'
jtbd
'
,
'
comment
'
],
props
:
{
props
:
{
trial
:
{
trial
:
{
type
:
Boolean
,
type
:
Boolean
,
...
@@ -84,8 +84,11 @@ export default {
...
@@ -84,8 +84,11 @@ export default {
</
script
>
</
script
>
<
template
>
<
template
>
<gl-form
:action=
"
createLead
Path"
method=
"post"
>
<gl-form
:action=
"
submit
Path"
method=
"post"
>
<input
:value=
"$options.csrf.token"
type=
"hidden"
name=
"authenticity_token"
/>
<input
:value=
"$options.csrf.token"
type=
"hidden"
name=
"authenticity_token"
/>
<input
:value=
"role"
type=
"hidden"
name=
"role"
data-testid=
"role"
/>
<input
:value=
"jtbd"
type=
"hidden"
name=
"jtbd"
data-testid=
"jtbd"
/>
<input
:value=
"comment"
type=
"hidden"
name=
"comment"
data-testid=
"comment"
/>
<gl-form-text
class=
"gl-font-base gl-text-gray-400 gl-pb-3"
>
{{
descriptionText
}}
</gl-form-text>
<gl-form-text
class=
"gl-font-base gl-text-gray-400 gl-pb-3"
>
{{
descriptionText
}}
</gl-form-text>
<div
class=
"gl-display-flex gl-flex-direction-column gl-sm-flex-direction-row gl-mt-5"
>
<div
class=
"gl-display-flex gl-flex-direction-column gl-sm-flex-direction-row gl-mt-5"
>
<gl-form-group
<gl-form-group
...
...
ee/app/controllers/registrations/company_controller.rb
View file @
40c2cb59
...
@@ -12,15 +12,16 @@ module Registrations
...
@@ -12,15 +12,16 @@ module Registrations
end
end
def
create
def
create
if
Gitlab
::
Utils
.
to_boolean
(
params
[
:trial
])
result
=
GitlabSubscriptions
::
CreateTrialOrLeadService
.
new
.
execute
(
result
=
GitlabSubscriptions
::
CreateLeadService
.
new
.
execute
({
trial_user:
company_params
})
user:
current_user
,
redirect_to
(
new_users_sign_up_groups_project_path
(
trial_onboarding_flow:
true
))
&&
return
if
result
[
:success
]
params:
permitted_params
)
if
result
[
:success
]
redirect_to
new_users_sign_up_groups_project_path
(
redirect_param
)
else
else
result
=
GitlabSubscriptions
::
CreateHandRaiseLeadService
.
new
.
execute
(
company_params
)
render
:new
redirect_to
(
new_users_sign_up_groups_project_path
(
skip_trial:
true
))
&&
return
if
result
[
:success
]
end
end
render
:new
end
end
private
private
...
@@ -31,22 +32,28 @@ module Registrations
...
@@ -31,22 +32,28 @@ module Registrations
redirect_to
new_trial_registration_path
,
alert:
I18n
.
t
(
'devise.failure.unauthenticated'
)
redirect_to
new_trial_registration_path
,
alert:
I18n
.
t
(
'devise.failure.unauthenticated'
)
end
end
def
company_params
def
permitted_params
params
.
permit
(
:first_name
,
:last_name
,
:company_name
,
:company_size
,
:phone_number
,
params
.
permit
(
:country
,
:state
,
:website_url
,
:glm_content
,
:glm_source
)
:company_name
,
.
merge
(
extra_params
)
:company_size
,
:phone_number
,
:country
,
:state
,
:website_url
,
# previous step(s) data
:role
,
:jtbd
,
:comment
,
:trial
)
end
end
def
extra_params
def
redirect_param
{
if
params
[
:trial
]
==
'true'
work_email:
current_user
.
email
,
{
trial_onboarding_flow:
true
}
uid:
current_user
.
id
,
else
provider:
'gitlab'
,
{
skip_trial:
true
}
setup_for_company:
current_user
.
setup_for_company
,
end
skip_email_confirmation:
true
,
gitlab_com_trial:
true
,
newsletter_segment:
current_user
.
email_opted_in
}
end
end
end
end
end
end
ee/app/helpers/ee/trial_helper.rb
View file @
40c2cb59
...
@@ -29,12 +29,10 @@ module EE
...
@@ -29,12 +29,10 @@ module EE
{
{
submit_path:
users_sign_up_company_path
(
glm_params
),
submit_path:
users_sign_up_company_path
(
glm_params
),
trial:
params
[
:trial
],
trial:
params
[
:trial
],
first_name:
current_user
.
first_name
,
last_name:
current_user
.
last_name
,
role:
params
[
:role
],
role:
params
[
:role
],
jtbd:
params
[
:jtbd
],
jtbd:
params
[
:jtbd
],
comment:
params
[
:comment
]
comment:
params
[
:comment
]
}
.
merge
(
params
.
slice
(
:first_name
,
:last_name
).
to_unsafe_h
.
symbolize_keys
)
}
end
end
def
should_ask_company_question?
def
should_ask_company_question?
...
...
ee/app/services/gitlab_subscriptions/create_trial_or_lead_service.rb
0 → 100644
View file @
40c2cb59
# frozen_string_literal: true
module
GitlabSubscriptions
class
CreateTrialOrLeadService
def
execute
(
user
:,
params
:)
params
=
params
.
merge
(
hardcoded_values
).
merge
(
user_values
(
user
))
response
=
if
Gitlab
::
Utils
.
to_boolean
(
params
[
:trial
])
client
.
generate_trial
(
trial_user:
params
)
else
client
.
generate_hand_raise_lead
(
params
)
end
if
response
[
:success
]
ServiceResponse
.
success
else
ServiceResponse
.
error
(
message:
response
.
dig
(
:data
,
:errors
))
end
end
private
def
hardcoded_values
{
provider:
'gitlab'
,
skip_email_confirmation:
true
,
gitlab_com_trial:
true
}
end
def
user_values
(
user
)
{
uid:
user
.
id
,
first_name:
user
.
first_name
,
last_name:
user
.
last_name
,
work_email:
user
.
email
,
setup_for_company:
user
.
setup_for_company
,
newsletter_segment:
user
.
email_opted_in
}
end
def
client
Gitlab
::
SubscriptionPortal
::
Client
end
end
end
ee/spec/controllers/registrations/company_controller_spec.rb
View file @
40c2cb59
...
@@ -49,67 +49,52 @@ RSpec.describe Registrations::CompanyController do
...
@@ -49,67 +49,52 @@ RSpec.describe Registrations::CompanyController do
it
{
is_expected
.
to
render_template
(
:new
)
}
it
{
is_expected
.
to
render_template
(
:new
)
}
end
end
end
end
describe
'#create'
do
describe
'#create'
do
using
RSpec
::
Parameterized
::
TableSyntax
using
RSpec
::
Parameterized
::
TableSyntax
context
'on success'
do
let
(
:params
)
do
{
company_name:
'GitLab'
,
company_size:
'1-99'
,
phone_number:
'+1 23 456-78-90'
,
country:
'US'
,
state:
'CA'
,
website_url:
'gitlab.com'
,
work_email:
user
.
email
,
uid:
user
.
id
,
provider:
'gitlab'
,
setup_for_company:
user
.
setup_for_company
,
skip_email_confirmation:
true
,
gitlab_com_trial:
true
,
newsletter_segment:
user
.
email_opted_in
}
end
let
(
:hand_raise_params
)
{
ActionController
::
Parameters
.
new
(
params
).
permit!
}
let
(
:lead_params
)
{
{
trial_user:
hand_raise_params
}
}
let
(
:trial_onboarding_flow
)
{
new_users_sign_up_groups_project_path
(
trial_onboarding_flow:
true
)
}
let
(
:params
)
do
let
(
:skip_trial
)
{
new_users_sign_up_groups_project_path
(
skip_trial:
true
)
}
{
company_name:
'GitLab'
,
company_size:
'1-99'
,
phone_number:
'+1 23 456-78-90'
,
country:
'US'
,
state:
'CA'
,
website_url:
'gitlab.com'
}
end
where
(
:trial
,
:expected_params
,
:post_service
,
:redirect_query
)
do
context
'on success'
do
true
|
ref
(
:lead_params
)
|
GitlabSubscriptions
::
CreateLeadService
|
ref
(
:trial_onboarding_flow
)
where
(
:trial
,
:redirect_query
)
do
false
|
ref
(
:hand_raise_params
)
|
GitlabSubscriptions
::
CreateHandRaiseLeadService
|
ref
(
:skip_trial
)
'true'
|
{
trial_onboarding_flow:
true
}
'false'
|
{
skip_trial:
true
}
end
end
with_them
do
with_them
do
it
'calls the correct service'
do
it
'creates trial or lead and redirects to the corect path'
do
expect_next_instance_of
(
post_service
)
do
|
service
|
expect_next_instance_of
(
GitlabSubscriptions
::
CreateTrialOrLeadService
)
do
|
service
|
expect
(
service
).
to
receive
(
:execute
).
with
(
expected_params
).
and_return
({
success:
true
})
expect
(
service
).
to
receive
(
:execute
).
with
({
user:
user
,
params:
ActionController
::
Parameters
.
new
(
params
.
merge
({
trial:
trial
})).
permit!
}).
and_return
({
success:
true
})
end
end
post_params
=
params
.
merge
(
trial:
trial
)
post
:create
,
params:
params
.
merge
({
trial:
trial
})
post
:create
,
params:
post_params
expect
(
response
).
to
have_gitlab_http_status
(
:redirect
)
expect
(
response
).
to
have_gitlab_http_status
(
:redirect
)
expect
(
response
).
to
redirect_to
(
redirect_query
)
expect
(
response
).
to
redirect_to
(
new_users_sign_up_groups_project_path
(
redirect_query
)
)
end
end
end
end
end
end
context
'on failure'
do
context
'on failure'
do
where
(
:trial
,
:post_service
)
do
where
(
trial:
%w[true false]
)
true
|
GitlabSubscriptions
::
CreateLeadService
false
|
GitlabSubscriptions
::
CreateHandRaiseLeadService
end
with_them
do
with_them
do
it
'
calls the correct service
'
do
it
'
renders company page :new
'
do
expect_next_instance_of
(
post_s
ervice
)
do
|
service
|
expect_next_instance_of
(
GitlabSubscriptions
::
CreateTrialOrLeadS
ervice
)
do
|
service
|
expect
(
service
).
to
receive
(
:execute
).
and_return
(
ServiceResponse
.
error
(
message:
'failed'
))
expect
(
service
).
to
receive
(
:execute
).
and_return
(
ServiceResponse
.
error
(
message:
'failed'
))
end
end
post
:create
,
params:
{
trial:
trial
}
post
:create
,
params:
params
.
merge
({
trial:
trial
})
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
render_template
(
:new
)
expect
(
response
).
to
render_template
(
:new
)
end
end
...
...
ee/spec/features/trial_registrations/company_information_spec.rb
View file @
40c2cb59
...
@@ -18,33 +18,22 @@ RSpec.describe 'Company Information', :js do
...
@@ -18,33 +18,22 @@ RSpec.describe 'Company Information', :js do
end
end
context
'send company information to create lead'
do
context
'send company information to create lead'
do
it
'with all required fields'
do
using
RSpec
::
Parameterized
::
TableSyntax
trial_user_params
=
{
let
(
:params
)
do
"company_name"
=>
'GitLab'
,
{
"company_size"
=>
'1 - 99'
.
delete
(
' '
),
company_name:
'GitLab'
,
"phone_number"
=>
'+1 23 456-78-90'
,
company_size:
'1-99'
,
"country"
=>
'US'
,
phone_number:
'+1 23 456-78-90'
,
"state"
=>
'CA'
,
country:
'US'
,
"work_email"
=>
user
.
email
,
state:
'CA'
,
"uid"
=>
user
.
id
,
website_url:
'gitlab.com'
,
"setup_for_company"
=>
user
.
setup_for_company
,
role:
''
,
"skip_email_confirmation"
=>
true
,
jtbd:
''
,
"gitlab_com_trial"
=>
true
,
comment:
''
"provider"
=>
"gitlab"
,
"newsletter_segment"
=>
user
.
email_opted_in
,
"website_url"
=>
'gitlab.com'
}
}
end
end
let
(
:params
)
{
ActionController
::
Parameters
.
new
(
trial_user_params
).
permit!
}
where
(
trial:
%w[true false]
)
let
(
:trial_params
)
{
{
trial_user:
params
}
}
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'
with_them
do
with_them
do
it
'proceeds to next step'
do
it
'proceeds to next step'
do
...
@@ -56,10 +45,13 @@ RSpec.describe 'Company Information', :js do
...
@@ -56,10 +45,13 @@ RSpec.describe 'Company Information', :js do
fill_in
'phone_number'
,
with:
'+1 23 456-78-90'
fill_in
'phone_number'
,
with:
'+1 23 456-78-90'
# defaults to trial off, click to turn on
# defaults to trial off, click to turn on
click_button
class:
'gl-toggle'
if
trial
click_button
class:
'gl-toggle'
if
Gitlab
::
Utils
.
to_boolean
(
trial
)
expect_next_instance_of
(
post_service
)
do
|
service
|
expect_next_instance_of
(
GitlabSubscriptions
::
CreateTrialOrLeadService
)
do
|
service
|
expect
(
service
).
to
receive
(
:execute
).
with
(
post_params
).
and_return
({
success:
true
})
expect
(
service
).
to
receive
(
:execute
).
with
({
user:
user
,
params:
ActionController
::
Parameters
.
new
(
params
.
merge
({
trial:
trial
})).
permit!
}).
and_return
({
success:
true
})
end
end
click_button
'Continue'
click_button
'Continue'
...
...
ee/spec/frontend/registrations/company/new/components/company_form_spec.js
View file @
40c2cb59
...
@@ -18,8 +18,6 @@ describe('RegistrationForm', () => {
...
@@ -18,8 +18,6 @@ describe('RegistrationForm', () => {
localVue
,
localVue
,
provide
:
{
provide
:
{
submitPath
:
SUBMIT_PATH
,
submitPath
:
SUBMIT_PATH
,
firstName
:
'
Joe
'
,
lastName
:
'
Doe
'
,
role
:
'
Software Engineer
'
,
role
:
'
Software Engineer
'
,
jtbd
:
'
Jobs to be done
'
,
jtbd
:
'
Jobs to be done
'
,
comment
:
'
A comment
'
,
comment
:
'
A comment
'
,
...
@@ -76,8 +74,6 @@ describe('RegistrationForm', () => {
...
@@ -76,8 +74,6 @@ describe('RegistrationForm', () => {
it
.
each
`
it
.
each
`
testid | value
testid | value
${
'
first_name
'
}
|
${
'
Joe
'
}
${
'
last_name
'
}
|
${
'
Doe
'
}
${
'
role
'
}
|
${
'
Software Engineer
'
}
${
'
role
'
}
|
${
'
Software Engineer
'
}
${
'
jtbd
'
}
|
${
'
Jobs to be done
'
}
${
'
jtbd
'
}
|
${
'
Jobs to be done
'
}
${
'
comment
'
}
|
${
'
A comment
'
}
${
'
comment
'
}
|
${
'
A comment
'
}
...
...
ee/spec/helpers/ee/trial_helper_spec.rb
View file @
40c2cb59
...
@@ -61,44 +61,15 @@ RSpec.describe EE::TrialHelper do
...
@@ -61,44 +61,15 @@ RSpec.describe EE::TrialHelper do
double
(
'User'
,
first_name:
'_first_name_'
,
last_name:
'_last_name_'
)
double
(
'User'
,
first_name:
'_first_name_'
,
last_name:
'_last_name_'
)
end
end
let
(
:extra_params
)
do
{
first_name:
'_params_first_name_'
,
last_name:
'_params_last_name_'
}
end
let
(
:params
)
do
ActionController
::
Parameters
.
new
(
extra_params
.
merge
(
glm_source:
'_glm_source_'
,
glm_content:
'_glm_content_'
))
end
before
do
before
do
allow
(
helper
).
to
receive
(
:params
).
and_return
(
params
)
allow
(
helper
).
to
receive
(
:current_user
).
and_return
(
user
)
allow
(
helper
).
to
receive
(
:current_user
).
and_return
(
user
)
end
end
it
'provides expected form data'
do
it
'provides expected form data'
do
keys
=
extra_params
.
keys
+
[
:submit_path
,
:trial
,
:role
,
:jtbd
,
:comment
]
keys
=
[
:submit_path
,
:trial
,
:role
,
:jtbd
,
:comment
]
expect
(
helper
.
create_company_form_data
.
keys
.
map
(
&
:to_sym
)).
to
match_array
(
keys
)
expect
(
helper
.
create_company_form_data
.
keys
.
map
(
&
:to_sym
)).
to
match_array
(
keys
)
end
end
it
'allows overriding data with params'
do
expect
(
helper
.
create_company_form_data
).
to
match
(
a_hash_including
(
extra_params
))
end
context
'when params are empty'
do
let
(
:extra_params
)
{
{}
}
it
'uses the values from current user'
do
current_user_attributes
=
{
first_name:
user
.
first_name
,
last_name:
user
.
last_name
}
expect
(
helper
.
create_company_form_data
).
to
match
(
a_hash_including
(
current_user_attributes
))
end
end
end
end
describe
'#should_ask_company_question?'
do
describe
'#should_ask_company_question?'
do
...
...
ee/spec/services/gitlab_subscriptions/create_trial_or_lead_service_spec.rb
0 → 100644
View file @
40c2cb59
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
GitlabSubscriptions
::
CreateTrialOrLeadService
do
let
(
:user
)
{
build
(
:user
)
}
describe
'#execute'
do
using
RSpec
::
Parameterized
::
TableSyntax
where
(
:trial
,
:service
)
do
'true'
|
:generate_trial
'false'
|
:generate_hand_raise_lead
end
with_them
do
it
'successfully creates a trial or lead'
do
allow
(
Gitlab
::
SubscriptionPortal
::
Client
).
to
receive
(
service
).
and_return
({
success:
true
})
result
=
described_class
.
new
.
execute
(
**
{
user:
user
,
params:
{
trial:
trial
}
})
expect
(
result
.
is_a?
(
ServiceResponse
)).
to
be
true
expect
(
result
.
success?
).
to
be
true
end
it
'error while creating trial or lead'
do
allow
(
Gitlab
::
SubscriptionPortal
::
Client
).
to
receive
(
service
).
and_return
({
success:
false
})
result
=
described_class
.
new
.
execute
(
**
{
user:
user
,
params:
{
trial:
trial
}
})
expect
(
result
.
is_a?
(
ServiceResponse
)).
to
be
true
expect
(
result
.
success?
).
to
be
false
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment