@@ -51,6 +51,43 @@ def test_send_request_delete_with_success_response
5151 assert_nil ( response_body )
5252 end
5353
54+ def test_send_request_does_not_raise_when_body_text_contains_error_substring
55+ payload = {
56+ 'data' => [ {
57+ 'name' => 'dia_push' ,
58+ 'components' => [ { 'type' => 'BODY' , 'text' => 'si tu cupón te da algún error, avísanos' } ]
59+ } ]
60+ }
61+ stub_test_request ( :get , response_body : payload )
62+
63+ response_body = @client . send_request ( endpoint : 'test' , http_method : 'get' )
64+
65+ assert_equal ( payload , response_body )
66+ end
67+
68+ def test_send_request_raises_when_response_has_error_key
69+ error_body = { 'error' => { 'message' => 'Invalid OAuth token' , 'code' => 190 } }
70+ stub_test_request ( :get , response_status : 400 , response_body : error_body )
71+
72+ error = assert_raises ( Api ::Responses ::HttpResponseError ) do
73+ @client . send_request ( endpoint : 'test' , http_method : 'get' )
74+ end
75+
76+ assert_equal ( 400 , error . http_status )
77+ assert_equal ( error_body , error . body )
78+ end
79+
80+ def test_send_request_raises_for_5xx_responses
81+ error_body = { 'error' => { 'message' => 'Internal server error' } }
82+ stub_test_request ( :get , response_status : 502 , response_body : error_body )
83+
84+ error = assert_raises ( Api ::Responses ::HttpResponseError ) do
85+ @client . send_request ( endpoint : 'test' , http_method : 'get' )
86+ end
87+
88+ assert_equal ( 502 , error . http_status )
89+ end
90+
5491 def test_set_api_version_in_config
5592 WhatsappSdk . configure do |config |
5693 config . api_version = 'v16.0'
0 commit comments