717a704d407649e0efe21d384953ed0d78902283
[akkoma] / test / pleroma / web / activity_pub / object_validators / article_note_page_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.ArticleNotePageValidatorTest do
6 use Pleroma.DataCase, async: true
7
8 alias Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidator
9 alias Pleroma.Web.ActivityPub.Utils
10
11 import Pleroma.Factory
12
13 describe "Notes" do
14 setup do
15 user = insert(:user)
16
17 note = %{
18 "id" => Utils.generate_activity_id(),
19 "type" => "Note",
20 "actor" => user.ap_id,
21 "to" => [user.follower_address],
22 "cc" => [],
23 "content" => "Hellow this is content.",
24 "context" => "xxx",
25 "summary" => "a post"
26 }
27
28 %{user: user, note: note}
29 end
30
31 test "a basic note validates", %{note: note} do
32 %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
33 end
34
35 test "a note with a remote replies collection should validate", _ do
36 insert(:user, %{ap_id: "https://bookwyrm.com/user/TestUser"})
37 collection = File.read!("test/fixtures/bookwyrm-replies-collection.json")
38
39 Tesla.Mock.mock(fn %{
40 method: :get,
41 url: "https://bookwyrm.com/user/TestUser/review/17/replies?page=1"
42 } ->
43 %Tesla.Env{
44 status: 200,
45 body: collection,
46 headers: HttpRequestMock.activitypub_object_headers()
47 }
48 end)
49
50 note = Jason.decode!(File.read!("test/fixtures/bookwyrm-article.json"))
51
52 %{valid?: true, changes: %{replies: ["https://bookwyrm.com/user/TestUser/status/18"]}} =
53 ArticleNotePageValidator.cast_and_validate(note)
54 end
55
56 test "a note with an attachment should work", _ do
57 insert(:user, %{ap_id: "https://owncast.localhost.localdomain/federation/user/streamer"})
58
59 note =
60 "test/fixtures/owncast-note-with-attachment.json"
61 |> File.read!()
62 |> Jason.decode!()
63
64 %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
65 end
66 end
67 end