2019-11-05 14:02:31 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2019-11-05 14:02:31 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-10-21 08:23:10 +00:00
|
|
|
defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest do
|
2020-12-21 11:21:40 +00:00
|
|
|
use Pleroma.DataCase, async: true
|
2019-11-05 14:02:31 +00:00
|
|
|
|
2020-10-21 08:23:10 +00:00
|
|
|
alias Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidator
|
2019-11-05 14:02:31 +00:00
|
|
|
alias Pleroma.Web.ActivityPub.Utils
|
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
describe "Notes" do
|
|
|
|
setup do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
note = %{
|
|
|
|
"id" => Utils.generate_activity_id(),
|
|
|
|
"type" => "Note",
|
|
|
|
"actor" => user.ap_id,
|
|
|
|
"to" => [user.follower_address],
|
|
|
|
"cc" => [],
|
|
|
|
"content" => "Hellow this is content.",
|
|
|
|
"context" => "xxx",
|
|
|
|
"summary" => "a post"
|
|
|
|
}
|
|
|
|
|
|
|
|
%{user: user, note: note}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "a basic note validates", %{note: note} do
|
2020-10-21 08:23:10 +00:00
|
|
|
%{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
|
2019-11-05 14:02:31 +00:00
|
|
|
end
|
2022-01-07 16:51:04 +00:00
|
|
|
|
|
|
|
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
|
2022-07-01 10:44:45 +00:00
|
|
|
|
|
|
|
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
|
2019-11-05 14:02:31 +00:00
|
|
|
end
|
|
|
|
end
|