plug_indie/test/plug_micropub_test.exs

41 lines
1,020 B
Elixir
Raw Permalink Normal View History

2024-11-29 09:42:27 +00:00
defmodule PlugIndieTest do
use ExUnit.Case, async: true
use Plug.Test
2024-11-29 09:42:27 +00:00
doctest PlugIndie
2024-11-29 09:42:27 +00:00
@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
2024-11-29 09:42:27 +00:00
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
2018-03-20 05:17:02 +00:00
end