Merge remote-tracking branch 'upstream/bookwyrm-entities' into develop
[akkoma] / test / pleroma / web / activity_pub / object_validators / tag_validator_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.ObjectValidators.TagValidatorTest do
6 use Pleroma.DataCase, async: true
7
8 alias Pleroma.Web.ActivityPub.ObjectValidators.TagValidator
9
10 test "it validates an Edition" do
11 edition = %{
12 "@context" => "https://www.w3.org/ns/activitystreams",
13 "asin" => "",
14 "authors" => ["https://bookwyrm.com/author/3"],
15 "cover" => %{
16 "@context" => "https://www.w3.org/ns/activitystreams",
17 "name" => "Piranesi (2020, Bloomsbury Publishing)",
18 "type" => "Document",
19 "url" => "https://bookwyrm.com/images/covers/9fd28af7-ebb8-4df3-80c8-28488fc5349f.jpeg"
20 },
21 "description" => "",
22 "editionRank" => 7,
23 "firstPublishedDate" => "",
24 "goodreadsKey" => "",
25 "id" => "https://bookwyrm.com/book/10",
26 "isbn10" => "163557563X",
27 "isbn13" => "9781635575637",
28 "languages" => ["English"],
29 "librarythingKey" => "",
30 "oclcNumber" => "",
31 "openlibraryKey" => "OL28300471M",
32 "pages" => 272,
33 "physicalFormat" => "",
34 "physicalFormatDetail" => "hardcover",
35 "publishedDate" => "2020-09-15T00:00:00+00:00",
36 "publishers" => ["Bloomsbury Publishing"],
37 "series" => "",
38 "seriesNumber" => "",
39 "sortTitle" => "",
40 "subjectPlaces" => [],
41 "subjects" => [],
42 "subtitle" => "",
43 "title" => "Piranesi",
44 "type" => "Edition",
45 "work" => "https://bookwyrm.com/book/9"
46 }
47
48 assert %{valid?: true, changes: %{name: "Piranesi"}} = TagValidator.cast_and_validate(edition)
49 end
50
51 test "it should validate an author" do
52 author = %{
53 "@context" => "https://www.w3.org/ns/activitystreams",
54 "aliases" => [],
55 "bio" => "snipped",
56 "bnfId" => "14603397h",
57 "born" => "1959-11-01T00:00:00+00:00",
58 "goodreadsKey" => "",
59 "id" => "https://bookwyrm.com/author/3",
60 "isni" => "0000 0001 0877 1086",
61 "librarythingKey" => "",
62 "name" => "Susanna Clarke",
63 "openlibraryKey" => "OL1387961A",
64 "type" => "Author",
65 "viafId" => "19931023",
66 "wikipediaLink" => ""
67 }
68
69 assert %{valid?: true, changes: %{name: "Susanna Clarke"}} =
70 TagValidator.cast_and_validate(author)
71 end
72
73 test "it should validate a work" do
74 work = %{
75 "@context" => "https://www.w3.org/ns/activitystreams",
76 "authors" => ["https://bookwyrm.com/author/3"],
77 "cover" => %{
78 "@context" => "https://www.w3.org/ns/activitystreams",
79 "name" => "Piranesi",
80 "type" => "Document",
81 "url" => "https://bookwyrm.com/images/covers/e950ac10-feaf-4c3e-b2d3-de20d3a28329.jpeg"
82 },
83 "description" => "snipped",
84 "editions" => [
85 "https://bookwyrm.com/book/12",
86 "https://bookwyrm.com/book/10",
87 "https://bookwyrm.com/book/14",
88 "https://bookwyrm.com/book/13",
89 "https://bookwyrm.com/book/11",
90 "https://bookwyrm.com/book/15"
91 ],
92 "firstPublishedDate" => "",
93 "goodreadsKey" => "",
94 "id" => "https://bookwyrm.com/book/9",
95 "languages" => [],
96 "lccn" => "",
97 "librarythingKey" => "",
98 "openlibraryKey" => "OL20893680W",
99 "publishedDate" => "",
100 "series" => "",
101 "seriesNumber" => "",
102 "sortTitle" => "",
103 "subjectPlaces" => [],
104 "subjects" => ["English literature"],
105 "subtitle" => "",
106 "title" => "Piranesi",
107 "type" => "Work"
108 }
109
110 assert %{valid?: true, changes: %{name: "Piranesi"}} = TagValidator.cast_and_validate(work)
111 end
112 end