Compare commits

...

1 Commits

Author SHA1 Message Date
Bilal
9012ec253d send first and last name to HubSpot when new account is created 2020-06-30 11:14:02 +02:00
4 changed files with 14 additions and 6 deletions

View File

@@ -17,7 +17,7 @@ class AccountsController < ApplicationController
if sign_in(user)
TrackAnalyticsJob.perform_later(user, user.primary_account, :track_guest_sign_up, user_agent: request.user_agent, user_ip: request.remote_ip)
SubmitHubspotFormJob.perform_later(user.email, account.name, i_m_interested_in: user.interested_product_name)
SubmitHubspotFormJob.perform_later(user.first_name, user.last_name, user.email, account.name, i_m_interested_in: user.interested_product_name)
redirect_to signed_in_root_path
else
redirect_to new_session_path, alert: t(".notice")

View File

@@ -1,12 +1,14 @@
class SubmitHubspotFormJob < ApplicationJob
queue_as :default
def perform(email, company_name, additional_params = {})
def perform(first_name, last_name, email, company_name, additional_params = {})
hubspot_form_guid = ENV["HUBSPOT_FORM_GUID"]
return unless hubspot_form_guid.present?
submission_params = {
email: email,
first_name: first_name,
last_name: last_name,
email: email,
company: company_name
}.merge(additional_params)

View File

@@ -57,6 +57,8 @@ RSpec.describe AccountsController, type: :controller do
expect {
post :create, params: params
}.to have_enqueued_job(SubmitHubspotFormJob).with(
"John",
"Doe",
"test_user+1@test.com",
"Test Dev account",
i_m_interested_in: "DirectME"

View File

@@ -11,10 +11,12 @@ RSpec.describe SubmitHubspotFormJob, type: :job do
allow(Hubspot::Form).to receive(:new).and_return(form)
allow(form).to receive(:submit).and_return(true)
SubmitHubspotFormJob.perform_now("email@test.com", "My Account")
SubmitHubspotFormJob.perform_now("John", "Doe", "email@test.com", "My Account")
expect(Hubspot::Form).to have_received(:new).with("guid" => "hubspot_form_guid")
expect(form).to have_received(:submit).with(
first_name: "John",
last_name: "Doe",
email: "email@test.com",
company: "My Account"
)
@@ -25,9 +27,11 @@ RSpec.describe SubmitHubspotFormJob, type: :job do
allow(Hubspot::Form).to receive(:new).and_return(form)
allow(form).to receive(:submit).and_return(true)
SubmitHubspotFormJob.perform_now("email@test.com", "My Account", additional_param_one: "Foo", additional_param_two: "Bar")
SubmitHubspotFormJob.perform_now("John", "Doe", "email@test.com", "My Account", additional_param_one: "Foo", additional_param_two: "Bar")
expect(form).to have_received(:submit).with(
first_name: "John",
last_name: "Doe",
email: "email@test.com",
company: "My Account",
additional_param_one: "Foo",
@@ -42,7 +46,7 @@ RSpec.describe SubmitHubspotFormJob, type: :job do
allow(Hubspot::Form).to receive(:new).and_return(form)
allow(form).to receive(:submit)
SubmitHubspotFormJob.perform_now("email@test.com", "My Account")
SubmitHubspotFormJob.perform_now("John", "Doe", "email@test.com", "My Account")
expect(form).not_to have_received(:submit)
end