Sha256: 76e205502c63dcbe06d4082abe1bab9f1bdf3cda99ea75f2b85255d90cc4ffc4

Contents?: true

Size: 1.28 KB

Versions: 11

Compression:

Stored size: 1.28 KB

Contents

# 测试 lib/common/HttpClient.rb
# 运行: ruby ./lib/test/mini_test/TestHttpClient.rb

require "minitest/autorun"
require './lib/common/HttpClient.rb'

class TestAuthenticationClient < Minitest::Test

  # 测试初始化,初始化不应该报错
  def test_init
    httpClient = AuthingRuby::Common::HttpClient.new
  end
  
  # 测试简单的 get 方法
  # ruby ./lib/test/mini_test/TestHttpClient.rb -n test_get
  def test_get
    httpClient = AuthingRuby::Common::HttpClient.new
    url = "https://postman-echo.com/get"
    # url = "https://postman-echo.com/get?foo1=bar1&foo2=bar2"
    params = {
      "a": 3,
      "b": 4,
    }
    resp = httpClient.request({
      method: 'GET',
      url: url,
      params: params,
    })
    json = JSON.parse(resp.body)
    # puts JSON.pretty_generate(json)
    assert(json.dig('args', "a") == "3")
  end

  # 测试 post 方法
  # ruby ./lib/test/mini_test/TestHttpClient.rb -n test_post
  def test_post
    httpClient = AuthingRuby::Common::HttpClient.new
    url = "https://postman-echo.com/post"
    resp = httpClient.request({
      method: 'POST',
      url: url,
      data: {
        "x": 100,
        "y": 200,
      }
    })
    json = JSON.parse(resp.body)
    # puts JSON.pretty_generate(json)
    assert(json.dig('json', "x") == "100")
  end


end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
authing_ruby-1.1.6 lib/authing_ruby/test/mini_test/TestHttpClient.rb
authing_ruby-1.1.5 lib/authing_ruby/test/mini_test/TestHttpClient.rb
authing_ruby-1.1.4 lib/authing_ruby/test/mini_test/TestHttpClient.rb
authing_ruby-1.1.3 lib/authing_ruby/test/mini_test/TestHttpClient.rb
authing_ruby-1.1.2 lib/authing_ruby/test/mini_test/TestHttpClient.rb
authing_ruby-1.1.1 lib/authing_ruby/test/mini_test/TestHttpClient.rb
authing_ruby-1.1.0 lib/authing_ruby/test/mini_test/TestHttpClient.rb
authing_ruby-1.0.9 lib/authing_ruby/test/mini_test/TestHttpClient.rb
authing_ruby-1.0.8 lib/authing_ruby/test/mini_test/TestHttpClient.rb
authing_ruby-1.0.7 lib/authing_ruby/test/mini_test/TestHttpClient.rb
authing_ruby-1.0.6 lib/authing_ruby/test/mini_test/TestHttpClient.rb