X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fpleroma%2Fweb%2Factivity_pub%2Fobject_validators%2Farticle_note_page_validator_test.exs;h=f419770f2e46e7c0cac2bff08cb2037227c17c2c;hb=aaf78e2b52c3aa1e75206e7dbe41b45874978e0a;hp=720c17d8da7e731da5c134dfce4699c274ecf48e;hpb=62bf6d67e393d2b290d226e8505d622d944c9a26;p=akkoma
diff --git a/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs
index 720c17d8d..f419770f2 100644
--- a/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs
+++ b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs
@@ -10,6 +10,12 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest
import Pleroma.Factory
+ setup_all do
+ Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
+
+ :ok
+ end
+
describe "Notes" do
setup do
user = insert(:user)
@@ -31,5 +37,111 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest
test "a basic note validates", %{note: note} do
%{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
end
+
+ test "a note with a remote replies collection should validate", _ do
+ insert(:user, %{ap_id: "https://bookwyrm.com/user/TestUser"})
+ collection = File.read!("test/fixtures/bookwyrm-replies-collection.json")
+
+ Tesla.Mock.mock(fn %{
+ method: :get,
+ url: "https://bookwyrm.com/user/TestUser/review/17/replies?page=1"
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: collection,
+ headers: HttpRequestMock.activitypub_object_headers()
+ }
+ end)
+
+ note = Jason.decode!(File.read!("test/fixtures/bookwyrm-article.json"))
+
+ %{valid?: true, changes: %{replies: ["https://bookwyrm.com/user/TestUser/status/18"]}} =
+ ArticleNotePageValidator.cast_and_validate(note)
+ end
+
+ test "a note with an attachment should work", _ do
+ insert(:user, %{ap_id: "https://owncast.localhost.localdomain/federation/user/streamer"})
+
+ note =
+ "test/fixtures/owncast-note-with-attachment.json"
+ |> File.read!()
+ |> Jason.decode!()
+
+ %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
+ end
+
+ test "a misskey MFM status with a content field should work and be linked", _ do
+ local_user =
+ insert(:user, %{nickname: "akkoma_user", ap_id: "http://localhost:4001/users/akkoma_user"})
+
+ remote_user =
+ insert(:user, %{
+ nickname: "remote_user",
+ ap_id: "http://misskey.local.live/users/remote_user"
+ })
+
+ full_tag_remote_user =
+ insert(:user, %{
+ nickname: "full_tag_remote_user",
+ ap_id: "http://misskey.local.live/users/full_tag_remote_user"
+ })
+
+ insert(:user, %{ap_id: "https://misskey.local.live/users/92hzkskwgy"})
+
+ note =
+ "test/fixtures/misskey/mfm_x_format.json"
+ |> File.read!()
+ |> Jason.decode!()
+
+ %{
+ valid?: true,
+ changes: %{
+ content: "this does not get replaced",
+ source: %{
+ "content" => content,
+ "mediaType" => "text/x.misskeymarkdown"
+ }
+ }
+ } = ArticleNotePageValidator.cast_and_validate(note)
+
+ assert content =~
+ "@akkoma_user"
+
+ assert content =~
+ "@remote_user"
+
+ assert content =~
+ "@full_tag_remote_user"
+
+ assert content =~ "@oops_not_a_mention"
+ assert content =~ "$[jelly mfm goes here]
## aaa"
+ end
+
+ test "a misskey MFM status with a _misskey_content field should work and be linked", _ do
+ local_user =
+ insert(:user, %{nickname: "akkoma_user", ap_id: "http://localhost:4001/users/akkoma_user"})
+
+ insert(:user, %{ap_id: "https://misskey.local.live/users/92hzkskwgy"})
+
+ note =
+ "test/fixtures/misskey/mfm_underscore_format.json"
+ |> File.read!()
+ |> Jason.decode!()
+
+ changes = ArticleNotePageValidator.cast_and_validate(note)
+
+ %{
+ valid?: true,
+ changes: %{
+ source: %{
+ "content" => content,
+ "mediaType" => "text/x.misskeymarkdown"
+ }
+ }
+ } = changes
+
+ assert content =~
+ "@akkoma_user"
+ end
end
end