-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathresponse_spec.rb
27 lines (20 loc) · 945 Bytes
/
response_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require 'spec_helper'
describe SparkPostRails::DeliveryMethod do
before(:each) do
@delivery_method = SparkPostRails::DeliveryMethod.new
end
context "API Response Handling" do
it "returns result data on success" do
test_email = Mailer.test_email
response = @delivery_method.deliver!(test_email)
expect(response).to eq({"total_rejected_recipients"=>0, "total_accepted_recipients"=>1, "id"=>"00000000000000000"})
end
it "raises exception on error" do
uri = URI.join(SparkPostRails.configuration.api_endpoint, 'v1/transmissions')
stub_request(:any, uri.to_s).
to_return(body: "{\"errors\":[{\"message\":\"required field is missing\",\"description\":\"recipients or list_id required\",\"code\":\"1400\"}]}", status: 403)
test_email = Mailer.test_email
expect {@delivery_method.deliver!(test_email)}.to raise_exception(SparkPostRails::DeliveryException)
end
end
end