Skip to content

Commit ed982fc

Browse files
author
sofia
committed
Added specs
1 parent 803d2b1 commit ed982fc

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

spec/unit/intercom/request_spec.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
it 'raises an error when a html error page rendered' do
88
response = OpenStruct.new(:code => 500)
99
req = Intercom::Request.new('path/', 'GET')
10-
proc {req.parse_body('<html>somethjing</html>', response)}.must_raise(Intercom::ServerError)
10+
proc {req.parse_body('<html>something</html>', response)}.must_raise(Intercom::ServerError)
1111
end
1212

1313
it 'raises a RateLimitExceeded error when the response code is 429' do
1414
response = OpenStruct.new(:code => 429)
1515
req = Intercom::Request.new('path/', 'GET')
16-
proc {req.parse_body('<html>somethjing</html>', response)}.must_raise(Intercom::RateLimitExceeded)
16+
proc {req.parse_body('<html>something</html>', response)}.must_raise(Intercom::RateLimitExceeded)
1717
end
1818

1919
it 'parse_body raises an error if the decoded_body is "null"' do
@@ -23,8 +23,8 @@
2323
end
2424

2525
describe 'Intercom::Client' do
26-
let (:client) { Intercom::Client.new(token: 'foo', handle_rate_limit: true) }
27-
let (:uri) {"https://api.intercom.io/users"}
26+
let(:client) { Intercom::Client.new(token: 'foo', handle_rate_limit: true) }
27+
let(:uri) {"https://api.intercom.io/users"}
2828

2929
it 'should have handle_rate_limit set' do
3030
client.handle_rate_limit.must_equal(true)
@@ -63,6 +63,18 @@
6363

6464
end
6565

66+
67+
describe "Application errors on failure" do
68+
let(:uri) {"https://api.intercom.io/conversations/reply"}
69+
it 'should raise error' do
70+
# Use webmock to mock the HTTP request
71+
stub_request(:put, uri).\
72+
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)
73+
req = Intercom::Request.put(uri, "")
74+
expect { req.execute(target_base_url=uri, username: "ted", secret: "") }.must_raise(Intercom::ResourceNotUniqueError)
75+
end
76+
end
77+
6678
it 'parse_body returns nil if decoded_body is nil' do
6779
response = OpenStruct.new(:code => 500)
6880
req = Intercom::Request.new('path/', 'GET')

0 commit comments

Comments
 (0)