Sha256: 5080007947033a02b44c730e7f252f171aca910e9b107ad0433f8165fb74d7a9

Contents?: true

Size: 1.6 KB

Versions: 2

Compression:

Stored size: 1.6 KB

Contents

require 'helper'

class TestRequest < Test::Unit::TestCase
  def test_initializes_receiving_data_and_optional_id
    request = MyMoip::Request.new("request_id")
    assert_equal "request_id", request.id
  end

  def test_logs_api_call_method_in_info_level
    logger = stub_everything
    request = MyMoip::Request.new("request_id")
    params = {
      http_method: :post, body: "<pretty><xml></xml></pretty>", path: "/ws/alpha/EnviarInstrucao/Unica"
    }

    HTTParty.stubs(:send).returns("<html>some_result</html>")
    logger.expects(:info).at_least_once.
      with(regexp_matches(/being sent to MoIP/))

    request.api_call(params, logger: logger)
  end

  def test_logs_api_call_method_parameters_in_debug_level
    logger = stub_everything
    request = MyMoip::Request.new("request_id")
    params = {
      http_method: :post, body: "<pretty><xml></xml></pretty>", path: "/ws/alpha/EnviarInstrucao/Unica"
    }

    HTTParty.stubs(:send).returns("<html>some_result</html>")
    logger.expects(:debug).at_least_once.
      with(regexp_matches(/request_id.+<pretty><xml><\/xml><\/pretty>/))

    request.api_call(params, logger: logger)
  end

  def test_logs_api_call_response_in_debug_level
    logger = stub_everything
    request = MyMoip::Request.new("request_id")
    params = {
      http_method: :post, body: "<pretty><xml></xml></pretty>", path: "/ws/alpha/EnviarInstrucao/Unica"
    }

    HTTParty.stubs(:send).returns("<html>some_result</html>")
    logger.expects(:debug).at_least_once.
      with(regexp_matches(/request_id.+<html>some_result<\/html>/))

    request.api_call(params, logger: logger)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mymoip-0.6.0 test/test_request.rb
mymoip-0.5.0 test/test_request.rb