From 12005618a963eaf9e9aaa05d5b7f33625fe86e30 Mon Sep 17 00:00:00 2001 From: Inhji Date: Thu, 5 Dec 2024 15:36:18 +0100 Subject: [PATCH] add Properties tests, handle bookmarks and likes --- lib/post.ex | 8 +++++++- lib/properties.ex | 16 +++++++++++++++ test/properties_test.exs | 43 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 test/properties_test.exs diff --git a/lib/post.ex b/lib/post.ex index 92a9597..eaddc2e 100644 --- a/lib/post.ex +++ b/lib/post.ex @@ -1,3 +1,9 @@ defmodule PlugIndie.Post do - defstruct [:type, :title, :content] + defstruct [ + :bookmark_of, + :content, + :like_of, + :title, + :type + ] end diff --git a/lib/properties.ex b/lib/properties.ex index 895fa21..cb39b92 100644 --- a/lib/properties.ex +++ b/lib/properties.ex @@ -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 diff --git a/test/properties_test.exs b/test/properties_test.exs new file mode 100644 index 0000000..54dfb27 --- /dev/null +++ b/test/properties_test.exs @@ -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