ArticleNoteValidatorTest: Test mastodon Note object

This commit is contained in:
Haelwenn (lanodan) Monnier 2020-09-17 14:51:18 +02:00 committed by Egor Kislitsyn
parent 76a5a192bc
commit 5f38513bf0
No known key found for this signature in database
GPG Key ID: 1B49CB15B71E7805
1 changed files with 62 additions and 18 deletions

View File

@ -5,31 +5,75 @@
defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNoteValidatorTest do
use Pleroma.DataCase, async: true
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ObjectValidator
alias Pleroma.Web.ActivityPub.ObjectValidators.ArticleNoteValidator
alias Pleroma.Web.ActivityPub.Utils
import Pleroma.Factory
describe "Notes" do
setup do
user = insert(:user)
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
:ok
end
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"
}
test "a basic note validates" do
user = insert(:user)
%{user: user, note: note}
end
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"
}
test "a basic note validates", %{note: note} do
%{valid?: true} = ArticleNoteValidator.cast_and_validate(note)
end
%{valid?: true} = ArticleNoteValidator.cast_and_validate(note)
end
test "Mastodon Note" do
data =
File.read!("test/fixtures/mastodon-post-activity.json")
|> Jason.decode!()
{:ok, %User{}} = ObjectValidator.fetch_actor(data)
assert %{changes: changes, valid?: true} =
ArticleNoteValidator.cast_and_validate(data["object"])
assert %{
actor: "http://mastodon.example.org/users/admin",
attributedTo: "http://mastodon.example.org/users/admin",
cc: [
"http://localtesting.pleroma.lol/users/lain",
"http://mastodon.example.org/users/admin/followers"
],
content:
"<p><span class=\"h-card\"><a href=\"http://localtesting.pleroma.lol/users/lain\" class=\"u-url mention\">@<span>lain</span></a></span></p>",
context: "tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation",
id: "http://mastodon.example.org/users/admin/statuses/99512778738411822",
published: "2018-02-12T14:08:20Z",
sensitive: true,
summary: "cw",
tag: [
%{
"href" => "http://localtesting.pleroma.lol/users/lain",
"name" => "@lain@localtesting.pleroma.lol",
"type" => "Mention"
}
],
to: ["https://www.w3.org/ns/activitystreams#Public"],
type: "Note",
url: "http://mastodon.example.org/@admin/99512778738411822",
replies: [
"http://mastodon.example.org/users/admin/statuses/99512778738411823",
"http://mastodon.example.org/users/admin/statuses/99512778738411824"
]
} = changes
assert changes[:context_id]
end
end