|
7 | 7 | it 'raises an error when a html error page rendered' do |
8 | 8 | response = OpenStruct.new(:code => 500) |
9 | 9 | 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) |
11 | 11 | end |
12 | 12 |
|
13 | 13 | it 'raises a RateLimitExceeded error when the response code is 429' do |
14 | 14 | response = OpenStruct.new(:code => 429) |
15 | 15 | 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) |
17 | 17 | end |
18 | 18 |
|
19 | 19 | it 'parse_body raises an error if the decoded_body is "null"' do |
|
23 | 23 | end |
24 | 24 |
|
25 | 25 | 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"} |
28 | 28 |
|
29 | 29 | it 'should have handle_rate_limit set' do |
30 | 30 | client.handle_rate_limit.must_equal(true) |
|
63 | 63 |
|
64 | 64 | end |
65 | 65 |
|
| 66 | + |
| 67 | + describe "Application errors on failure" do |
| 68 | + let(:uri) {"https://api.intercom.io/conversations/reply"} |
| 69 | + it 'should raise ResourceNotUniqueError error on resource_conflict code' 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 | + |
66 | 78 | it 'parse_body returns nil if decoded_body is nil' do |
67 | 79 | response = OpenStruct.new(:code => 500) |
68 | 80 | req = Intercom::Request.new('path/', 'GET') |
|
0 commit comments