Start setting up WebMock to stub responses

This commit is contained in:
CactusPuppy 2021-03-14 13:25:36 -07:00
parent cc57973103
commit d99487b19c
No known key found for this signature in database
GPG key ID: 4B33B0A3E15E2C82

View file

@ -8,9 +8,38 @@ describe External::MailblusterHelper, type: :helper do
describe 'create_lead' do
it 'makes a post request to Mailbluster\'s API' do
stub_request(:post, "http://api.mailbluster.com/api/leads")
.to_return(body: '{
"message": "Lead created",
"lead": {
"id": 329395,
"firstName": "Richard",
"lastName": "Hendricks",
"fullName": "Richard Hendricks",
"email": "richard@example.com",
"timezone": "America/Los_Angeles",
"ipAddress": "162.213.1.246",
"subscribed": false,
"meta": {
"company": "Pied Piper",
"role": "CEO",
"continent": "North America",
"country": "United States",
"city": "San Jose",
"latitude": 37.3008,
"longitude": -121.9777,
"source": "Lead API"
},
"tags": [
"iPhone User",
"Startup"
],
"createdAt": "2016-07-23T08:03:18.954Z",
"updatedAt": "2016-07-23T08:03:18.954Z"
}
}', status: 200)
create_lead(user)
expect(WebMock).to have_requested(:post, "api.mailbluster.com/api/leads").
with { |req| req.body == "abc" }
expect(WebMock).to have_requested(:post, "api.mailbluster.com/api/leads")
end
end
end