Class: TestMobilyApiJsonRequestHandler
- Inherits:
-
MiniTest::Unit::TestCase
- Object
- MiniTest::Unit::TestCase
- TestMobilyApiJsonRequestHandler
- Defined in:
- lib/mobily/test/tc_json_request_handler.rb
Instance Method Summary collapse
- #test_json_building ⇒ Object
- #test_response_parsing_success ⇒ Object
- #test_response_parsing_throws ⇒ Object
Instance Method Details
#test_json_building ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/mobily/test/tc_json_request_handler.rb', line 12 def test_json_building expected_json = '{"Data":{"Method":"balance","Auth":{"mobile":"test","password":"test"}}}' handler = MobilyApiJsonRequestHandler.new handler.auth = MobilyApiAuth.new('test', 'test') handler.set_api_method('balance') assert_equal expected_json, handler.get_request_data end |
#test_response_parsing_success ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mobily/test/tc_json_request_handler.rb', line 20 def test_response_parsing_success fake_response = '' '{ "status":1, "ResponseStatus":"success", "Data":{ "result":"1", "MessageAr":"يمكنك الإرسال الآن", "MessageEn":"You can send SMS now" }, "Error":null } ' '' expected_response = MobilyApiResponse.new(1, 'success') expected_response.add_data('result', '1') expected_response.add_data('MessageAr', 'يمكنك الإرسال الآن') expected_response.add_data('MessageEn', 'You can send SMS now') handler = MobilyApiJsonRequestHandler.new handler.request = MobilyApiRequestStub.new(fake_response) assert_equal expected_response, handler.handle end |
#test_response_parsing_throws ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/mobily/test/tc_json_request_handler.rb', line 41 def test_response_parsing_throws fake_response = '' '{ "status":1, "ResponseStatus":"fail", "Data":null, "Error":{ "ErrorCode":0, "MessageAr":"بوابة غير معرفة لدينا", "MessageEn":"API not exist" } }' '' err = assert_raises MobilyApiError do handler = MobilyApiJsonRequestHandler.new handler.request = MobilyApiRequestStub.new(fake_response) handler.handle end assert_equal 'بوابة غير معرفة لدينا', err.msg_arabic assert_equal 'API not exist', err.msg_english assert_equal 0, err.code end |