X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Fostatus%2Fostatus_test.exs;h=959b744afaa4dd2d5f5cfc1540f57a2f6d2c308d;hb=72ca58c540ee03de50631ea08a419f2589a0fe8e;hp=e8f81aae69922a60e49c27e9b0aea1c0535106ae;hpb=1b67a597955b87ff792d50bed913b0af59f14edc;p=akkoma diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs index e8f81aae6..959b744af 100644 --- a/test/web/ostatus/ostatus_test.exs +++ b/test/web/ostatus/ostatus_test.exs @@ -15,10 +15,13 @@ defmodule Pleroma.Web.OStatusTest do incoming = File.read!("test/fixtures/incoming_note_activity.xml") {:ok, [activity]} = OStatus.handle_incoming(incoming) + user = User.get_by_ap_id(activity.data["actor"]) + assert user.info["note_count"] == 1 assert activity.data["type"] == "Create" assert activity.data["object"]["type"] == "Note" assert activity.data["object"]["id"] == "tag:gs.example.org:4040,2017-04-23:noticeId=29:objectType=note" assert activity.data["published"] == "2017-04-23T14:51:03+00:00" + assert activity.data["object"]["published"] == "2017-04-23T14:51:03+00:00" assert activity.data["context"] == "tag:gs.example.org:4040,2017-04-23:objectType=thread:nonce=f09e22f58abd5c7b" assert "http://pleroma.example.org:4000/users/lain3" in activity.data["to"] assert activity.local == false @@ -34,6 +37,7 @@ defmodule Pleroma.Web.OStatusTest do assert activity.data["object"]["content"] == "Will it blend?" user = User.get_cached_by_ap_id(activity.data["actor"]) assert User.ap_followers(user) in activity.data["to"] + assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"] end test "handle incoming notes with attachments - GS, subscription" do @@ -44,6 +48,16 @@ defmodule Pleroma.Web.OStatusTest do assert activity.data["object"]["type"] == "Note" assert activity.data["object"]["actor"] == "https://social.heldscal.la/user/23211" assert activity.data["object"]["attachment"] |> length == 2 + assert activity.data["object"]["external_url"] == "https://social.heldscal.la/notice/2020923" + assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"] + end + + test "handle incoming notes with tags" do + incoming = File.read!("test/fixtures/ostatus_incoming_post_tag.xml") + {:ok, [activity]} = OStatus.handle_incoming(incoming) + + assert activity.data["object"]["tag"] == ["nsfw"] + assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"] end test "handle incoming notes - Mastodon, salmon, reply" do @@ -60,6 +74,7 @@ defmodule Pleroma.Web.OStatusTest do assert activity.data["object"]["type"] == "Note" assert activity.data["object"]["actor"] == "https://mastodon.social/users/lambadalambda" assert activity.data["context"] == "2hu" + assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"] end test "handle incoming notes - Mastodon, with CW" do @@ -70,6 +85,14 @@ defmodule Pleroma.Web.OStatusTest do assert activity.data["object"]["type"] == "Note" assert activity.data["object"]["actor"] == "https://mastodon.social/users/lambadalambda" assert String.contains?(activity.data["object"]["content"], "technologic") + assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"] + end + + test "handle incoming retweets - Mastodon, with CW" do + incoming = File.read!("test/fixtures/cw_retweet.xml") + {:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming) + + assert String.contains?(retweeted_activity.data["object"]["content"], "Hey.") end test "handle incoming notes - GS, subscription, reply" do @@ -81,6 +104,7 @@ defmodule Pleroma.Web.OStatusTest do assert activity.data["object"]["actor"] == "https://social.heldscal.la/user/23211" assert activity.data["object"]["content"] == "@shpbot why not indeed." assert activity.data["object"]["inReplyTo"] == "tag:gs.archae.me,2017-04-30:noticeId=778260:objectType=note" + assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"] end test "handle incoming retweets - GS, subscription" do @@ -99,6 +123,7 @@ defmodule Pleroma.Web.OStatusTest do refute retweeted_activity.local assert retweeted_activity.data["object"]["announcement_count"] == 1 assert String.contains?(retweeted_activity.data["object"]["content"], "mastodon") + refute String.contains?(retweeted_activity.data["object"]["content"], "Test account") end test "handle incoming retweets - GS, subscription - local message" do @@ -138,6 +163,7 @@ defmodule Pleroma.Web.OStatusTest do assert retweeted_activity.data["type"] == "Create" assert retweeted_activity.data["actor"] == "https://pleroma.soykaf.com/users/lain" refute retweeted_activity.local + refute String.contains?(retweeted_activity.data["object"]["content"], "Test account") end test "handle incoming favorites - GS, websub" do @@ -181,6 +207,7 @@ defmodule Pleroma.Web.OStatusTest do assert activity.data["object"]["inReplyTo"] == "http://pleroma.example.org:4000/objects/55bce8fc-b423-46b1-af71-3759ab4670bc" assert "http://pleroma.example.org:4000/users/lain5" in activity.data["to"] assert activity.data["object"]["id"] == "tag:gs.example.org:4040,2017-04-25:noticeId=55:objectType=note" + assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"] end test "handle incoming follows" do @@ -192,8 +219,8 @@ defmodule Pleroma.Web.OStatusTest do assert activity.data["object"] == "https://pawoo.net/users/pekorino" refute activity.local - follower = User.get_cached_by_ap_id(activity.data["actor"]) - followed = User.get_cached_by_ap_id(activity.data["object"]) + follower = User.get_by_ap_id(activity.data["actor"]) + followed = User.get_by_ap_id(activity.data["object"]) assert User.following?(follower, followed) end @@ -217,6 +244,7 @@ defmodule Pleroma.Web.OStatusTest do assert user.local == false assert user.info["uri"] == uri assert user.ap_id == uri + assert user.bio == "Call me Deacon Blues." assert user.avatar["type"] == "Image" {:ok, user_again} = OStatus.find_or_make_user(uri) @@ -228,7 +256,9 @@ defmodule Pleroma.Web.OStatusTest do uri = "https://social.heldscal.la/user/23211" {:ok, user} = OStatus.find_or_make_user(uri) - change = Ecto.Changeset.change(user, %{avatar: nil}) + old_name = user.name + old_bio = user.bio + change = Ecto.Changeset.change(user, %{avatar: nil, bio: nil, old_name: nil}) {:ok, user} = Repo.update(change) refute user.avatar @@ -237,6 +267,8 @@ defmodule Pleroma.Web.OStatusTest do [author] = :xmerl_xpath.string('//author[1]', doc) {:ok, user} = OStatus.find_make_or_update_user(author) assert user.avatar["type"] == "Image" + assert user.name == old_name + assert user.bio == old_bio {:ok, user_again} = OStatus.find_make_or_update_user(author) assert user_again == user @@ -261,6 +293,7 @@ defmodule Pleroma.Web.OStatusTest do "uri" => "https://social.heldscal.la/user/29191", "host" => "social.heldscal.la", "fqn" => user, + "bio" => "cofe", "avatar" => %{"type" => "Image", "url" => [%{"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg", "mediaType" => "image/jpeg", "type" => "Link"}]} } assert data == expected @@ -283,6 +316,7 @@ defmodule Pleroma.Web.OStatusTest do "uri" => "https://social.heldscal.la/user/29191", "host" => "social.heldscal.la", "fqn" => user, + "bio" => "cofe", "avatar" => %{"type" => "Image", "url" => [%{"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg", "mediaType" => "image/jpeg", "type" => "Link"}]} } assert data == expected @@ -298,4 +332,11 @@ defmodule Pleroma.Web.OStatusTest do assert activity.data["object"]["id"] == "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment" end end + + test "insert or update a user from given data" do + user = insert(:user, %{nickname: "nick@name.de"}) + data = %{ ap_id: user.ap_id <> "xxx", name: user.name, nickname: user.nickname } + + assert {:ok, %User{}} = OStatus.insert_or_update_user(data) + end end