Fix tests

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2020-12-16 11:14:24 +01:00
parent d1472d94de
commit 273c98cfdf
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
3 changed files with 75 additions and 105 deletions

View file

@ -111,117 +111,110 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.UpdateTest do
describe "handle incoming updates activities for group posts" do describe "handle incoming updates activities for group posts" do
test "it works for incoming update activities on group posts when remote actor is a moderator" do test "it works for incoming update activities on group posts when remote actor is a moderator" do
use_cassette "activity_pub/group_post_update_activities" do %Actor{url: remote_actor_url} =
%Actor{url: remote_actor_url} = remote_actor =
remote_actor = insert(:actor,
insert(:actor, domain: "remote.domain",
domain: "remote.domain", url: "https://remote.domain/@remote",
url: "https://remote.domain/@remote", preferred_username: "remote"
preferred_username: "remote" )
)
group = insert(:group) group = insert(:group)
%Member{} = member = insert(:member, actor: remote_actor, parent: group, role: :moderator) %Member{} = member = insert(:member, actor: remote_actor, parent: group, role: :moderator)
%Post{} = post = insert(:post, attributed_to: group) %Post{} = post = insert(:post, attributed_to: group)
data = Convertible.model_to_as(post) data = Convertible.model_to_as(post)
refute is_nil(Posts.get_post_by_url(data["id"])) refute is_nil(Posts.get_post_by_url(data["id"]))
update_data = File.read!("test/fixtures/mastodon-update.json") |> Jason.decode!() update_data = File.read!("test/fixtures/mastodon-update.json") |> Jason.decode!()
object = object =
data data
|> Map.put("name", "My updated post") |> Map.put("name", "My updated post")
|> Map.put("type", "Article") |> Map.put("type", "Article")
update_data = update_data =
update_data update_data
|> Map.put("actor", remote_actor_url) |> Map.put("actor", remote_actor_url)
|> Map.put("object", object) |> Map.put("object", object)
{:ok, %Activity{data: data, local: false}, _} = {:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(update_data)
Transmogrifier.handle_incoming(update_data)
%Post{id: updated_post_id, title: updated_post_title} = %Post{id: updated_post_id, title: updated_post_title} =
Posts.get_post_by_url(data["object"]["id"]) Posts.get_post_by_url(data["object"]["id"])
assert updated_post_id == post.id assert updated_post_id == post.id
assert updated_post_title == "My updated post" assert updated_post_title == "My updated post"
end
end end
test "it works for incoming update activities on group posts" do test "it works for incoming update activities on group posts" do
use_cassette "activity_pub/group_post_update_activities" do %Actor{url: remote_actor_url} =
%Actor{url: remote_actor_url} = remote_actor =
remote_actor = insert(:actor,
insert(:actor, domain: "remote.domain",
domain: "remote.domain", url: "https://remote.domain/@remote",
url: "https://remote.domain/@remote", preferred_username: "remote"
preferred_username: "remote" )
)
group = insert(:group) group = insert(:group)
%Member{} = member = insert(:member, actor: remote_actor, parent: group) %Member{} = member = insert(:member, actor: remote_actor, parent: group)
%Post{} = post = insert(:post, attributed_to: group) %Post{} = post = insert(:post, attributed_to: group)
data = Convertible.model_to_as(post) data = Convertible.model_to_as(post)
refute is_nil(Posts.get_post_by_url(data["id"])) refute is_nil(Posts.get_post_by_url(data["id"]))
update_data = File.read!("test/fixtures/mastodon-update.json") |> Jason.decode!() update_data = File.read!("test/fixtures/mastodon-update.json") |> Jason.decode!()
object = object =
data data
|> Map.put("name", "My updated post") |> Map.put("name", "My updated post")
|> Map.put("type", "Article") |> Map.put("type", "Article")
update_data = update_data =
update_data update_data
|> Map.put("actor", remote_actor_url) |> Map.put("actor", remote_actor_url)
|> Map.put("object", object) |> Map.put("object", object)
:error = Transmogrifier.handle_incoming(update_data) :error = Transmogrifier.handle_incoming(update_data)
%Post{id: updated_post_id, title: updated_post_title} = Posts.get_post_by_url(data["id"]) %Post{id: updated_post_id, title: updated_post_title} = Posts.get_post_by_url(data["id"])
assert updated_post_id == post.id assert updated_post_id == post.id
refute updated_post_title == "My updated post" refute updated_post_title == "My updated post"
end
end end
test "it fails for incoming update activities on group posts when the actor is not a member from the group" do test "it fails for incoming update activities on group posts when the actor is not a member from the group" do
use_cassette "activity_pub/group_post_update_activities" do %Actor{url: remote_actor_url} =
%Actor{url: remote_actor_url} = insert(:actor,
insert(:actor, domain: "remote.domain",
domain: "remote.domain", url: "https://remote.domain/@remote",
url: "https://remote.domain/@remote", preferred_username: "remote"
preferred_username: "remote" )
)
group = insert(:group) group = insert(:group)
%Post{} = post = insert(:post, attributed_to: group) %Post{} = post = insert(:post, attributed_to: group)
data = Convertible.model_to_as(post) data = Convertible.model_to_as(post)
refute is_nil(Posts.get_post_by_url(data["id"])) refute is_nil(Posts.get_post_by_url(data["id"]))
update_data = File.read!("test/fixtures/mastodon-update.json") |> Jason.decode!() update_data = File.read!("test/fixtures/mastodon-update.json") |> Jason.decode!()
object = object =
data data
|> Map.put("name", "My updated post") |> Map.put("name", "My updated post")
|> Map.put("type", "Article") |> Map.put("type", "Article")
update_data = update_data =
update_data update_data
|> Map.put("actor", remote_actor_url) |> Map.put("actor", remote_actor_url)
|> Map.put("object", object) |> Map.put("object", object)
:error = Transmogrifier.handle_incoming(update_data) :error = Transmogrifier.handle_incoming(update_data)
%Post{id: updated_post_id, title: updated_post_title} = Posts.get_post_by_url(data["id"]) %Post{id: updated_post_id, title: updated_post_title} = Posts.get_post_by_url(data["id"])
assert updated_post_id == post.id assert updated_post_id == post.id
refute updated_post_title == "My updated post" refute updated_post_title == "My updated post"
end
end end
end end
end end

View file

@ -1,24 +0,0 @@
[
{
"request": {
"body": "{\"@context\":[\"https://www.w3.org/ns/activitystreams\",\"https://litepub.social/litepub/context.jsonld\",{\"Hashtag\":\"as:Hashtag\",\"PostalAddress\":\"sc:PostalAddress\",\"address\":{\"@id\":\"sc:address\",\"@type\":\"sc:PostalAddress\"},\"addressCountry\":\"sc:addressCountry\",\"addressLocality\":\"sc:addressLocality\",\"addressRegion\":\"sc:addressRegion\",\"anonymousParticipationEnabled\":{\"@id\":\"mz:anonymousParticipationEnabled\",\"@type\":\"sc:Boolean\"},\"category\":\"sc:category\",\"commentsEnabled\":{\"@id\":\"pt:commentsEnabled\",\"@type\":\"sc:Boolean\"},\"discoverable\":\"toot:discoverable\",\"ical\":\"http://www.w3.org/2002/12/cal/ical#\",\"joinMode\":{\"@id\":\"mz:joinMode\",\"@type\":\"mz:joinModeType\"},\"joinModeType\":{\"@id\":\"mz:joinModeType\",\"@type\":\"rdfs:Class\"},\"location\":{\"@id\":\"sc:location\",\"@type\":\"sc:Place\"},\"manuallyApprovesFollowers\":\"as:manuallyApprovesFollowers\",\"maximumAttendeeCapacity\":\"sc:maximumAttendeeCapacity\",\"mz\":\"https://joinmobilizon.org/ns#\",\"participationMessage\":{\"@id\":\"mz:participationMessage\",\"@type\":\"sc:Text\"},\"postalCode\":\"sc:postalCode\",\"pt\":\"https://joinpeertube.org/ns#\",\"repliesModerationOption\":{\"@id\":\"mz:repliesModerationOption\",\"@type\":\"mz:repliesModerationOptionType\"},\"repliesModerationOptionType\":{\"@id\":\"mz:repliesModerationOptionType\",\"@type\":\"rdfs:Class\"},\"sc\":\"http://schema.org#\",\"streetAddress\":\"sc:streetAddress\",\"toot\":\"http://joinmastodon.org/ns#\",\"uuid\":\"sc:identifier\"}],\"actor\":\"http://mobilizon.test/@myGroup0\",\"cc\":[],\"id\":\"http://mobilizon.test/announces/839e0ffc-f437-48db-afba-9ce1e971e938\",\"object\":{\"actor\":\"http://mobilizon.test/@thomas0\",\"attributedTo\":\"http://mobilizon.test/@myGroup0\",\"content\":\"The <b>HTML</b>body for my Article\",\"id\":\"http://mobilizon.test/p/6a482d5f-94fc-446b-84bb-d4d386d5dd45\",\"name\":\"My updated post\",\"published\":\"2020-10-19T08:37:52Z\",\"type\":\"Article\"},\"to\":[\"http://mobilizon.test/@myGroup0/members\"],\"type\":\"Announce\"}",
"headers": {
"Content-Type": "application/activity+json",
"signature": "keyId=\"http://mobilizon.test/@myGroup0#main-key\",algorithm=\"rsa-sha256\",headers=\"(request-target) content-length date digest host\",signature=\"P+7rSSUeUBdX74wbvSEe4roG7yh7MfpF6s4tjv5q1kbeVKtXZRyfC1LqgVNCADZYXFqYlMvfF7DiaRQRiMznGWawM/QXK08eXiAVihYK28Pa56BfI68OUakd+FptlwfB4WJ4Jc7xi1z+iarv+EvlFxjkG5pgwL4mW49rvNnigELzypGtp2bj/2BhiBItHutvOju1MwLR1EBQFJBSZDVZZKbHTcV4KbGtbYvkWUbH8fZbe3fgctKlvO/z9kw+yBTTIEE1O18F4HiJ17nYtaaxv3/vl5RxcjYLpf+QQzkaPOsSLZs8zpIZZp3BbLtPh+OGwkyK9PBQsaI0N1ZSLQ5gaQ==\"",
"digest": "SHA-256=EyZ+uZ/Vv2lUK8ozgOHBpnoUWUM5WQHATQb1tEMldNU=",
"date": "Mon, 19 Oct 2020 08:37:52 GMT"
},
"method": "post",
"options": [],
"request_body": "",
"url": "http://mobilizon.test/inbox"
},
"response": {
"binary": false,
"body": "nxdomain",
"headers": [],
"status_code": null,
"type": "error"
}
}
]

View file

@ -374,6 +374,7 @@ defmodule Mobilizon.Factory do
tags: build_list(3, :tag), tags: build_list(3, :tag),
visibility: :public, visibility: :public,
publish_at: DateTime.utc_now(), publish_at: DateTime.utc_now(),
picture: insert(:media),
media: [], media: [],
url: Routes.page_url(Endpoint, :post, uuid) url: Routes.page_url(Endpoint, :post, uuid)
} }