aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/statuses/masto-note.json47
-rw-r--r--test/pleroma/web/activity_pub/activity_pub_controller_test.exs78
2 files changed, 125 insertions, 0 deletions
diff --git a/test/fixtures/statuses/masto-note.json b/test/fixtures/statuses/masto-note.json
new file mode 100644
index 000000000..6b96de473
--- /dev/null
+++ b/test/fixtures/statuses/masto-note.json
@@ -0,0 +1,47 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ {
+ "ostatus": "http://ostatus.org#",
+ "atomUri": "ostatus:atomUri",
+ "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
+ "conversation": "ostatus:conversation",
+ "sensitive": "as:sensitive",
+ "toot": "http://joinmastodon.org/ns#",
+ "votersCount": "toot:votersCount"
+ }
+ ],
+ "id": "https://example.com/users/{{nickname}}/statuses/{{status_id}}",
+ "type": "Note",
+ "summary": null,
+ "inReplyTo": null,
+ "published": "2021-02-24T12:40:49Z",
+ "url": "https://example.com/@{{nickname}}/{{status_id}}",
+ "attributedTo": "https://example.com/users/{{nickname}}",
+ "to": [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "cc": [
+ "https://example.com/users/{{nickname}}/followers"
+ ],
+ "sensitive": false,
+ "atomUri": "https://example.com/users/{{nickname}}/statuses/{{status_id}}",
+ "inReplyToAtomUri": null,
+ "conversation": "tag:example.com,2021-02-24:objectId=15:objectType=Conversation",
+ "content": "<p></p>",
+ "contentMap": {
+ "en": "<p></p>"
+ },
+ "attachment": [],
+ "tag": [],
+ "replies": {
+ "id": "https://example.com/users/{{nickname}}/statuses/{{status_id}}/replies",
+ "type": "Collection",
+ "first": {
+ "type": "CollectionPage",
+ "next": "https://example.com/users/{{nickname}}/statuses/{{status_id}}/replies?only_other_accounts=true&page=true",
+ "partOf": "https://example.com/users/{{nickname}}/statuses/{{status_id}}/replies",
+ "items": []
+ }
+ }
+}
diff --git a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs
index a9cbf90c3..d9fa25d94 100644
--- a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs
@@ -716,6 +716,84 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
user = refresh_record(user)
refute user.pinned_objects[data["object"]]
end
+
+ test "mastodon pin/unpin", %{conn: conn} do
+ status_id = "105786274556060421"
+
+ status =
+ File.read!("test/fixtures/statuses/masto-note.json")
+ |> String.replace("{{nickname}}", "lain")
+ |> String.replace("{{status_id}}", status_id)
+
+ status_url = "https://example.com/users/lain/statuses/#{status_id}"
+
+ user =
+ File.read!("test/fixtures/users_mock/user.json")
+ |> String.replace("{{nickname}}", "lain")
+
+ actor = "https://example.com/users/lain"
+
+ Tesla.Mock.mock(fn
+ %{
+ method: :get,
+ url: ^status_url
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: status,
+ headers: [{"content-type", "application/activity+json"}]
+ }
+
+ %{
+ method: :get,
+ url: ^actor
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: user,
+ headers: [{"content-type", "application/activity+json"}]
+ }
+ end)
+
+ data = %{
+ "@context" => "https://www.w3.org/ns/activitystreams",
+ "actor" => actor,
+ "object" => status_url,
+ "target" => "https://example.com/users/lain/collections/featured",
+ "type" => "Add"
+ }
+
+ assert "ok" ==
+ conn
+ |> assign(:valid_signature, true)
+ |> put_req_header("content-type", "application/activity+json")
+ |> post("/inbox", data)
+ |> json_response(200)
+
+ ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
+ assert Activity.get_by_object_ap_id_with_object(data["object"])
+ user = User.get_cached_by_ap_id(data["actor"])
+ assert user.pinned_objects[data["object"]]
+
+ data = %{
+ "actor" => actor,
+ "object" => status_url,
+ "target" => "https://example.com/users/lain/collections/featured",
+ "type" => "Remove"
+ }
+
+ assert "ok" ==
+ conn
+ |> assign(:valid_signature, true)
+ |> put_req_header("content-type", "application/activity+json")
+ |> post("/inbox", data)
+ |> json_response(200)
+
+ ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
+ assert Activity.get_by_object_ap_id_with_object(data["object"])
+ user = refresh_record(user)
+ refute user.pinned_objects[data["object"]]
+ end
end
describe "/users/:nickname/inbox" do