Add tests for unrepeats
authorFrancis Dinh <normandy@firemail.cc>
Fri, 11 May 2018 19:30:47 +0000 (15:30 -0400)
committerFrancis Dinh <normandy@firemail.cc>
Fri, 11 May 2018 19:30:47 +0000 (15:30 -0400)
test/fixtures/mastodon-undo-announce.json [new file with mode: 0644]
test/web/activity_pub/transmogrifier_test.exs

diff --git a/test/fixtures/mastodon-undo-announce.json b/test/fixtures/mastodon-undo-announce.json
new file mode 100644 (file)
index 0000000..2d8bca4
--- /dev/null
@@ -0,0 +1,47 @@
+{
+   "type": "Undo",
+   "signature": {
+     "type": "RsaSignature2017",
+     "signatureValue": "VU9AmHf3Pus9cWtMG/TOdxr+MRQfPHdTVKBBgFJBXhAlMhxEtcbxsu7zmqBgfIz6u0HpTCi5jRXEMftc228OJf/aBUkr4hyWADgcdmhPQgpibouDLgQf9BmnrPqb2rMbzZyt49GJkQZma8taLh077TTq6OKcnsAAJ1evEKOcRYS4OxBSwh4nI726bOXzZWoNzpTcrnm+llcUEN980sDSAS0uyZdb8AxZdfdG6DJQX4AkUD5qTpfqP/vC1ISirrNphvVhlxjUV9Amr4SYTsLx80vdZe5NjeL5Ir4jTIIQLedpxaDu1M9Q+Jpc0fYByQ2hOwUq8JxEmvHvarKjrq0Oww==",
+     "creator": "http://mastodon.example.org/users/admin#main-key",
+     "created": "2018-05-11T16:23:45Z"
+   },
+   "object": {
+     "type": "Announce",
+     "to": [
+       "http://www.w3.org/ns/activitystreams#Public"
+     ],
+     "published": "2018-05-11T16:23:37Z",
+     "object": "http://lostallofmy.faith/objects/acc592f0-093a-4326-856e-2ab30947ef11",
+     "id": "http://mastodon.example.org/users/admin/statuses/100011594053806179/activity",
+     "cc": [
+       "http://lostallofmy.faith/users/admin",
+       "http://mastodon.example.org/users/admin/followers"
+     ],
+     "atomUri": "http://mastodon.example.org/users/admin/statuses/100011594053806179/activity",
+     "actor": "http://mastodon.example.org/users/admin"
+   },
+   "id": "http://mastodon.example.org/users/admin#announces/100011594053806179/undo",
+   "actor": "http://mastodon.example.org/users/admin",
+   "@context": [
+     "http://www.w3.org/ns/activitystreams",
+     "http://w3id.org/security/v1",
+     {
+       "toot": "http://joinmastodon.org/ns#",
+       "sensitive": "as:sensitive",
+       "ostatus": "http://ostatus.org#",
+       "movedTo": "as:movedTo",
+       "manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
+       "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
+       "focalPoint": {
+         "@id": "toot:focalPoint",
+         "@container": "@list"
+       },
+       "featured": "toot:featured",
+       "conversation": "ostatus:conversation",
+       "atomUri": "ostatus:atomUri",
+       "Hashtag": "as:Hashtag",
+       "Emoji": "toot:Emoji"
+     }
+   ]
+}
index eb093262f82cbff2e710b2f230d4aecd631e594f..a3408da9db58a95983585a645879d68b6b5fb04d 100644 (file)
@@ -232,6 +232,34 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
 
       refute Repo.get(Activity, activity.id)
     end
+
+    test "it works for incoming unannounces with an existing notice" do
+      user = insert(:user)
+      {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
+
+      announce_data =
+        File.read!("test/fixtures/mastodon-announce.json")
+        |> Poison.decode!()
+        |> Map.put("object", activity.data["object"]["id"])
+
+      {:ok, %Activity{data: announce_data, local: false}} =
+        Transmogrifier.handle_incoming(announce_data)
+
+      data =
+        File.read!("test/fixtures/mastodon-undo-announce.json")
+        |> Poison.decode!()
+        |> Map.put("object", announce_data)
+        |> Map.put("actor", announce_data["actor"])
+
+      {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+
+      assert data["type"] == "Undo"
+      assert data["object"]["type"] == "Announce"
+      assert data["object"]["object"] == activity.data["object"]["id"]
+
+      assert data["object"]["id"] ==
+               "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
+    end
   end
 
   describe "prepare outgoing" do