1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest do
6 use Pleroma.DataCase, async: true
8 alias Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidator
9 alias Pleroma.Web.ActivityPub.Utils
11 import Pleroma.Factory
14 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
24 "id" => Utils.generate_activity_id(),
26 "actor" => user.ap_id,
27 "to" => [user.follower_address],
29 "content" => "Hellow this is content.",
34 %{user: user, note: note}
37 test "a basic note validates", %{note: note} do
38 %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
41 test "a note with a remote replies collection should validate", _ do
42 insert(:user, %{ap_id: "https://bookwyrm.com/user/TestUser"})
43 collection = File.read!("test/fixtures/bookwyrm-replies-collection.json")
47 url: "https://bookwyrm.com/user/TestUser/review/17/replies?page=1"
52 headers: HttpRequestMock.activitypub_object_headers()
56 note = Jason.decode!(File.read!("test/fixtures/bookwyrm-article.json"))
58 %{valid?: true, changes: %{replies: ["https://bookwyrm.com/user/TestUser/status/18"]}} =
59 ArticleNotePageValidator.cast_and_validate(note)
62 test "a note with an attachment should work", _ do
63 insert(:user, %{ap_id: "https://owncast.localhost.localdomain/federation/user/streamer"})
66 "test/fixtures/owncast-note-with-attachment.json"
70 %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
73 test "a misskey MFM status with a content field should work and be linked", _ do
75 insert(:user, %{nickname: "akkoma_user", ap_id: "http://localhost:4001/users/akkoma_user"})
79 nickname: "remote_user",
80 ap_id: "http://misskey.local.live/users/remote_user"
83 full_tag_remote_user =
85 nickname: "full_tag_remote_user",
86 ap_id: "http://misskey.local.live/users/full_tag_remote_user"
89 insert(:user, %{ap_id: "https://misskey.local.live/users/92hzkskwgy"})
92 "test/fixtures/misskey/mfm_x_format.json"
102 "@akkoma_user @remote_user @full_tag_remote_user@misskey.local.live @oops_not_a_mention linkifylink #dancedance $[jelly mfm goes here] \n\n## aaa",
103 "mediaType" => "text/x.misskeymarkdown"
106 } = ArticleNotePageValidator.cast_and_validate(note)
109 "<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{local_user.id}\" href=\"#{local_user.ap_id}\" rel=\"ugc\">@<span>akkoma_user</span></a></span>"
112 "<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{remote_user.id}\" href=\"#{remote_user.ap_id}\" rel=\"ugc\">@<span>remote_user</span></a></span>"
115 "<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{full_tag_remote_user.id}\" href=\"#{full_tag_remote_user.ap_id}\" rel=\"ugc\">@<span>full_tag_remote_user</span></a></span>"
117 assert content =~ "@oops_not_a_mention"
118 assert content =~ "$[jelly mfm goes here] <br><br>## aaa"
121 test "a misskey MFM status with a _misskey_content field should work and be linked", _ do
123 insert(:user, %{nickname: "akkoma_user", ap_id: "http://localhost:4001/users/akkoma_user"})
125 insert(:user, %{ap_id: "https://misskey.local.live/users/92hzkskwgy"})
128 "test/fixtures/misskey/mfm_underscore_format.json"
133 "<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{local_user.id}\" href=\"#{local_user.ap_id}\" rel=\"ugc\">@<span>akkoma_user</span></a></span> linkifylink <a class=\"hashtag\" data-tag=\"dancedance\" href=\"http://localhost:4001/tag/dancedance\" rel=\"tag ugc\">#dancedance</a> $[jelly mfm goes here] <br><br>## aaa"
138 content: ^expected_content,
140 "content" => "@akkoma_user linkifylink #dancedance $[jelly mfm goes here] \n\n## aaa",
141 "mediaType" => "text/x.misskeymarkdown"
144 } = ArticleNotePageValidator.cast_and_validate(note)