require_relative "test_helper"

App = Rack::Builder.new {
  use Rack::Committee::ParamValidation, schema: File.read("./test/schema.json")
  run lambda { |_|
    [200, {}, []]
  }
}

describe Rack::Committee::ParamValidation do
  include Rack::Test::Methods

  def app
    App
  end

  it "x" do
    post "/apps"
  end
end

require_relative "test_helper"

App = Rack::Builder.new {
  use Rack::Committee::ParamValidation, schema: File.read("./test/schema.json")
  run lambda { |_|
    [200, {}, []]
  }
}

describe Rack::Committee::ParamValidation do
  include Rack::Test::Methods

  def app
    App
  end

  before do
    header "Content-Type", "application/json"
  end

  it "detects an invalid Content-Type" do
    header "Content-Type", "application/whats-this"
    post "/account/app-transfers", "{}"
    assert_equal 400, last_response.status
  end

  it "passes through a valid request" do
    params = {
      "app" => "www",
      "recipient" => "owner@heroku.com",
    }
    post "/account/app-transfers", MultiJson.encode(params)
    assert_equal 200, last_response.status
  end

  it "detects a missing parameter" do
    post "/account/app-transfers", "{}"
    assert_equal 422, last_response.status
  end

  it "detects an extra parameter" do
    params = {
      "cloud" => "production"
    }
    post "/account/app-transfers", MultiJson.encode(params)
    assert_equal 422, last_response.status
  end
end

Add real tests for the parameter validation middleware
Add real tests for the parameter validation middleware
