2024-11-29 09:39:35 +00:00
|
|
|
defmodule ParserTest do
|
|
|
|
use ExUnit.Case
|
2024-11-29 09:42:27 +00:00
|
|
|
doctest PlugIndie.Parser
|
|
|
|
import PlugIndie.Parser, only: [parse_create_body: 2]
|
2024-11-29 09:39:35 +00:00
|
|
|
|
|
|
|
test "parse_create_body with content-type json" do
|
|
|
|
params = %{
|
|
|
|
"type" => ["h-entry"],
|
|
|
|
"properties" => %{
|
2024-12-05 14:36:43 +00:00
|
|
|
"name" => ["First Note"],
|
|
|
|
"content" => ["Hello World!"],
|
|
|
|
"category" => ["Foo", "Bar"]
|
2024-11-29 09:39:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-05 14:36:43 +00:00
|
|
|
assert {:ok, "entry",
|
|
|
|
%{
|
|
|
|
"content" => ["Hello World!"],
|
|
|
|
"category" => ["Foo", "Bar"],
|
|
|
|
"name" => ["First Note"]
|
|
|
|
}} ==
|
2024-11-29 09:39:35 +00:00
|
|
|
parse_create_body("application/json", params)
|
|
|
|
end
|
2024-12-05 14:36:43 +00:00
|
|
|
|
|
|
|
test "parse_create_body with content-type form" do
|
|
|
|
params = %{
|
|
|
|
"h" => "entry",
|
|
|
|
"name" => "First Note",
|
|
|
|
"content" => "Hello World!",
|
|
|
|
"category" => ["Foo", "Bar"]
|
|
|
|
}
|
|
|
|
|
|
|
|
# TODO: fix content type
|
|
|
|
assert {:ok, "entry",
|
|
|
|
%{
|
|
|
|
"content" => ["Hello World!"],
|
|
|
|
"category" => ["Foo", "Bar"],
|
|
|
|
"name" => ["First Note"]
|
|
|
|
}} ==
|
|
|
|
parse_create_body("application/form", params)
|
|
|
|
end
|
2024-11-29 09:39:35 +00:00
|
|
|
end
|