lucky icon indicating copy to clipboard operation
lucky copied to clipboard

Not possible to send raw body in the ApiClient in tests

Open confact opened this issue 3 years ago • 0 comments

Describe the bug I am doing a app with json streaming (multiple jsons separated with lines (\n)) and had no way to send it in as params got parsed to json and would not work.

To Reproduce Steps to reproduce the behavior:

    test_data = <<-JSON
      { "event_id": "#{event_id}"}
      { "type": "event"}
      { "event_id": "#{event_id}", "type": "event", "platform": "", "timestamp": #{Time.utc.to_unix}, "message": "message"}

    JSON

    client = ApiClient.new
    response = client.exec(Api::Events, test_data)

Will give error on method with those params doesn't exist.

By adding these methods in ApiClient, it works:

  def exec(action : Lucky::Action.class, body : String) : HTTP::Client::Response
    exec(action.route, body)
  end

  def exec(route_helper : Lucky::RouteHelper, body : String) : HTTP::Client::Response
    @client.exec(method: route_helper.method.to_s.upcase, path: route_helper.path, body: body)
  end

Expected behavior Accept sending in a string in the body for testing. My suggestion is to add those methods to be default in the builtin BaseHTTPClient

Versions (please complete the following information):

  • Lucky version (check in shard.lock): 0.29.0
  • Crystal version (crystal --version): 1.1.0
  • OS: Linux Mint

confact avatar Mar 25 '22 22:03 confact