Commit 5ad0cf1c authored by Aishwarya Subramanian's avatar Aishwarya Subramanian Committed by Martin Wortschack

Sending email opted param in Lead creation

Removed irrelevant spec, since the feature is removed
Using translation for opt in message
Changed condition to send event only if user opts
parent b7e298f9
......@@ -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,34 +44,67 @@ 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
end
context 'on success' do
let(:create_lead_result) { true }
context 'on success' do
let(:create_lead_result) { true }
it 'redirects user to Step 3' do
post :create_lead
it 'redirects user to Step 3' do
post :create_lead
expect(response).to redirect_to(select_trials_url)
expect(response).to redirect_to(select_trials_url)
end
end
end
context 'on failure' do
let(:create_lead_result) { false }
context 'on failure' do
let(:create_lead_result) { false }
it 'renders the :new template' do
post :create_lead
it 'renders the :new template' do
post :create_lead
expect(response).to render_template(:new)
end
end
end
expect(response).to render_template(:new)
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
......
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