2018-03-20 05:17:02 +00:00
|
|
|
defmodule PlugMicropubTest do
|
2024-11-29 09:39:35 +00:00
|
|
|
use ExUnit.Case, async: true
|
|
|
|
use Plug.Test
|
|
|
|
|
2018-03-20 05:17:02 +00:00
|
|
|
doctest PlugMicropub
|
2024-11-29 09:39:35 +00:00
|
|
|
|
|
|
|
@opts PlugMicropub.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 = PlugMicropub.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
|
2018-03-20 05:17:02 +00:00
|
|
|
end
|