Commit b3e6d37d authored by Martin Wortschack's avatar Martin Wortschack

Merge branch 'fix-email-opt-in-trial' into 'master'

Update on SalesForce if a user opts to receive updates about GitLab

See merge request gitlab-org/gitlab!20082
parents b7e298f9 5ad0cf1c
......@@ -12,12 +12,6 @@ class TrialRegistrationsController < RegistrationsController
before_action :set_redirect_url, only: [:new]
before_action :skip_confirmation, only: [:create]
def create
super do |new_user|
new_user.system_hook_service.execute_hooks_for(new_user, :create) if new_user.persisted?
end
end
def new
end
......
......@@ -58,6 +58,7 @@ class TrialsController < ApplicationController
attrs[:skip_email_confirmation] = true
attrs[:gitlab_com_trial] = true
attrs[:provider] = 'gitlab'
attrs[:newsletter_segment] = current_user.email_opted_in
attrs
end
......
......@@ -33,9 +33,8 @@
- terms_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: terms_path }
= _("I accept the %{terms_link_start}Terms of Service and Privacy Policy%{terms_link_end}").html_safe % { terms_link_start: terms_link_start, terms_link_end: '</a>'.html_safe }
.form-group
= check_box_tag :email_opted_in, '1', false, data: { qa_selector: 'new_user_email_opted_in_checkbox' }
= label_tag :email_opted_in, for: 'email_opted_in', class: 'form-check-label' do
= _("I'd like to receive updates via email about GitLab")
= f.check_box :email_opted_in, data: { qa_selector: 'new_user_email_opted_in_checkbox' }
= f.label :email_opted_in, _("I'd like to receive updates via email about GitLab"), class: 'form-check-label'
%div
- if show_recaptcha_sign_up?
= recaptcha_tags
......
......@@ -101,22 +101,6 @@ describe TrialRegistrationsController do
expect(User.last.name).to eq("#{user_params[:first_name]} #{user_params[:last_name]}")
end
end
context 'system hook' do
it 'triggers user_create event on trial sign up' do
expect_any_instance_of(SystemHooksService).to receive(:execute_hooks_for).with(an_instance_of(User), :create)
post :create, params: { user: user_params }
end
it 'does not trigger user_create event when data is invalid' do
user_params[:email] = ''
expect_any_instance_of(SystemHooksService).not_to receive(:execute_hooks_for).with(an_instance_of(User), :create)
post :create, params: { user: user_params }
end
end
end
end
end
......@@ -44,14 +44,17 @@ describe TrialsController do
it_behaves_like 'an authenticated endpoint', :post, :create_lead
describe 'authenticated' do
let(:user) { create(:user) }
let(:user) { create(:user, email_opted_in: true) }
let(:create_lead_result) { nil }
before do
sign_in(user)
end
expect_any_instance_of(GitlabSubscriptions::CreateLeadService).to receive(:execute) do
{ success: create_lead_result }
context 'response url' do
before do
allow_next_instance_of(GitlabSubscriptions::CreateLeadService) do |lead_service|
expect(lead_service).to receive(:execute).and_return({ success: create_lead_result })
end
end
......@@ -75,6 +78,36 @@ describe TrialsController do
end
end
end
context 'request params to Lead Service' do
it 'sends appropriate request params' do
params = {
company_name: 'Gitlab',
company_size: '1-99',
phone_number: '1111111111',
number_of_users: "20",
country: 'IN'
}
extra_params = {
first_name: user.first_name,
last_name: user.last_name,
work_email: user.email,
uid: user.id,
skip_email_confirmation: true,
gitlab_com_trial: true,
provider: 'gitlab',
newsletter_segment: user.email_opted_in
}
expected_params = ActionController::Parameters.new(params).merge(extra_params).permit!
expect_next_instance_of(GitlabSubscriptions::CreateLeadService) do |lead_service|
expect(lead_service).to receive(:execute).with({ trial_user: expected_params }).and_return({ success: true })
end
post :create_lead, params: params
end
end
end
end
describe '#select' do
......
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