defmodule PlugIndieTest do use ExUnit.Case, async: true use Plug.Test doctest PlugIndie @opts PlugIndie.init( hostname: "example.com", handler: TestHandler, token_endpoint: "http://example.com/token", json_encoder: Jason, user_agent: "ExUnit", token_handler: TestToken ) test "creates a new note using json" do # Create a test connection conn = request("/", %{ "content" => ["Hello World!"] }) # Invoke the plug conn = PlugIndie.call(conn, @opts) # Assert the response and status assert conn.state == :sent assert conn.status == 201 assert ["/notes" <> _] = get_resp_header(conn, "location") end defp request(url, properties, content_type \\ "application/json") do conn(:post, url, %{ "type" => ["h-entry"], "properties" => properties }) |> put_req_header("authorization", "Bearer 1234567890") |> put_req_header("content-type", content_type) end end