plug_indie/test/plug_micropub_test.exs
Inhji c257845f06 first version of PlugIndie
- add attribute parsing
- add tests
- add token verification
2024-11-29 10:39:35 +01:00

40 lines
1 KiB
Elixir

defmodule PlugMicropubTest do
use ExUnit.Case, async: true
use Plug.Test
doctest PlugMicropub
@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
end