2020-01-22 02:14:42 +01:00
|
|
|
defmodule Mobilizon.Federation.ActivityPub.UtilsTest do
|
2019-09-22 16:26:23 +02:00
|
|
|
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
|
|
|
|
2018-12-14 17:41:55 +01:00
|
|
|
use Mobilizon.DataCase
|
2019-09-22 16:26:23 +02:00
|
|
|
|
2018-12-14 17:41:55 +01:00
|
|
|
import Mobilizon.Factory
|
2019-09-22 16:26:23 +02:00
|
|
|
|
2020-01-22 22:40:40 +01:00
|
|
|
alias Mobilizon.Federation.ActivityStream.Converter
|
2019-09-22 16:26:23 +02:00
|
|
|
|
2020-01-26 21:36:50 +01:00
|
|
|
alias Mobilizon.Web.Endpoint
|
|
|
|
alias Mobilizon.Web.Router.Helpers, as: Routes
|
2018-12-14 17:41:55 +01:00
|
|
|
|
|
|
|
describe "make" do
|
|
|
|
test "comment data from struct" do
|
|
|
|
comment = insert(:comment)
|
2019-10-25 17:43:37 +02:00
|
|
|
tag = insert(:tag, title: "MyTag")
|
2020-07-09 17:24:28 +02:00
|
|
|
reply = insert(:comment, in_reply_to_comment: comment, tags: [tag], attributed_to: nil)
|
2018-12-14 17:41:55 +01:00
|
|
|
|
|
|
|
assert %{
|
|
|
|
"type" => "Note",
|
|
|
|
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
2019-10-25 17:43:37 +02:00
|
|
|
"cc" => [],
|
|
|
|
"tag" => [
|
|
|
|
%{
|
|
|
|
"href" => "http://mobilizon.test/tags/#{tag.slug}",
|
|
|
|
"name" => "#MyTag",
|
|
|
|
"type" => "Hashtag"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"content" => "My Comment",
|
2018-12-14 17:41:55 +01:00
|
|
|
"actor" => reply.actor.url,
|
|
|
|
"uuid" => reply.uuid,
|
2019-04-25 19:05:05 +02:00
|
|
|
"id" => Routes.page_url(Endpoint, :comment, reply.uuid),
|
2018-12-14 17:41:55 +01:00
|
|
|
"inReplyTo" => comment.url,
|
2019-12-03 11:29:51 +01:00
|
|
|
"attributedTo" => reply.actor.url,
|
2020-08-14 11:32:23 +02:00
|
|
|
"mediaType" => "text/html",
|
2021-06-03 18:58:47 +02:00
|
|
|
"published" => reply.published_at |> DateTime.to_iso8601(),
|
|
|
|
"isAnnouncement" => false
|
2019-09-22 18:29:13 +02:00
|
|
|
} == Converter.Comment.model_to_as(reply)
|
2018-12-14 17:41:55 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "comment data from map" do
|
2020-07-09 17:24:28 +02:00
|
|
|
comment = insert(:comment, attributed_to: nil)
|
|
|
|
reply = insert(:comment, in_reply_to_comment: comment, attributed_to: nil)
|
2018-12-14 17:41:55 +01:00
|
|
|
to = ["https://www.w3.org/ns/activitystreams#Public"]
|
2019-12-03 11:29:51 +01:00
|
|
|
comment_data = Converter.Comment.model_to_as(reply)
|
2018-12-14 17:41:55 +01:00
|
|
|
assert comment_data["type"] == "Note"
|
|
|
|
assert comment_data["to"] == to
|
|
|
|
assert comment_data["content"] == reply.text
|
|
|
|
assert comment_data["actor"] == reply.actor.url
|
|
|
|
assert comment_data["inReplyTo"] == comment.url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|