add bookwyrm entity tests
authorFloatingGhost <hannah@coffee-and-dreams.uk>
Fri, 7 Jan 2022 17:17:18 +0000 (17:17 +0000)
committerFloatingGhost <hannah@coffee-and-dreams.uk>
Fri, 7 Jan 2022 17:17:18 +0000 (17:17 +0000)
lib/pleroma/web/activity_pub/object_validators/tag_validator.ex
test/pleroma/web/activity_pub/object_validators/tag_validator_test.exs [new file with mode: 0644]

index 77aaf7f2962aef2bf2b7ecff4bd9517b6b5f0084..00d0194afcf27849ff1e0410b9113c249f79283d 100644 (file)
@@ -77,7 +77,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.TagValidator do
   end
 
   def changeset(struct, %{"type" => "Edition"} = data) do
-    data = Map.put(data, "name", data["work"])
+    data = Map.put(data, "name", data["title"])
 
     struct
     |> cast(data, [:type, :name])
@@ -85,7 +85,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.TagValidator do
   end
 
   def changeset(struct, %{"type" => "Work"} = data) do
-    data = Map.put(data, "name", data["lccn"])
+    data = Map.put(data, "name", data["title"])
 
     struct
     |> cast(data, [:type, :name])
diff --git a/test/pleroma/web/activity_pub/object_validators/tag_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/tag_validator_test.exs
new file mode 100644 (file)
index 0000000..bca7a32
--- /dev/null
@@ -0,0 +1,112 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.ObjectValidators.TagValidatorTest do
+  use Pleroma.DataCase, async: true
+
+  alias Pleroma.Web.ActivityPub.ObjectValidators.TagValidator
+
+  test "it validates an Edition" do
+    edition = %{
+      "@context" => "https://www.w3.org/ns/activitystreams",
+      "asin" => "",
+      "authors" => ["https://bookwyrm.com/author/3"],
+      "cover" => %{
+        "@context" => "https://www.w3.org/ns/activitystreams",
+        "name" => "Piranesi (2020, Bloomsbury Publishing)",
+        "type" => "Document",
+        "url" => "https://bookwyrm.com/images/covers/9fd28af7-ebb8-4df3-80c8-28488fc5349f.jpeg"
+      },
+      "description" => "",
+      "editionRank" => 7,
+      "firstPublishedDate" => "",
+      "goodreadsKey" => "",
+      "id" => "https://bookwyrm.com/book/10",
+      "isbn10" => "163557563X",
+      "isbn13" => "9781635575637",
+      "languages" => ["English"],
+      "librarythingKey" => "",
+      "oclcNumber" => "",
+      "openlibraryKey" => "OL28300471M",
+      "pages" => 272,
+      "physicalFormat" => "",
+      "physicalFormatDetail" => "hardcover",
+      "publishedDate" => "2020-09-15T00:00:00+00:00",
+      "publishers" => ["Bloomsbury Publishing"],
+      "series" => "",
+      "seriesNumber" => "",
+      "sortTitle" => "",
+      "subjectPlaces" => [],
+      "subjects" => [],
+      "subtitle" => "",
+      "title" => "Piranesi",
+      "type" => "Edition",
+      "work" => "https://bookwyrm.com/book/9"
+    }
+
+    assert %{valid?: true, changes: %{name: "Piranesi"}} = TagValidator.cast_and_validate(edition)
+  end
+
+  test "it should validate an author" do
+    author = %{
+      "@context" => "https://www.w3.org/ns/activitystreams",
+      "aliases" => [],
+      "bio" => "snipped",
+      "bnfId" => "14603397h",
+      "born" => "1959-11-01T00:00:00+00:00",
+      "goodreadsKey" => "",
+      "id" => "https://bookwyrm.com/author/3",
+      "isni" => "0000 0001 0877 1086",
+      "librarythingKey" => "",
+      "name" => "Susanna Clarke",
+      "openlibraryKey" => "OL1387961A",
+      "type" => "Author",
+      "viafId" => "19931023",
+      "wikipediaLink" => ""
+    }
+
+    assert %{valid?: true, changes: %{name: "Susanna Clarke"}} =
+             TagValidator.cast_and_validate(author)
+  end
+
+  test "it should validate a work" do
+    work = %{
+      "@context" => "https://www.w3.org/ns/activitystreams",
+      "authors" => ["https://bookwyrm.com/author/3"],
+      "cover" => %{
+        "@context" => "https://www.w3.org/ns/activitystreams",
+        "name" => "Piranesi",
+        "type" => "Document",
+        "url" => "https://bookwyrm.com/images/covers/e950ac10-feaf-4c3e-b2d3-de20d3a28329.jpeg"
+      },
+      "description" => "snipped",
+      "editions" => [
+        "https://bookwyrm.com/book/12",
+        "https://bookwyrm.com/book/10",
+        "https://bookwyrm.com/book/14",
+        "https://bookwyrm.com/book/13",
+        "https://bookwyrm.com/book/11",
+        "https://bookwyrm.com/book/15"
+      ],
+      "firstPublishedDate" => "",
+      "goodreadsKey" => "",
+      "id" => "https://bookwyrm.com/book/9",
+      "languages" => [],
+      "lccn" => "",
+      "librarythingKey" => "",
+      "openlibraryKey" => "OL20893680W",
+      "publishedDate" => "",
+      "series" => "",
+      "seriesNumber" => "",
+      "sortTitle" => "",
+      "subjectPlaces" => [],
+      "subjects" => ["English literature"],
+      "subtitle" => "",
+      "title" => "Piranesi",
+      "type" => "Work"
+    }
+
+    assert %{valid?: true, changes: %{name: "Piranesi"}} = TagValidator.cast_and_validate(work)
+  end
+end