add Properties tests, handle bookmarks and likes
This commit is contained in:
parent
7b19e42f57
commit
12005618a9
3 changed files with 66 additions and 1 deletions
|
@ -1,3 +1,9 @@
|
|||
defmodule PlugIndie.Post do
|
||||
defstruct [:type, :title, :content]
|
||||
defstruct [
|
||||
:bookmark_of,
|
||||
:content,
|
||||
:like_of,
|
||||
:title,
|
||||
:type
|
||||
]
|
||||
end
|
||||
|
|
|
@ -13,6 +13,22 @@ defmodule PlugIndie.Properties do
|
|||
content: content
|
||||
}}
|
||||
|
||||
:bookmark ->
|
||||
{:ok,
|
||||
%PlugIndie.Post{
|
||||
type: type,
|
||||
title: title,
|
||||
content: content,
|
||||
bookmark_of: get_bookmarked_url(properties)
|
||||
}}
|
||||
|
||||
:like ->
|
||||
{:ok,
|
||||
%PlugIndie.Post{
|
||||
type: type,
|
||||
like_of: get_liked_url(properties)
|
||||
}}
|
||||
|
||||
:unknown ->
|
||||
{:error, :parse_error}
|
||||
end
|
||||
|
|
43
test/properties_test.exs
Normal file
43
test/properties_test.exs
Normal file
|
@ -0,0 +1,43 @@
|
|||
defmodule PropertiesTest do
|
||||
use ExUnit.Case
|
||||
doctest PlugIndie.Properties
|
||||
import PlugIndie.Properties, only: [parse: 1]
|
||||
|
||||
test "parse/1 identifies a note" do
|
||||
props = %{
|
||||
"content" => ["Hello World!"]
|
||||
}
|
||||
|
||||
assert {:ok,
|
||||
%PlugIndie.Post{
|
||||
type: :note,
|
||||
content: "Hello World!"
|
||||
}} == parse(props)
|
||||
end
|
||||
|
||||
test "parse/1 identifies a bookmark" do
|
||||
props = %{
|
||||
"content" => ["Hello World!"],
|
||||
"bookmark-of" => ["https://100r.co"]
|
||||
}
|
||||
|
||||
assert {:ok,
|
||||
%PlugIndie.Post{
|
||||
type: :bookmark,
|
||||
content: "Hello World!",
|
||||
bookmark_of: "https://100r.co"
|
||||
}} == parse(props)
|
||||
end
|
||||
|
||||
test "parse/1 identifies a like" do
|
||||
props = %{
|
||||
"like-of" => ["https://100r.co"]
|
||||
}
|
||||
|
||||
assert {:ok,
|
||||
%PlugIndie.Post{
|
||||
type: :like,
|
||||
like_of: "https://100r.co"
|
||||
}} == parse(props)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue