1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 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.ObjectValidator
9 alias Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidator
10 alias Pleroma.Web.ActivityPub.Utils
12 import Pleroma.Factory
19 "id" => Utils.generate_activity_id(),
21 "actor" => user.ap_id,
22 "to" => [user.follower_address],
24 "content" => "Hellow this is content.",
29 %{user: user, note: note}
32 test "a basic note validates", %{note: note} do
33 %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
36 test "a note from factory validates" do
38 %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note.data)
42 describe "Note with history" do
45 {:ok, activity} = Pleroma.Web.CommonAPI.post(user, %{status: "mew mew :dinosaur:"})
46 {:ok, edit} = Pleroma.Web.CommonAPI.update(user, activity, %{status: "edited :blank:"})
48 {:ok, %{"object" => external_rep}} =
49 Pleroma.Web.ActivityPub.Transmogrifier.prepare_outgoing(edit.data)
51 %{external_rep: external_rep}
54 test "edited note", %{external_rep: external_rep} do
55 assert %{"formerRepresentations" => %{"orderedItems" => [%{"tag" => [_]}]}} = external_rep
57 {:ok, validate_res, []} = ObjectValidator.validate(external_rep, [])
59 assert %{"formerRepresentations" => %{"orderedItems" => [%{"emoji" => %{"dinosaur" => _}}]}} =
63 test "edited note, badly-formed formerRepresentations", %{external_rep: external_rep} do
64 external_rep = Map.put(external_rep, "formerRepresentations", %{})
66 assert {:error, _} = ObjectValidator.validate(external_rep, [])
69 test "edited note, badly-formed history item", %{external_rep: external_rep} do
71 Enum.at(external_rep["formerRepresentations"]["orderedItems"], 0)
72 |> Map.put("type", "Foo")
77 ["formerRepresentations", "orderedItems"],
81 assert {:error, _} = ObjectValidator.validate(external_rep, [])
85 test "a Note from Roadhouse validates" do
86 insert(:user, ap_id: "https://macgirvin.com/channel/mike")
89 "test/fixtures/roadhouse-create-activity.json"
93 %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
96 test "a note with an attachment should work", _ do
97 insert(:user, %{ap_id: "https://owncast.localhost.localdomain/federation/user/streamer"})
100 "test/fixtures/owncast-note-with-attachment.json"
104 %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
107 test "a Note without replies/first/items validates" do
108 insert(:user, ap_id: "https://mastodon.social/users/emelie")
111 "test/fixtures/tesla_mock/status.emelie.json"
114 |> pop_in(["replies", "first", "items"])
117 %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)