spec/unit/intercom/request_spec.rb in intercom-3.5.22 vs spec/unit/intercom/request_spec.rb in intercom-3.5.23
- old
+ new
@@ -5,28 +5,28 @@
describe 'Intercom::Request' do
it 'raises an error when a html error page rendered' do
response = OpenStruct.new(:code => 500)
req = Intercom::Request.new('path/', 'GET')
- proc {req.parse_body('<html>somethjing</html>', response)}.must_raise(Intercom::ServerError)
+ proc {req.parse_body('<html>something</html>', response)}.must_raise(Intercom::ServerError)
end
it 'raises a RateLimitExceeded error when the response code is 429' do
response = OpenStruct.new(:code => 429)
req = Intercom::Request.new('path/', 'GET')
- proc {req.parse_body('<html>somethjing</html>', response)}.must_raise(Intercom::RateLimitExceeded)
+ proc {req.parse_body('<html>something</html>', response)}.must_raise(Intercom::RateLimitExceeded)
end
it 'parse_body raises an error if the decoded_body is "null"' do
response = OpenStruct.new(:code => 500)
req = Intercom::Request.new('path/', 'GET')
proc { req.parse_body('null', response)}.must_raise(Intercom::ServerError)
end
describe 'Intercom::Client' do
- let (:client) { Intercom::Client.new(token: 'foo', handle_rate_limit: true) }
- let (:uri) {"https://api.intercom.io/users"}
+ let(:client) { Intercom::Client.new(token: 'foo', handle_rate_limit: true) }
+ let(:uri) {"https://api.intercom.io/users"}
it 'should have handle_rate_limit set' do
client.handle_rate_limit.must_equal(true)
end
@@ -59,9 +59,21 @@
req.handle_rate_limit=true
req.expects(:sleep).with(any_parameters)
req.execute(target_base_url=uri, username: "ted", secret: "")
end
+ end
+
+
+ describe "Application errors on failure" do
+ let(:uri) {"https://api.intercom.io/conversations/reply"}
+ it 'should raise ResourceNotUniqueError error on resource_conflict code' do
+ # Use webmock to mock the HTTP request
+ stub_request(:put, uri).\
+ to_return(status: [409, "Resource Already Exists"], headers: { 'X-RateLimit-Reset' => Time.now.utc + 10 }, body: {type: "error.list", errors: [ code: "resource_conflict" ]}.to_json)
+ req = Intercom::Request.put(uri, "")
+ expect { req.execute(target_base_url=uri, username: "ted", secret: "") }.must_raise(Intercom::ResourceNotUniqueError)
+ end
end
it 'parse_body returns nil if decoded_body is nil' do
response = OpenStruct.new(:code => 500)
req = Intercom::Request.new('path/', 'GET')