Files
old-holivud2/spec/jobs/submit_hubspot_form_job_spec.rb

56 lines
2.0 KiB
Ruby
Raw Normal View History

2020-05-31 22:38:19 +02:00
require 'rails_helper'
RSpec.describe SubmitHubspotFormJob, type: :job do
describe '#perform_now' do
before do
ENV["HUBSPOT_FORM_GUID"] = "hubspot_form_guid"
end
it 'submits to the Hubspot API with the right params' do
form = double(:form)
allow(Hubspot::Form).to receive(:new).and_return(form)
allow(form).to receive(:submit).and_return(true)
2020-07-15 11:57:21 +02:00
SubmitHubspotFormJob.perform_now(first_name: "John", last_name: "Doe", email: "email@test.com", company: "My Account", form_guid: ENV["HUBSPOT_FORM_GUID"])
2020-05-31 22:38:19 +02:00
expect(Hubspot::Form).to have_received(:new).with("guid" => "hubspot_form_guid")
expect(form).to have_received(:submit).with(
2020-07-01 06:39:02 +02:00
first_name: "John",
last_name: "Doe",
2020-05-31 22:38:19 +02:00
email: "email@test.com",
company: "My Account"
)
end
it 'allows additional params to be submitted' do
form = double(:form)
allow(Hubspot::Form).to receive(:new).and_return(form)
allow(form).to receive(:submit).and_return(true)
2020-07-15 11:57:21 +02:00
SubmitHubspotFormJob.perform_now(first_name: "John", last_name: "Doe", email: "email@test.com", company: "My Account", form_guid: ENV["HUBSPOT_FORM_GUID"], additional_param_one: "Foo", additional_param_two: "Bar")
2020-05-31 22:38:19 +02:00
expect(form).to have_received(:submit).with(
2020-07-01 06:39:02 +02:00
first_name: "John",
last_name: "Doe",
2020-05-31 22:38:19 +02:00
email: "email@test.com",
company: "My Account",
additional_param_one: "Foo",
2020-07-15 11:57:21 +02:00
additional_param_two: "Bar"
2020-05-31 22:38:19 +02:00
)
end
context 'when HUBSPOT_FORM_GUID is not available' do
it 'does not submit to the API' do
ENV["HUBSPOT_FORM_GUID"] = nil
form = double(:form)
allow(Hubspot::Form).to receive(:new).and_return(form)
allow(form).to receive(:submit)
2020-07-15 11:57:21 +02:00
SubmitHubspotFormJob.perform_now(first_name: "John", last_name: "Doe", email: "email@test.com", company: "My Account", form_guid: ENV["HUBSPOT_FORM_GUID"])
2020-05-31 22:38:19 +02:00
expect(form).not_to have_received(:submit)
end
end
end
end