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"
101 "mediaType" => "text/x.misskeymarkdown"
104 } = ArticleNotePageValidator.cast_and_validate(note)
107 "<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>"
110 "<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>"
113 "<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>"
115 assert content =~ "@oops_not_a_mention"
118 "<span class=\"mfm _mfm_jelly_\" style=\"display: inline-block; animation: 1s linear 0s infinite normal both running mfm-rubberBand;\">mfm goes here</span> </p>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"
132 changes = ArticleNotePageValidator.cast_and_validate(note)
139 "mediaType" => "text/x.misskeymarkdown",
140 "content" => "@akkoma_user linkifylink #dancedance $[jelly mfm goes here] \n\n## aaa"
146 "<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>"
150 test "a Note without replies/first/items validates" do
151 insert(:user, ap_id: "https://mastodon.social/users/emelie")
154 "test/fixtures/tesla_mock/status.emelie.json"
157 |> pop_in(["replies", "first", "items"])
160 %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)