Commit 5faa7881 authored by minahilnichols's avatar minahilnichols

Add hidden params to form

parent 3c16576a
......@@ -5,12 +5,19 @@ import RegistrationForm from 'ee/registrations/components/company_form.vue';
export default () => {
const el = document.querySelector('#js-company-registration-form');
const { trial, createLeadPath } = el.dataset;
const { submitPath, trial, firstName, lastName, role, jtbd, comment } = el.dataset;
return new Vue({
el,
apolloProvider,
provide: { createLeadPath },
provide: {
submitPath,
firstName,
lastName,
role,
jtbd,
comment,
},
render(createElement) {
return createElement(RegistrationForm, {
props: { trial },
......
......@@ -28,7 +28,7 @@ export default {
CountryOrRegionSelector,
RegistrationTrialToggle,
},
inject: ['createLeadPath'],
inject: ['submitPath', 'firstName', 'lastName', 'role', 'jtbd', 'comment'],
props: {
trial: {
type: Boolean,
......
......@@ -27,6 +27,8 @@ class TrialsController < ApplicationController
end
def create_lead
return create_hand_raise_lead unless Gitlab::Utils.to_boolean(params[:trial])
url_params = { glm_source: params[:glm_source], glm_content: params[:glm_content] }
@result = GitlabSubscriptions::CreateLeadService.new.execute({ trial_user: company_params })
......
......@@ -25,6 +25,18 @@ module EE
}.merge(params.slice(:first_name, :last_name, :company_name, :company_size, :phone_number, :country, :state).to_unsafe_h.symbolize_keys)
end
def create_company_form_data
{
submit_path: create_lead_trials_path(glm_params),
trial: params[:trial],
first_name: current_user.first_name,
last_name: current_user.last_name,
role: params[:role],
jtbd: params[:jtbd],
comment: params[:comment]
}.merge(params.slice(:first_name, :last_name).to_unsafe_h.symbolize_keys)
end
def should_ask_company_question?
TRIAL_ONBOARDING_SOURCE_URLS.exclude?(glm_params[:glm_source])
end
......
......@@ -216,6 +216,24 @@ 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
......
......@@ -17,7 +17,12 @@ describe('RegistrationForm', () => {
return mountFunction(RegistrationForm, {
localVue,
provide: {
createLeadPath: SUBMIT_PATH,
submitPath: SUBMIT_PATH,
firstName: 'Joe',
lastName: 'Doe',
role: 'Software Engineer',
jtbd: 'Jobs to be done',
comment: 'A comment',
},
propsData: { trial: true },
});
......@@ -68,6 +73,17 @@ describe('RegistrationForm', () => {
`('has the correct form input in the form content', ({ testid }) => {
expect(findFormInput(testid).exists()).toBe(true);
});
it.each`
testid | value
${'first_name'} | ${'Joe'}
${'last_name'} | ${'Doe'}
${'role'} | ${'Software Engineer'}
${'jtbd'} | ${'Jobs to be done'}
${'comment'} | ${'A comment'}
`('has the hidden injected value for $testid', ({ testid, value }) => {
expect(findFormInput(testid).attributes('value')).toBe(value);
});
});
describe('submitting', () => {
......
......@@ -56,6 +56,51 @@ RSpec.describe EE::TrialHelper do
end
end
describe '#create_company_form_data' do
let(:user) do
double('User', first_name: '_first_name_', last_name: '_last_name_')
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
allow(helper).to receive(:params).and_return(params)
allow(helper).to receive(:current_user).and_return(user)
end
it 'provides expected form data' do
keys = extra_params.keys + [:submit_path, :trial, :role, :jtbd, :comment]
expect(helper.create_company_form_data.keys.map(&:to_sym)).to match_array(keys)
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
describe '#should_ask_company_question?' do
before do
allow(helper).to receive(:glm_params).and_return(glm_source ? { glm_source: glm_source } : {})
......
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