Add ability to set a default post expiry (#321)
[akkoma] / test / pleroma / web / metadata / utils_test.exs
index c99d11596f250552ca679d901d880a47932c656d..665efb9cad73b79c7270e27b16b3c99ec4f76ab2 100644 (file)
@@ -8,7 +8,7 @@ defmodule Pleroma.Web.Metadata.UtilsTest do
   alias Pleroma.Web.Metadata.Utils
 
   describe "scrub_html_and_truncate/1" do
-    test "it returns text without encode HTML" do
+    test "it returns content text without encode HTML if summary is nil" do
       user = insert(:user)
 
       note =
@@ -16,6 +16,7 @@ defmodule Pleroma.Web.Metadata.UtilsTest do
           data: %{
             "actor" => user.ap_id,
             "id" => "https://pleroma.gov/objects/whatever",
+            "summary" => nil,
             "content" => "Pleroma's really cool!"
           }
         })
@@ -23,6 +24,39 @@ defmodule Pleroma.Web.Metadata.UtilsTest do
       assert Utils.scrub_html_and_truncate(note) == "Pleroma's really cool!"
     end
 
+    test "it returns context text without encode HTML if summary is empty" do
+      user = insert(:user)
+
+      note =
+        insert(:note, %{
+          data: %{
+            "actor" => user.ap_id,
+            "id" => "https://pleroma.gov/objects/whatever",
+            "summary" => "",
+            "content" => "Pleroma's really cool!"
+          }
+        })
+
+      assert Utils.scrub_html_and_truncate(note) == "Pleroma's really cool!"
+    end
+
+    test "it returns summary text without encode HTML if summary is filled" do
+      user = insert(:user)
+
+      note =
+        insert(:note, %{
+          data: %{
+            "actor" => user.ap_id,
+            "id" => "https://pleroma.gov/objects/whatever",
+            "summary" => "Public service announcement on caffeine consumption",
+            "content" => "cofe"
+          }
+        })
+
+      assert Utils.scrub_html_and_truncate(note) ==
+               "Public service announcement on caffeine consumption"
+    end
+
     test "it does not return old content after editing" do
       user = insert(:user)