2021-03-13 15:04:57 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
require 'webmock/rspec'
|
|
|
|
|
|
2021-03-16 15:22:15 -07:00
|
|
|
describe External::MailblusterHelper, type: :helper do
|
2021-03-13 15:04:57 -08:00
|
|
|
let!(:user) { create(:user) }
|
|
|
|
|
|
|
|
|
|
describe 'create_lead' do
|
2021-03-16 15:22:15 -07:00
|
|
|
it 'makes a post request to Mailbluster\'s API and gets the correct response' do
|
2021-03-16 14:28:39 -07:00
|
|
|
response_body = "{
|
|
|
|
|
\"message\": \"Lead created\",
|
|
|
|
|
\"lead\": {
|
|
|
|
|
\"id\": 329395,
|
|
|
|
|
\"firstName\": \"#{user.name}\",
|
|
|
|
|
\"lastName\": \"\",
|
|
|
|
|
\"fullName\": \"#{user.name}\",
|
|
|
|
|
\"email\": \"#{user.email}\",
|
|
|
|
|
\"subscribed\": true,
|
|
|
|
|
\"tags\": [
|
|
|
|
|
\"snapcon\"
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
}"
|
2021-03-16 15:22:15 -07:00
|
|
|
stub_request(:post, 'https://api.mailbluster.com/api/leads')
|
2021-03-16 14:28:39 -07:00
|
|
|
.to_return(body: response_body, status: 200)
|
|
|
|
|
response = create_lead(user)
|
2021-03-16 15:22:15 -07:00
|
|
|
|
|
|
|
|
expect(WebMock).to have_requested(:post, 'api.mailbluster.com/api/leads').with(body: {
|
|
|
|
|
'email': user.email,
|
|
|
|
|
'firstName': user.name,
|
2021-03-14 13:54:44 -07:00
|
|
|
'overrideExisting': true,
|
2021-03-16 15:22:15 -07:00
|
|
|
'subscribed': true,
|
|
|
|
|
'tags': ['snapcon']
|
2021-03-14 13:54:44 -07:00
|
|
|
}.to_json)
|
2021-03-16 14:28:39 -07:00
|
|
|
expect(response).to eq(response_body)
|
2021-03-13 15:04:57 -08:00
|
|
|
end
|
|
|
|
|
end
|
2021-03-13 15:22:19 -08:00
|
|
|
end
|